Open sandeepbhutani304 opened 6 months ago
Yeah I noticed the same. It seems the equity and cash attributes are not being updated correctly for each new candle. I think the fix would be as follows. Under the Broker class we have to fix:
@property
def equity(self) -> float:
return self._cash + sum(trade.pl for trade in self.trades)
to
@property
def equity(self) -> float:
return self._cash + sum(trade.value for trade in self.trades)
2. on the **_close_trade** method we should replace
`self._cash += trade.pl`
for
`self._cash += trade.value`
3. on the **_open_trade** method we should add at the end the following line:
`self._cash = self._cash - trade.size*trade.entry_price `
Expected Behavior
Equity value should be same as of starting equity value
Actual Behavior
It changes based on number of data points
Steps to Reproduce
`class SmaCross(Strategy):
Define the two MA lags as class variables
`
Additional info
Backtesting version: 0.3.3
bokeh.__version__
: