Prompt Details
Model
(gemini-3.6-flash)
Token size
591
Example input
[Trading Concept]: Trend-following strategy using moving-average crossover
[Market, Asset, and Timeframe]: S&P 500 ETF, daily timeframe
[Entry and Exit Idea]: Buy when the 50-day moving average crosses above the 200-day moving average; exit when it crosses back below
[Risk and Position Rules]: One open position at a time, no leverage, maximum 2% portfolio risk per trade
[Constraints and Additional Notes]: Include transaction costs, compare multiple moving-average combinations, and test across bull, bear, and sideways markets
Example output
## π Strategy Overview
* **Asset / Instrument:** S&P 500 ETF (e.g., SPY or IVV)
* **Timeframe:** Daily ($1\text{-day}$ close bars)
* **Strategy Type:** Systemic, trend-following, long-only regime model
* **Execution Frequency:** Low (infrequent rebalancing upon signal trigger)
## π§ Core Trading Hypothesis
An asset's long-term upward trend creates sufficient price momentum to compensate for signal lag and false-breakout whipsaws. By capturing major bull markets and exiting during severe bear markets, the strategy aims to achieve higher risk-adjusted returns (or lower maximum drawdowns) relative to a buy-and-hold benchmark on the S&P 500.
## π₯ Entry Rules
A **Long Entry** is generated when the fast moving average crosses above the slow moving average on the daily close.
* **Trigger Condition:** $\text{MA}_{\text{fast}}[t-1] \le \text{MA}_{\text{slow}}[t-1]$ AND $\text{MA}_{\text{fast}}[t] > \text{MA}_{\text{slow}}[t]$
* **Execution Time:** Market Open on bar $t+1$ (assuming next-day execution to avoid lookahead bias).
* **Execution Price:** $\text{Open}[t+1]$
## π€ Exit Rules
A **Long Exit** is generated when the fast moving average crosses back below the slow moving average on the daily close.
* **Trigger Condition:** $\text{MA}_{\text{fast}}[t-1] \ge \text{MA}_{\text{slow}}[t-1]$ AND $\text{MA}_{\text{fast}}[t] < \text{MA}_{\text{slow}}[t]$
* **Execution Time:** Market Open on bar $t+1$.
* **Execution Price:** $\text{Open}[t+1]$
## βοΈ Variables & Parameters
| Variable Name | Type | Baseline Value | Parameter Sweep / Alternative Options |
| --- | --- | --- | --- |
| `Fast_MA_Period` | Integer | $50$ | $10, 20, 50, 100$ |
| `Slow_MA_Period` | Integer | $200$ | $100, 150, 200$ |
| `MA_Type` | Categorical | Simple Moving Average (SMA) | Exponential (EMA), Weighted (WMA) |
| `Transaction_Fee` | Float | $0.00$ USD/share | Commission rates per broker ($0.0005\text{--}0.005$/share) |
| `Slippage_Pcnt` | Float | $0.02\%$ per trade | $0.00\%\text{--}0.10\%$ |
| `Max_Portfolio_Risk` | Float | $2\%$ | Configured via sizing or hard stops |
## π‘οΈ Risk & Position Management
* **Position Limits:** Maximum 1 open position at a time (no stacking or scaling).
* **Leverage:** $1.0\times$ maximum (no margin, long-only).
* **Position Sizing:** Allocate portfolio equity based on specified max risk parameters.
* *Option A (All-In Trend Filter):* Allocate $100\%$ of unencumbered cash upon signal. The $2\%$ account risk rule requires a defined stop distance $S_{\text{dist}}$ (e.g., $2\%$ loss limit from entry price or trailing stop).
* *Option B (Fixed Volatility Sizing):* Position Size $= (\text{Equity} \times 0.02) / (\text{Vol}_{\text{ATR}})$, capped at $100\%$ equity.
* **Stop-Loss / Take-Profit:** None explicitly supplied in core concept. Pure crossover rules rely on the opposing cross as the stop. *(Assumed for testing: Evaluate baseline without hard stops vs. adding an $X\%$ trailing stop or ATR stop).*
## π§ͺ Backtest Scenarios
```
βββββββββββββββββββββββββββββββββββββ
β Strategy Optimization β
βββββββββββββββββββ¬ββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββ
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Baseline Model β β Parameter Sweep β β Friction & β
β (50/200 SMA) β β (20/100, 10/200)β β Stress Testing β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
```
1. **Baseline Scenario:** $50\text{-day}$ SMA crossing $200\text{-day}$ SMA. $100\%$ equity allocation, zero slippage, zero commission.
2. **Conservative Scenario:** Include $0.05\%$ slippage + commission. Implement a $2\%$ hard stop-loss per position or ATR-based exit to conform strictly to the risk constraint.
3. **Aggressive Scenario:** Test Exponential Moving Averages (EMA) with faster periods ($20\text{-day} / 100\text{-day}$) to reduce signal lag during market turns.
4. **Stress-Test Scenario:** High-friction modeling ($0.15\%$ slippage per trade) combined with extreme gap-down execution simulation.
## π Market Regime Tests
To validate robustness across varying market structural states, evaluate performance separately within the following isolated date windows:
* **Bull Regimes:** Sustained macro upswings (e.g., 2012β2019, 2020β2021).
* **Bear Regimes:** Severe market drawdowns (e.g., 2000β2002 Dot-Com Crash, 2007β2008 GFC, 2022 Fed tightening).
* **Sideways / Consolidation Regimes:** Volatilities without clear directional momentum (e.g., 2015β2016 range-bound market, 2023 choppy periods).
## π Evaluation Metrics
The backtest module must output the following non-fabricated performance parameters:
```
Performance Dashboard
βββββββββββββββββββββββββ¬ββββββββββββββββββββββββ¬βββββββββββββββββββββββββ
β Absolute Return Metrics β Risk & Drawdown β Trade & Expectancy β
βββββββββββββββββββββββββΌββββββββββββββββββββββββΌβββββββββββββββββββββββββ€
β β’ CAGR β β’ Max Drawdown (%) β β’ Total Trades Count β
β β’ Total Net Return (%)β β’ Max DD Duration β β’ Win Rate (%) β
β β’ Benchmark Relative β β’ Sharpe Ratio β β’ Profit Factor β
β Alpha / Beta β β’ Sortino Ratio β β’ Expectancy ($ / %) β
βββββββββββββββββββββββββ΄ββββββββββββββββββββββββ΄βββββββββββββββββββββββββ
```
* **Absolute & Adjusted Return:** Compound Annual Growth Rate (CAGR), Total Net Return (%).
* **Risk & Drawdown:** Maximum Drawdown (MDD %), Maximum Drawdown Duration (days), Annualized Volatility.
* **Risk-Adjusted Ratios:** Sharpe Ratio (using 0% or prevailing risk-free rate), Sortino Ratio, Calmar Ratio.
* **Trade Dynamics:** Total Trade Count, Win Rate (%), Profit Factor ($\text{Gross Profit} / \text{Gross Loss}$), Average Trade Duration, Expectancy per Trade.
## β οΈ Biases, Risks & Assumptions
* **Data Leakage & Lookahead Bias:** Calculations must strictly use close data from bar $t$ to execute at open of bar $t+1$.
* **Survivorship Bias:** Must run testing using historical index constituents or survivor-bias-free ETF historical series (accounting for dividends and stock splits via total-return series).
* **Slippage & Gap Risk:** Moving-average systems suffer severe execution losses during overnight gap-down exits (e.g., exiting below the 200 SMA on a flash crash open).
* **Whipsaw Risk:** In sideways markets, moving-average crossovers produce repeated false signals, leading to consecutive losses (capital erosion).
* **Unstated Assumptions To Validate:**
* Cash reinvestment yield during out-of-market periods (assumed $0\%$ risk-free return).
* Treatment of ETF dividend yield (assumed re-invested total return index).
## β
Backtest Checklist
* [ ] Verify total-return data is adjusted for dividends and split events.
* [ ] Ensure point-in-time signal generation ($t$) executes on next-bar open ($t+1$).
* [ ] Apply fixed transaction costs and variable slippage models.
* [ ] Partition dataset into In-Sample (training/parameter search) and Out-of-Sample (validation) periods.
* [ ] Run parameter sensitivity sweeps across variable grids to map performance stability plateaus.
* [ ] Validate risk controls (ensure maximum portfolio risk stays within the $2\%$ threshold).
## π― Decision Criteria
Abandon or reject the strategy if any of the following occur during testing:
* **In-Sample vs. Out-of-Sample Decay:** Out-of-sample Sharpe ratio degrades by $> 50\%$ compared to the in-sample period.
* **Benchmark Underperformance:** CAGR fails to outperform a basic S&P 500 Buy-and-Hold strategy while displaying higher maximum drawdown.
* **Whipsaw Vulnerability:** Consecutive losing trades in range-bound regimes exhaust $> 15\%$ of total portfolio equity.
* **Low Trade Sample Size:** Fewer than 30 total trades across a multi-decade backtest, rendering metrics statistically insignificant.
By purchasing this prompt, you agree to our terms of service
GEMINI-3.6-FLASH
Turn a trading idea into a structured backtesting framework with clear entry rules, exit logic, variables, market conditions, risk controls, test scenarios, and evaluation metrics. This prompt helps traders, analysts, researchers, and strategy developers organize concepts into testable systems without assuming profitability or inventing results. ππ§
...more
Added over 1 month ago
