Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Constant Rebalance Via Trigger - Simple Question

Hi, How one goes about setting up a constant rebalace of a given sid or sids that is controlled by some other condition, Ie:
if value X is above value Y, close open position on security N and reopen the same position on the same session (harvesting any gain/loss), repeat the process the next day (given the X above Y setup is still in place)

i could do that with a schedule function (by just scheduling a recheck few minutes after the first check) but theres probably a more intelligent way

Thank you

4 responses

I am not sure I understand, you want to completely sell a position in N, and then repurchase it right away?

Thanks Simon for getting back - Correct: I attached a simple example of the rebalance logic, not sure if its executing properly though, meaning it should rebalance on the same day (within the same schedule function)

Thanks for your time

Hi Darell,

Your algo builds leverage up to x2.88 or so.

To rebalance you don't need to sell everything and order it back again. order_target_percent adjusts the position to your requested fraction. However, it does not taken into account open orders when calculating the quantity of shares, so two calls for the same sid messes it up completely.

See if the following code helps:

Thanks for getting back Jack, one follow up question:
I dont see the Sell order in the code, its does it by itself via get_open_orders ?

thank you