polakowo / vectorbt

Find your trading edge, using the fastest engine for backtesting, algorithmic trading, and research.
https://vectorbt.dev
Other
3.96k stars 582 forks source link

Testing multiple assets in a basket #97

Closed skollar closed 3 months ago

skollar commented 3 years ago

Is there a way to add a bag of assets in a single portfolio. ie [ AAPL, MSFT, GOOG]. Goal is to view the effect of a strategy in a set of non correlated assets.

Is this feasible? Is there any hooks to add custom order management based on current open orders?

polakowo commented 3 years ago

You need to pack your asset prices into a single DataFrame and run any Portfolio.from_* method with group_by set to True. If the basket should share the same capital, set cash_sharing to True (see examples).

Any order management logic can be implemented using Portfolio.from_order_func, where you pass an order function that is then called every tick (see examples). But note that vectorbt allows only one order per tick and asset, since the solution is built on top of NumPy arrays that cannot grow efficiently.

rolandgem commented 1 year ago

Hi @polakowo the example links above return page 404 not found. Do you have any examples on constructing a multi-asset portfolio? Thanks!

ari62 commented 1 year ago

This might be the new link: https://vectorbt.pro/tutorials/portfolio-optimization/