# NOT RUN {
currency("USD")
stock("SPY", "USD")
stock("DIA", "USD")
getSymbols(c("SPY","DIA"))
#can call with names of instrument/xts ojects
fSB <- fn_SpreadBuilder("SPY","DIA")
fSB2 <- fn_SpreadBuilder(SPY,DIA) # or you can pass xts objects
#assuming you first somehow calculated the ratio to be a constant 1.1
fSB3 <- fn_SpreadBuilder("SPY","DIA",1.1)
head(fSB)
# Call fn_SpreadBuilder with vector of 2 instrument names
# in 1 arg instead of using both prod1 and prod2.
fSB4 <- fn_SpreadBuilder(c("SPY","DIA"))
#download data and plot the closing values of a spread in one line
chartSeries(Cl(fn_SpreadBuilder(getSymbols(c("SPY","DIA")),auto.assign=FALSE)))
# }
Run the code above in your browser using DataLab