Skip to content

Instantly share code, notes, and snippets.

View timelyportfolio's full-sized avatar

timelyportfolio timelyportfolio

View GitHub Profile
@timelyportfolio
timelyportfolio / moodys aaa forward and back.r
Created January 6, 2012 22:48
moodys aaa forward and back
require(quantmod)
require(PerformanceAnalytics)
require(latticeExtra)
require(grid)
require(reshape)
require(RQuantLib)
getSymbols("AAA",src="FRED") # load Moody's AAA from Fed Fred
#Fed monthly series of yields is the monthly average of daily yields
@timelyportfolio
timelyportfolio / bondreturnsources.r
Created January 12, 2012 16:35
Source of Bond Return
require(quantmod)
require(PerformanceAnalytics)
require(lattice)
require(latticeExtra)
getSymbols("GS10",src="FRED") #load 10yTreasury
getSymbols("BAA",src="FRED") #load Corporate for credit
getSymbols("CPIAUCSL",src="FRED") #load CPI for inflation
bondReturnSources<-na.omit(merge(ROC(CPIAUCSL,12,type="discrete")*100,
BAA-GS10,GS10-ROC(CPIAUCSL,12,type="discrete")*100))
@timelyportfolio
timelyportfolio / stocks with extreme bonds.r
Created January 12, 2012 21:22
stocks under extreme bonds
require(quantmod)
require(PerformanceAnalytics)
require(RQuantLib)
require(lattice)
getSymbols("AAA",src="FRED") # load Moody's AAA from Fed Fred
#Fed monthly series of yields is the monthly average of daily yields
#set index to yyyy-mm-dd format rather than to.monthly mmm yyy for better merging later
index(AAA)<-as.Date(index(AAA))
@timelyportfolio
timelyportfolio / yen and us10y.r
Created January 13, 2012 23:10
yen and us10y
require(quantmod)
#get Japanese Yen daily from Fred http://research.stlouisfed.org/fred2
getSymbols("DEXJPUS",src="FRED")
#get US 10y Yield from Fred
getSymbols("DGS10", src="FRED")
Yen10y <- na.omit(merge(DEXJPUS,DGS10))
#define colors
@timelyportfolio
timelyportfolio / currencies and US10y.r
Created January 17, 2012 17:37
currencies and US10y
require(quantmod)
require(colorRamps)
#get currency data from the FED FRED data series
getSymbols("DEXKOUS",src="FRED") #load Korea
getSymbols("DEXMAUS",src="FRED") #load Malaysia
getSymbols("DEXSIUS",src="FRED") #load Singapore
getSymbols("DEXTAUS",src="FRED") #load Taiwan
getSymbols("DEXCHUS",src="FRED") #load China
getSymbols("DEXJPUS",src="FRED") #load Japan
@timelyportfolio
timelyportfolio / vis of survey.r
Created January 26, 2012 22:56
survey visualization
#r code to read survey responses
#from a google spreadsheet published to web as .csv
#please see http://lamages.blogspot.com/2012/01/feedback-from-vignette-survey.html
#and the github https://gist.github.com/1579665
#for another method using google fusion tables
#require(vcd) #use vcd since I have never used it before
#ended up not using since I could not control size and location
#of the assoc plot
@timelyportfolio
timelyportfolio / cumul growth of dollar.r
Created February 6, 2012 21:09
cumul growth of dollar
#trying to get a better growth of a $1 chart
#using lattice or PerformanceAnalytics
require(quantmod)
require(reshape)
require(lattice)
require(latticeExtra)
#get Vanguard US Total Bond Fund vbmfx
getSymbols("VBMFX",from="1990-01-01",to=Sys.Date(),adjust=TRUE)
#get Vanguard SP500 Fund vfinx
@timelyportfolio
timelyportfolio / use of systematic investor part 1.r
Created February 10, 2012 22:33
use of systematic investor part 1
#highlight the very fine work of http://systematicinvestor.wordpress.com/
#adapted some of his code to provide an addtional example for
#those that might be interested
###############################################################################
# Load Systematic Investor Toolbox (SIT)
# http://systematicinvestor.wordpress.com/systematic-investor-toolbox/
###############################################################################
con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb'))
    source(con)
@timelyportfolio
timelyportfolio / japan_trade_yen.r
Created March 7, 2012 22:18
japan trade and yen
require(quantmod)
#get data from Japan Ministry of Finance website in csv form
url = "http://www.customs.go.jp/toukei/suii/html/data/d41ma.csv"
japantrade <- read.csv(url,skip=2,stringsAsFactors=FALSE)
#start cleaning data and getting in xts form
japantrade.xts <- japantrade[2:NROW(japantrade),]
#remove trailing 0 for future data
japantrade.xts <- japantrade.xts[which(japantrade.xts[,2]!=0),]
@timelyportfolio
timelyportfolio / japan trade by region.r
Created March 12, 2012 19:31
japan trade by region.r
#further explore Japanese trade data by region
#website is http://www.customs.go.jp/toukei/suii/html/time_e.htm
#format is http://www.customs.go.jp/toukei/suii/html/data/d42ma001.csv
#and the filename increments from 001 to 008 for the geographic areas
require(quantmod)
require(reshape)
require(lattice)
require(latticeExtra)