con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb'))
source(con)
close(con)
load.packages("TTR,PerformanceAnalytics,quantmod,lattice")
#######################################################
#Get and Prep Data
#######################################################
data <- new.env()
tickers<-spl("VTI,IEF,TLT,DBC,VNQ,GLD")
getSymbols(tickers, src = 'yahoo', from = '1980-01-01', env = data)
for(i in ls(data)) data[[i]] = adjustOHLC(data[[i]], use.Adjusted=TRUE)
bt.prep(data, align='remove.na', dates='1990::2013')
我遇到了从 xts 对象中减去特定列的问题。
prices = data$prices
ret = prices / mlag(prices) - 1
ret - ret[,3] #subtract column three from every other column don't seem to work
有没有快速的解决方案?
我试过了:
apply(ret,2,function(x) x - x[,3]) #doesn't seem to work
有任何想法吗?