vectorbt icon indicating copy to clipboard operation
vectorbt copied to clipboard

Specifying capital for each stock in portfolio instead of target size percentage

Open singyeah opened this issue 2 years ago • 1 comments

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?

singyeah avatar Jun 18 '22 10:06 singyeah

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

polakowo avatar Jun 27 '22 08:06 polakowo