I am trying to reproduce R results in Python. The following R code works:
library("TTR")
library("zoo")
library("xts")
library("quantmod")
getSymbols("^GSPC",from = "2014-01-01", to = "2015-01-01")
dataf = GSPC[,c("GSPC.High", "GSPC.Low", "GSPC.Close")]
result = CCI(dataf, n=20, c=0.015)
But not the following Python code:
from datetime import datetime
from rpy2.robjects.packages import importr
TTR = importr('TTR')
import pandas_datareader as pdr
from rpy2.robjects import pandas2ri
pandas2ri.activate()
GSPC = pdr.get_data_yahoo(symbols='^GSPC', start=datetime(2014, 1, 1), end=datetime(2015, 1, 1))
dataf = GSPC[['High', 'Low', 'Close']]
result = TTR.CCI(dataf, n=20, c=0.015)
The error I get occurs on the last line when using TTR.CCI. Traceback and error returned is:
Traceback (most recent call last):
File "svm_strat_test_oliver.py", line 30, in <module> result = TTR.CCI(dataf, n=20, c=0.015)
File "/usr/local/lib/python2.7/site-packages/rpy2/robjects/functions.py", line 178, in __call__
return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/rpy2/robjects/functions.py", line 106, in __call__
res = super(Function, self).__call__(*new_args, **new_kwargs)
rpy2.rinterface.RRuntimeError: Error in `[.data.frame`(center, beg:NROW(x)) : undefined columns selected