Back to Community
Buying and Selling without a timed Rebalance Help

I am trying to design a program that buys and sells programs not based on a timed rebalance like most of the Quantopian Strategies. I am trying to buy stocks everyday if they make a new yearly high, and sell them once they hit their ATR stop loss. I currently have to reweigh the portfolio every day as I get new positions. I added a momentum score also, for speed, and volatility to find stocks with lower standard deviations.

E.g.
Day 1:
I have 10 positions
Day 2:
Add 3, lose 2

so the weight would start on day 1 as 10%,
but now I have 11, i.e. (10+3)-2, So I rebalance the portfolio to 1/11 or 9% to keep the equal weight

This gives me the equation.

long_weight=1.0/(new+old-context.ts)
where I loop through context.buy

context.buy=context.longs+context.exist

I know there are probably a lot of better ways to do this. How do I add positions daily, and sell them after an indicator signal?

Thanks,

Eric

Clone Algorithm
120
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: 5927866bb4cf634df38fd276
There was a runtime error.