Replies: 2 comments 2 replies
-
Hi all, I solved the problem. I was referencing a global variable and not the class variable called data hence the problem. I am now encountering an even more baffeling error message but that is a post for a separate thread. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Hi, The self.df is an accessor which gives you access to the data frame. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all,
I have a pandas data frame which I am passing into the backtesting framework.
I have got this frame from a machine learning model. The data frame has a column named "signal". If "signal" is 1, then I buy otherwise I sell.
How do I encode this logic into the next function? I tried the following code and got the below error.
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
class testModel(Strategy):
def init(self):
super().init()
bt = Backtest(data, testModel, commission=.0002, margin=.05)
stats = bt.run()
The problem is at the line if (data.signal==1):
I have tried enclosing this in parenthesis but that did not help.
I did check if custom data frames can be used and from whatever I have read, the above code should work.
Anyone any ideas on how to fix this?
Pranav
Beta Was this translation helpful? Give feedback.
All reactions