cuemacro / finmarketpy

Python library for backtesting trading strategies & analyzing financial markets (formerly pythalesians)
http://www.cuemacro.com
Apache License 2.0
3.41k stars 490 forks source link

Pipelining / stacking strategies #34

Open flipdazed opened 3 years ago

flipdazed commented 3 years ago

Hey Saeed - been looking your finmarketpy library - looks nice!

What wasn't clear to me from looking at it was if you can stack strategies upon each other?

For example:

Is that achievable ?

I couldn't see how it would be set up and return risk metrics at each constituent level.

saeedamen commented 3 years ago

Thanks @flipdazed - one way to do this, would be to construct TradingModel classes for each of your building blocks. You'd then create a another portfolio based TradingModel strategy, and you'd fill the load_asset method to construct all the building blocks. The construct_signal method could be filled with all your weightings. You can then access all the return risk metrics for the whole portfolio, do all the sensitivity analysis (using TradeAnalysis) too.

At the moment there are automatic processes for doing things like vol targeting, but can imagine that people might want more complicated portfolio construction too.

However, I can add additional functionality to make this stacking of strategies a bit nicer/easier with TradingModel? One way I thought of doing this, would be simply to add your substrategies as parameters to the BacktestRequest and all the load_assets stuff would get filled automatically. You'd just need to write the scheme for construct_signals (and could default that to equal weighting). How does that sound?

flipdazed commented 3 years ago

Ok I'll check how that works and get back to you