enzoampil / fastquant

fastquant — Backtest and optimize your ML trading strategies with only 3 lines of code!
MIT License
1.52k stars 239 forks source link

add dividends to cash #346

Closed rafmacalaba closed 3 years ago

rafmacalaba commented 3 years ago

adding dividends to broker. resolves #336

rafmacalaba commented 3 years ago

still figuring out checks. it fails on the sentiment part.

rafmacalaba commented 3 years ago

@enzoampil please review.

enzoampil commented 3 years ago

@rafmacalaba Sorry, tested it on my notebook, and it seems to fail when there's no dividend column?

from fastquant import backtest, get_stock_data
df = get_stock_data("TSLA", "2019-01-01", "2020-01-01")
backtest("smac", df)

Starting Portfolio Value: 100000.00
2019-12-31, ===Global level arguments===
2019-12-31, init_cash : 100000
2019-12-31, buy_prop : 1
2019-12-31, sell_prop : 1
2019-12-31, commission : 0.0075
2019-12-31, stop_loss : 0
2019-12-31, stop_trail : 0
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-60f712f51c7e> in <module>()
----> 1 backtest("smac", df)

7 frames
/usr/local/lib/python3.7/dist-packages/backtrader/lineseries.py in __getattr__(self, name)
    459         # in this object if we set an attribute in this object it will be
    460         # found before we end up here
--> 461         return getattr(self.lines, name)
    462 
    463     def __len__(self):

AttributeError: 'Lines_LineSeries_DataSeries_OHLC_OHLCDateTime_Abst' object has no attribute 'dividend'

On this notebook

https://colab.research.google.com/drive/1ScJ8bzEcafgibMNc1GVl1RZZy41PNJDB?usp=sharing

enzoampil commented 3 years ago

@rafmacalaba Recent change takes out error in the case the input dataframe has no "dividend" column :)

Congrats! WIll merge this now 😄