Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Help with a maximum Holding period XIV strategy

Hi everyone,
So I am doing a backtest on XIV based on the VIX.
I would like to set a holding period of maximum 21 days, however, the code seems not to work and I am not sure why.
In lines 55 to 58 I defined the maximum holding period and in lines 189 to 200 I want to sell the position if it has ben bought more than 21 days ago.

Could maybe anyone give me a hand?

Thank you so much

4 responses

Hi Sebastian,

Is there a typo at line 56? context.days_to_hold = 1 (21)

Hi Jack,
It's not, when I started to think that my holding period wasn't really working, I started trying different days to see if something changed, but nothing did. That's why I come to the conclusion that I must have another typo somewhere because the holding period isn't really working for me :(

I think the reason is that order_positions() is not called or scheduled to run.

It's not working because you rebalance daily and alter the position allocation without checking the days held

Also, this might work in a back test but in live trading you may lose track of your days held in the event your algo is restarted