Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
order_target_percent dry run

Hello

I'm wondering if it's possible to launch a dry run of order_target_percent

I have an algorithm that rebalances some securities but I would like to avoid sells. The intention is to use order_target_percent to rebalance but avoid the trade if it means selling the security.

Is there any easy way to do that?

Thanks!

6 responses

Jorge,

Not sure I follow. Where will the capital come from to rebalance? For example, if you have X% in one stock and Y% in another, and the latter stock appreciates to (Y+delta)%, you'd need to sell some of it, and buy more of the former.

Grant

Thanks for your answer Grant

What I mean is:

I allocate 50% of my portfolio on security A and 50% on security B

After a month security A went up and it's 60% of the portfolio and security B is 40%

If I rebalance now with order_target_percent to 50%, it will sell A and buy B to make both 50% of the portfolio

What I'd like is just to execute the buying order on B and avoid the selling order on A even if the final portfolio is 60-50 or even 60-60

I was wondering if it's a way of calling order_target_percent without executing the real order until I check what's gonna do.

You could give this a try:

order_target_percent(stock_B, 0.5)  

This should increase your position in B, without affecting A. Since you have two stocks, they should both be at 50% weight, after the order goes through. I'd expect your leverage to go up, as well, since the capital for buying B will have to come from somewhere.

Are you needing to do this for more than two stocks?

Yes, but how do I know that? if that's the opposite case and I use order_target_percent(stock_B, 0.5) I would end up selling B. And that's what I don't want.

I know I can do that getting all my positions and calculating the desired new ones. I was just wondering if it's possible to get the outcome of order_target_percent without actually running it. I guess it's not possible.

I don't think it is possible, without writing some additional code. It seems like the kind of problem that might be framed as a set of equations with constraints, for the general case of N stocks. The value of each position has to stay the same or increase. And the normalization is unconstrained (sum of all of the relative weights/percentages), unless you limit the leverage. If I'm thinking about it correctly, you'd have to write your own custom version of order_target_percent (except if you only have two stocks, which is kinda trivial).

Yes... I was thinking about more than 1 stock :)

Thanks anyway Grant!