Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can bt be used to buy certain dollar amounts of stock (vs rebalancing to weights)? #385

Open
brettelliot opened this issue Sep 6, 2022 · 4 comments

Comments

@brettelliot
Copy link

Hi,

Let's say i want to build a trend strategy with a universe of 10 stocks. Id like the strategy to invest up to 10% of the total portfolio value when any stock is trending up. Say stock A goes up, and i end up buying 100 shares. When stock B goes up, I want to invest up to 10% of the current portfolio value (which is hopefully higher since we invested in stock A because it was going up). But I don't want to change anything about stock A's position. We should keep the 100 shares of stock A no matter what percentage of the portfolio they amount to until the strategy decides to sell stock A.

Can bt backtest a strategy like this?

@Helikoptermann2
Copy link

@brettelliot Did you ever find a solution for this? I'm stuck with the exact same problem.
I don't want the algo to rebalance with every transaction made and just keep the existing positions as they are

@dqnne
Copy link

dqnne commented Sep 24, 2024

@Helikoptermann2 Hey, I'm facing the same issue. Did you ever figure out what to do?

I feel like it would be possible with some custom algos but I don't know how to implement it exactly.

@Helikoptermann2
Copy link

No, I did not find a solution and then stepped away from this package.
But would still be interested in a solution

@dqnne
Copy link

dqnne commented Sep 24, 2024

Looking at the docs I see that the SecurityBase class has methods for allocate() and transact(), which are meant to buy/sell for a specific amount/quantity. I think we would just have to create a custom algo for buying/selling with these methods instead of using rebalance.

There's also the StrategyBase class which also has methods for allocate() and transact(). These seem to behave a little differently.

https://pmorissette.github.io/bt/bt.html#bt.core.SecurityBase
https://pmorissette.github.io/bt/bt.html#bt.core.StrategyBase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants