First, I would like to thank the community for the fantastic support and reactivity.
I encounter a problem applying a simple MA crossover strategy on multi instruments.
Basically, I maintain a database of csv price files. I retrieve these files using this code
getdata <- function(ticker){
d <- read.csv(ticker, header=TRUE, sep = ",")
d[,1] <- as.Date(as.character(d[,1]), tz ="GMT", format="%m/%d/%Y")
ticker <- as.xts(d[,-1], order.by =d[,1] )
}
I then import the data which creates me valid xts object with correct indexing
GBPUSD <- getdata("GBPUSD.csv")
AUDUSD <- getdata("AUDUSD.csv")
EURUSD <- getdata("EURUSD.csv")
I then run the usual initialistion process
### Initialisation
currency(c("USD","EUR","AUD","GBP"))
exchange_rate(c("EURUSD","GBPUSD","AUDUSD"),"USD")
symbols <- c("EURUSD","GBPUSD","AUDUSD")
init.date <- "2001-09-04" #date d'initialisation de l'environement
start.date <- "2001-09-05" #1ere date du jeu de donnée
end.date <- "2017-01-04" #dernière date du jeu de donnée
initial.capital <- 1000000 #Capital de départ
model <- strategy("model")
portfolio.st <- account.st <- strat.st <- "model"
if (!exists('.blotter')) .blotter <- new.env()
if (!exists('.strategy')) .strategy <- new.env()
Then (and i suspect the problem is here), I initiate the portfolio. If i initiate the portfolio where i input directly the name of the instruments like that it works properly.
initPortf(portfolio.st, #nom du book
symbols = "EURUSD", #list des instruments
initDate=init.date, #date de départ du book
currency='USD') #devise de référence du book
But I want to apply the strategy on "symbols", not running it instrument by instrument. I know I should write the following but unfortunately, it does not work.
initPortf(portfolio.st, #nom du book
symbols = symbols, #list des instruments
initDate=init.date, #date de départ du book
currency='USD') #devise de référence du book
Finally, and this is where I don't find any logic, if i intiate the portfolio like that, it works with 2 instruments, not 3
initPortf(portfolio.st, #nom du book
symbols = c("EURUSD","GBPUSD"), #list des instruments
initDate=init.date, #date de départ du book
currency='USD') #devise de référence du book
The error message I get is
applyStrategy("model", portfolios = portfolio.st, symbols = symbols)
Error in sum(x[beg:(n + beg - 1)]) :
invalid 'type' (character) of argument
Once again, thanks in advance for the support.
Nicolas