vectorbt
vectorbt copied to clipboard
Specifying capital for each stock in portfolio instead of target size percentage
Hi, thank you for writing this amazing library. It is a very powerful yet simple to use backtrading library. My question is: is it possible for me to input an array of capital, or any specific functions i could call so that i can indicate the amount of capital to be used to buy stocks for my portfolio. Say I have a portfolio size of 5 stocks and captial is evenly split among them. Whenever i sell a stock to take profit, i buy another stock. Thus when i sell two stocks to take profit, the capital spent on the two new stocks is split evenly from the total profit of the previous two stocks plus the initial capital allocated, while capital allocated to the remaining three stocks does not change?
There is an equally-weighted portfolio example in the api documentation of from_orders: https://vectorbt.dev/api/portfolio/base/#vectorbt.portfolio.base.Portfolio.from_orders
You can also create an order function that does what you want dynamically, see examples under from_order_func: https://vectorbt.dev/api/portfolio/base/#vectorbt.portfolio.base.Portfolio.from_order_func