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

Clone Algorithm
3
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 55d5d077952e010da1f7cdcb
There was a runtime error.

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:

Clone Algorithm
3
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 55d5fb72428d220d7b8a9139
There was a runtime error.

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