Testing Momentum Lookback Windows with Parameter Scans
Summary
This notebook explains how to compare strategy performance across parameter values using a parameter scan. Its example targets the momentum lookback window in a strategy and tests three lengths: 252, 126, and 63 trading days, described approximately as twelve, six, and three months. The scan is run over a specified historical date range and writes its output to a CSV file.
The notebook then shows that the CSV can be used to create a parameter-scan tear sheet for reviewing the alternatives. The example demonstrates a workflow for evaluating sensitivity to one strategy setting; it does not report which window performed best, show scan results, or establish that any choice will generalize. A scan can target strategy parameters defined as class attributes, but this example varies only the momentum window. Interpretation still depends on the chosen sample period and other backtest assumptions.
Key ideas
- A parameter scan compares a strategy across selected values of a class-level parameter.
- The example varies the momentum lookback among 252, 126, and 63 trading days.
- The scan covers a specified date range and saves results in a CSV file.
- A tear sheet can summarize the scan, but the notebook gives no performance conclusion or evidence of out-of-sample robustness.
Tags
Full text
# Moonshot Parameter Scans
<a href="https://www.quantrocket.com"><img alt="QuantRocket logo" src="https://www.quantrocket.com/assets/img/notebook-header-logo.png"></a><br>
<a href="https://www.quantrocket.com/disclaimer/">Disclaimer</a>
***
[Moonshot Intro](Introduction.ipynb) › Part 6: Moonshot Parameter Scans
***
# Moonshot Parameter Scans
You can use parameter scans to test variations of your strategy. In this notebook we'll test several different window lengths for calculating momentum.
A parameter scan can target any strategy parameter defined as a class attribute on the strategy. In this example `MOMENTUM_WINDOW` is the parameter we will target:
```python
class UpMinusDown(Moonshot):
CODE = "umd"
MOMENTUM_WINDOW = 252
```
We'll compare 3 window lengths: 12 months (approx. 252 trading days), 6 months (126 trading days), and 3 months (63 trading days):
```python
from quantrocket.moonshot import scan_parameters
scan_parameters("umd-demo",
param1="MOMENTUM_WINDOW",
vals1=[252, 126, 63],
start_date="2018-01-01",
end_date="2020-04-01",
filepath_or_buffer="umd_moonshot_MOMENTUM_WINDOW.csv")
```
As with the backtest, a parameter scan returns a CSV, which we can use to generate a tear sheet using Moonchart:
```python
from moonchart import ParamscanTearsheet
ParamscanTearsheet.from_csv("umd_moonshot_MOMENTUM_WINDOW.csv")
```
***
## *Next Up*
Part 7: [Debug Moonshot Strategies](Part7-Debug-Moonshot-Strategies.ipynb)





Shown in full with attribution under the source's licence. Licence: Apache-2.0
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.