Troubleshooting Simulated Sells in a Rank-Based Stock Strategy
Summary
The post asks why a daily stock-ranking strategy sells positions in backtests but appears only to buy them in simulation. Its code includes a trailing stop based on a percentage below the highest observed price since purchase, then manages capital and ranks current holdings for possible replacement. Once the initial staging period ends, it walks holdings from the bottom of the day’s prediction order and submits orders to reduce selected positions to zero until a cash target is met. It then allocates available buying cash among the highest-ranked instruments, subject to per-instrument limits.
The post provides the code and the reported difference between backtest and simulation behavior, but no diagnosis or confirmed fix. The sell branch is conditional on both staging having ended and its calculated cash-for-sell value being positive; the selected holdings must also appear in the day’s prediction data. These conditions are plausible areas to inspect, but the document offers no logs or platform details establishing the cause. The code’s behavior in simulation remains unresolved.
Key ideas
- The strategy applies a stop based on a percentage decline from the post-purchase high.
- Rank-based selling begins only after the staging period and when the cash-for-sell condition is positive.
- The strategy considers held stocks found in that day’s ranked predictions for replacement.
- Buy orders favor higher-ranked stocks and observe per-instrument allocation limits.
- The author reports that simulation buys without selling, but the post gives no diagnosis or confirmed remedy.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.