What is the structure of self.data ? #526
-
I defined a func to prepare for the indicator which will use both open, high, low, close columns as input. As my experience before, the package will first turn all pandas DataFrames into np.arrays. So I add a line to turn it back into pandas, so that I can use pd funcs to prepare the data. But it is throwing an error which indicates that DataFrame constructor failed. `def slump(df):
... class Big10(Strategy):
and the error is:
I guess the problem lies in my calling self.data , as the input. As I see in the tutorials, self.data.Close works fine. So, I guess self.data has all the 5 columns ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The docs explicitly say Finally, when in doubt, just look in the source: backtesting.py/backtesting/_util.py Lines 103 to 195 in 267d99f 😁 |
Beta Was this translation helpful? Give feedback.
The docs explicitly say
Strategy.data
is not a dataframe, so you can't just use it as if.If you need data to become a DataFrame, you can use its
.df accessor
(self.data.df
), or.s
accessor for individual series (self.data.Close.s
).Finally, when in doubt, just look in the source:
backtesting.py/backtesting/_util.py
Lines 103 to 195 in 267d99f