turtle_quant_1.strategies.mean_reversion.roc_multi_condition_crossover¶
turtle_quant_1.strategies.mean_reversion.roc_multi_condition_crossover
¶
Rate of Change (RoC) Multi-Condition Crossover strategy with trend filter.
RocMultiConditionCrossover
¶
RocMultiConditionCrossover(
roc_period: int = 14,
signal_period: int = 9,
trend_period: int = 90,
min_threshold: float = 1.0,
use_zero_filter: bool = True,
use_trend_filter: bool = True,
)
Bases: BaseStrategy
A strategy using RoC crossover with optional zero-line, threshold, and trend filters.
This strategy is a combination of the RoC crossover strategy and the trend filter strategy.
The following filters are applied:
- Zero-line filter: Ignore signals if RoC > 0 for buys and RoC < 0 for sells.
- Threshold filter: Ignore signals if |RoC| < min_threshold.
- Trend filter: Only take long signals if price > SMA(trend_period),
short signals if price < SMA(trend_period).
The filters are put in place to mute signal noise, thus reduce false signals.
Leading / Lagging: TODO Lag period (in candles): TODO Effect: TODO
Refer to: https://www.investopedia.com/terms/r/rateofchange.asp
Initialize the RoC multi-condition crossover strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
roc_period
|
int
|
The number of candles to calculate RoC. |
14
|
signal_period
|
int
|
The number of candles to smooth RoC into a signal line. |
9
|
trend_period
|
int
|
Lookback period for trend filter (SMA). |
90
|
min_threshold
|
float
|
As a percentage. Ignore signals if |
1.0
|
use_zero_filter
|
bool
|
If True, require RoC > 0 for buys and RoC < 0 for sells. |
True
|
use_trend_filter
|
bool
|
If True, only take long signals if price > SMA(trend_period), short signals if price < SMA(trend_period). |
True
|
Source code in src/turtle_quant_1/strategies/mean_reversion/roc_multi_condition_crossover.py
generate_historical_scores
¶
Generate historical scores based on RoC crossovers with filters.
NOTE: Assume that the data is sorted by datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame with OHLCV data. |
required |
symbol
|
str
|
The symbol being analyzed. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
Score array with values between -1.0 and +1.0, indexed by the original data's index. |
Source code in src/turtle_quant_1/strategies/mean_reversion/roc_multi_condition_crossover.py
generate_prediction_score
¶
Generate the latest prediction score.
NOTE: Assume that the data is sorted by datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
The data to use for the strategy. |
required |
symbol
|
str
|
The symbol being analyzed. |
required |
Returns:
| Type | Description |
|---|---|
float
|
A float between -1.0 and +1.0 representing the most recent signal. |