I am trying to upload a group of symbols into the package quantstrat using quantmod::getSymbols
.
The symbols I am loading are not available on Yahoo (they are South African stocks), so I need to load them from a local directory and from .csv files.
My symbols file looks as follows:
head(symbols)
[1] "SHFJ" "FSRJ" "RDFJ" "GRTJ" "MTNJ" "SLMJ"....
My symbol price history are in separate csv files, and each contain a date column and OHLC columns, with a header only for the OHLC prices.
I use the function getSymbols.csv
function as follows:
getSymbols.csv(symbols, env, dir="E:/data/CData_Files_NB/", return.class = "xts", extension="csv")
but I get the following error message
loading SHFJ .....done.
Error in `colnames<-`(`*tmp*`, value = c("SHFJ.Open", "SHFJ.High","SHFJ.Low", : length of 'dimnames' [2] not equal to array extent
I would much appreciate it if anyone could show me what I am doing wrong. I am not sure if there is another way to load stock prices into the quantstrat package.
getsymbols.csv expects six columns: Open, High, Low, Close, Volume, Adjusted
Your data does not have the "Adjusted" column; it has 5 column names instead of 6, which is causing the dimnames error you're seeing.
If you can modify the local data files, try adding an empty "Adjusted" column (easily done by opening the CSVs in LibreOffice or Excel,)
or try duplicating the getsymbols.csv() function and changing:
To
In order to support your data.