pmorissette / bt

bt - flexible backtesting for Python
http://pmorissette.github.io/bt
MIT License
2.11k stars 411 forks source link

How to get combined strategies of combined strategies working? #415

Open Pirat83 opened 1 year ago

Pirat83 commented 1 year ago

BT composite strategies

This repository shows the effect of the issue https://github.com/pmorissette/bt/issues/415. For more details see the test_interpreter.py unit test or use the Jupyter notebook example.ipynb

Simple buy and hold strategy:

We create a simple buy and hold strategy with the QQQ.

First level composite strategy

Second level composite strategy

We create a combined strategy containing to combined strategies and one asset.

bt/core.py:763: AttributeError


# How to get this working?

```shell
git clone https://github.com/Pirat83/bt-composite-strategies.git
cd bt-composite-strategies/
conda create --name bt-composite-strategies
conda env update

If you can contribute to the solution I would appreciate it very much.

Pirat83 commented 1 year ago

Please see: https://github.com/Pirat83/bt-composite-strategies/blob/main/example.ipynb

Pirat83 commented 1 year ago

How to get rid of this error:

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../../.conda/envs/bt-composite-strategies/lib/python3.11/site-packages/bt/backtest.py:28: in run
    bkt.run()
../../../.conda/envs/bt-composite-strategies/lib/python3.11/site-packages/bt/backtest.py:253: in run
    self.strategy.update(dt)
bt/core.py:732: in bt.core.StrategyBase.update
    ???
bt/core.py:856: in bt.core.StrategyBase.update
    ???
bt/core.py:2144: in bt.core.Strategy.run
    ???
bt/core.py:2140: in bt.core.Strategy.run
    ???
bt/core.py:2079: in bt.core.AlgoStack.__call__
    ???
../../../.conda/envs/bt-composite-strategies/lib/python3.11/site-packages/bt/algos.py:1809: in __call__
    target.root.update(target.now)
bt/core.py:732: in bt.core.StrategyBase.update
    ???
bt/core.py:732: in bt.core.StrategyBase.update
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   AttributeError: 'Strategy' object has no attribute '_values'

bt/core.py:763: AttributeError

======================== 1 failed, 4 warnings in 2.36s =========================

Process finished with exit code 1

Thank you very much.

Pirat83 commented 1 year ago

Seems like https://github.com/pmorissette/bt/issues/333 has similar issues.