Persia Strategy In-Depth Analysis
Chapter 1: Strategy Overview and Design Philosophy
1.1 Strategy Background
Persia is an innovative hyperparameter optimization strategy framework created by developer Mablue (Masoud Azizi). The name "Persia" comes from the ancient Persian Empire, suggesting it embodies wisdom from its Persian developer. Unlike traditional strategies with fixed technical indicators and trading logic, Persia adopts a unique "formula-based" design, allowing the system to automatically search for the optimal trading strategy combination.
1.2 Core Design Philosophy
The core design philosophy of this strategy is "let the machine discover the optimal strategy". The strategy doesn't preset fixed buy and sell logic, but instead provides a framework containing multiple technical indicators, time periods, and mathematical formulas, automatically finding optimal combinations through Freqtrade's Hyperopt functionality.
Core design elements include:
- Flexible Indicator Combinations: Supports SMA, EMA, TEMA, DEMA four moving average types
- Flexible Time Periods: Supports multiple periods from 3 to 189
- Rich Formula System: Predefines 10 mathematical relationship formulas
- Fully Adjustable Parameters: Both buy and sell parameters support hyperparameter optimization
1.3 Strategy Positioning
Persia is positioned as a strategy discovery tool rather than a finished strategy. It's suitable for:
- Finding optimal strategies for specific market environments
- Exploring effectiveness of different indicator combinations
- Researching optimal time period configurations
- Learning quantitative strategy development methods
Chapter 2: Technical Indicator System
2.1 Moving Average Types
The strategy supports four mainstream moving averages, each with unique characteristics:
SMA (Simple Moving Average)
- Calculation: All prices weighted equally averaged
- Characteristics: Stable, strong lag
- Application: Trend confirmation
EMA (Exponential Moving Average)
- Calculation: Recent prices have higher weights
- Characteristics: Fast response, high sensitivity
- Application: Trend change detection
TEMA (Triple Exponential Moving Average)
- Calculation: Triple exponential smoothing
- Characteristics: Extremely low lag, rapid response
- Application: Short-term trading signals
DEMA (Double Exponential Moving Average)
- Calculation: Double exponential smoothing
- Characteristics: Between EMA and TEMA
- Application: Medium-short-term trend tracking
2.2 Time Period System
The strategy supports extremely rich time period configurations:
COSTUMETF = [3, 7, 9, 21, 27, 63, 81, 189]
Period Interpretation:
- 3 periods: Extremely short-term, fastest response, most noise
- 7 periods: Short-term baseline, commonly used for intraday trading
- 9 periods: Classic short-term period
- 21 periods: Near monthly period (approximately one month of trading days)
- 27 periods: Medium-long-term transition
- 63 periods: Approximately one quarter of trading days
- 81 periods: Long-term trend
- 189 periods: Super long-term trend (approximately one year of trading days)
2.3 Formula System
The strategy predefines 10 mathematical relationship formulas describing relationships between two indicators:
| Number | Formula | Meaning |
|---|---|---|
| 1 | A>B | Indicator A greater than indicator B |
| 2 | A<B | Indicator A less than indicator B |
| 3 | A*R==B | Indicator A times coefficient R equals indicator B |
| 4 | A==R | Indicator A equals specific value R |
| 5 | A!=R | Indicator A not equal to specific value R |
| 6 | A/B>R | Ratio of two indicators greater than R |
| 7 | B/A>R | Ratio of two indicators greater than R (reverse) |
| 8 | 0<=A<=1 | Indicator A between 0 and 1 |
| 9 | 0<=B<=1 | Indicator B between 0 and 1 |
Formula Application: Each buy/sell condition can choose one formula, where A and B represent two indicator values, and R represents an adjustable real number parameter.
2.4 Real Number Parameter System
The strategy defines real number parameter value ranges:
REALSRANGE = [-2, 2]
DECIMALS = 1
Real number parameter R can take values between -2.0 and 2.0, with precision of one decimal place. This parameter serves as threshold or coefficient in formulas.
Chapter 3: Parameter Structure Details
3.1 Condition Quantity Configuration
The strategy supports up to 100 independent buy and sell conditions:
CONDITIONS = 3 # Currently enables 3 conditions
Each condition includes these parameters:
- formula: Selected formula type
- indicator: Indicator A's type
- crossed: Indicator B's type (for crossover judgment)
- timeframe: Indicator A's time period
- crossed_timeframe: Indicator B's time period
- real: Real number parameter R's value
3.2 Buy Parameter Example
Currently configured buy parameters:
buy_params = {
"formula0": "A!=R",
"formula1": "0<=B<=1",
"formula2": "B/A>R",
"indicator0": "TEMA",
"indicator1": "DEMA",
"indicator2": "DEMA",
"timeframe0": 9,
"timeframe1": 3,
"timeframe2": 27,
"crossed0": "TEMA",
"crossed1": "EMA",
"crossed2": "DEMA",
"crossed_timeframe0": 81,
"crossed_timeframe1": 27,
"crossed_timeframe2": 63,
"real0": 0.5,
"real1": 1.8,
"real2": -1.4,
}
3.3 Sell Parameter Example
Currently configured sell parameters:
sell_params = {
"sell_formula0": "A==R",
"sell_formula1": "B/A>R",
"sell_formula2": "A!=R",
"sell_indicator0": "EMA",
"sell_indicator1": "DEMA",
"sell_indicator2": "TEMA",
"sell_timeframe0": 21,
"sell_timeframe1": 21,
"sell_timeframe2": 3,
"sell_crossed0": "SMA",
"sell_crossed1": "TEMA",
"sell_crossed2": "EMA",
"sell_crossed_timeframe0": 27,
"sell_crossed_timeframe1": 27,
"sell_crossed_timeframe2": 3,
"sell_real0": 1.5,
"sell_real1": 1.4,
"sell_real2": 1.6,
}
Chapter 4: Signal Generation Mechanism
4.1 Indicator Calculation Logic
The strategy calculates all indicator combinations in populate_indicators:
for indicator in indicators: # SMA, EMA, TEMA, DEMA
for tf_idx in timeframes: # 3, 7, 9, 21, 27, 63, 81, 189
dataframe[f'{indicator}-{tf_idx}'] = getattr(ta, indicator)(dataframe, timeperiod=tf_idx)
This generates 4×8 = 32 indicator columns, such as:
- TEMA-9: 9-period TEMA
- EMA-27: 27-period EMA
- SMA-189: 189-period SMA
4.2 Buy Signal Generation
Buy signals are generated through condition combinations:
for i in range(CONDITIONS):
# Get parameters
indicator = getattr(self, "indicator"+str(i)).value
crossed = getattr(self, "crossed"+str(i)).value
timeframe = getattr(self, "timeframe"+str(i)).value
crossed_timeframe = getattr(self, "crossed_timeframe"+str(i)).value
formula = getattr(self, "formula"+str(i)).value
# Build data
A = dataframe[f'{indicator}-{timeframe}']
B = dataframe[f'{crossed}-{crossed_timeframe}']
R = pd.Series([getattr(self, "real"+str(i)).value] * len(A))
# Calculate condition
df = pd.DataFrame({'A': A, 'B': B, 'R': R})
conditions.append(df.eval(formula))
# All conditions AND combined
dataframe.loc[reduce(lambda x, y: x & y, conditions), 'buy'] = 1
4.3 Current Buy Conditions Interpretation
Based on current parameters, the three buy conditions are:
Condition 0:
- Formula: A!=R (TEMA-9 not equal to 0.5)
- A = TEMA-9
- R = 0.5
Condition 1:
- Formula: 0<=B<=1 (DEMA-3 value between 0 and 1)
- B = EMA-27
Condition 2:
- Formula: B/A>R (DEMA-63 / DEMA-27 > -1.4)
- A = DEMA-27
- B = DEMA-63
- R = -1.4
Combined Logic: All three conditions must be satisfied simultaneously to trigger buy.
4.4 Sell Signal Generation
Sell logic is similar to buy, using sell_ prefixed parameters:
for i in range(CONDITIONS):
indicator = getattr(self, "sell_indicator"+str(i)).value
crossed = getattr(self, "sell_crossed"+str(i)).value
# ... similar to buy logic
Chapter 5: Risk Management Configuration
5.1 ROI Configuration
Strategy's ROI configuration is relatively aggressive:
minimal_roi = {
"0": 0.273, # Immediately: 27.3%
"26": 0.084, # After 26 minutes: 8.4%
"79": 0.033, # After 79 minutes: 3.3%
"187": 0 # After 187 minutes: 0% (forced exit)
}
Configuration Analysis:
- Initial ROI set at 27.3%, very high profit target
- After 26 minutes drops to 8.4%, still relatively high
- After 79 minutes drops to 3.3%, becoming realistic
- After 187 minutes set to 0%, forced close
This configuration indicates the strategy pursues high profits while setting a final exit mechanism.
5.2 Stop Loss Configuration
stoploss = -0.19
Interpretation: 19% stop loss is very wide, giving strategy enough room for fluctuation. Typically used for high volatility markets or strategies pursuing major trends.
5.3 Timeframe
timeframe = '5m'
5-minute timeframe is standard configuration for medium-frequency trading, balancing signal frequency and noise filtering.
Chapter 6: Hyperparameter Optimization Mechanism
6.1 Hyperopt Basics
Freqtrade's Hyperopt functionality can automatically search for optimal parameter combinations. Persia strategy is fully designed for this:
freqtrade hyperopt --hyperopt-loss SharpeHyperOptLoss --strategy Persia
6.2 Parameter Space
The strategy defines an enormous parameter space:
- Formula Selection: 10 choices per condition
- Indicator Selection: 4 choices per condition
- Time Period: 8 choices per condition
- Real Number Parameter: 40 values per condition (-2.0 to 2.0, step 0.1)
Single condition parameter space approximately: 10 × 4 × 8 × 4 × 8 × 40 ≈ 400,000 combinations Three conditions combined space is astronomical.
6.3 Optimization Suggestions
Parameter Space Control:
- Reduce CONDITIONS number (like setting to 1-2)
- Limit time period selection range
- Narrow real number parameter range
Loss Function Selection:
- SharpeHyperOptLoss: Optimize Sharpe ratio
- WinRatioLoss: Optimize win rate
- ProfitDrawDownHyperOptLoss: Balance profit and drawdown
Validation Methods:
- Use Walk-Forward validation
- Reserve test set
- Check parameter boundary issues
Chapter 7: Strategy Feature Analysis
7.1 High Flexibility
Persia's biggest feature is flexibility:
- Can simulate moving average crossover strategies
- Can simulate mean reversion strategies
- Can simulate trend following strategies
- Strategy type entirely determined by parameters
7.2 Auto Machine Learning Characteristics
Strategy has AutoML (Automated Machine Learning) philosophy:
- Automatically searches for optimal parameters
- No need for human preset logic
- Results may exceed human intuition
7.3 Overfitting Risk
High flexibility brings overfitting risk:
- Huge parameter space, easy to find "perfect match to historical data" parameters
- Good historical performance doesn't equal future effectiveness
- Requires strict validation
Chapter 8: Strategy Advantages and Limitations
8.1 Strategy Advantages
- Fully Customizable: Parameter combinations cover almost all moving average strategies
- Automatic Optimization: Automatically discover optimal combinations through Hyperopt
- Learning Value: Helps understand effects of different indicators and time periods
- Adaptability: Can optimize different parameters for different markets
8.2 Strategy Limitations
- Extremely High Overfitting Risk: Huge parameter space easily leads to overfitting
- Black Box Nature: Optimization results difficult to interpret
- Large Computational Resource Needs: Requires massive computation for parameter search
- Lacks Protection Mechanisms: No built-in stop loss protection or fund management
- Unknown Stability: Optimized parameter stability needs verification
8.3 Applicable Scenarios
Suitable for:
- Strategy research and development
- Exploring specific market patterns
- Learning quantitative trading principles
Not suitable for:
- Direct live trading (risk too high)
- Beginner use
- Scenarios pursuing stable returns
Chapter 9: Practical Usage Suggestions
9.1 Parameter Optimization Process
Step 1: Define optimization objectives
- Clarify whether pursuing high win rate, high profit/loss ratio, or Sharpe ratio
- Choose appropriate loss function
Step 2: Limit parameter space
- Reduce condition quantity
- Limit time period range
- Narrow real number parameter range
Step 3: Phased optimization
- First optimize buy conditions
- Then optimize sell conditions
- Finally joint optimization
Step 4: Validate results
- Walk-Forward validation
- Out-of-sample testing
- Parameter stability analysis
9.2 Result Interpretation
After optimization completion, need to interpret actual meaning of parameters:
Example Interpretation:
formula0: A!=R, indicator0: TEMA, timeframe0: 9, real0: 0.5
Meaning: 9-period TEMA not equal to 0.5 (price away from specific value)
Reasonability Check:
- Are parameters at boundary? (e.g., real exactly -2.0 or 2.0)
- Are time periods reasonable? (e.g., 189 periods might be too long)
- Are formulas meaningful? (e.g., A==R might be too strict)
9.3 Risk Control Supplements
Recommend adding when using:
- Stop Loss Protection: Add MaxDrawdown, StoplossGuard
- Fund Management: Limit single position size and total holdings
- Market Filter: Add trend or volatility filters
- Volume Confirmation: Add volume-related conditions
Chapter 10: Comparison with Other Strategies
10.1 Comparison with Fixed Indicator Strategies
Fixed Indicator Strategies (like NostalgiaForInfinity series):
- Clear logic, easy to understand
- Relatively fixed parameters
- Suitable for specific market environments
Persia Strategy:
- Variable logic, difficult to interpret
- Completely open parameters
- Can adapt to multiple markets
10.2 Comparison with Machine Learning Strategies
Machine Learning Strategies:
- Use neural networks and other algorithms
- Need massive data training
- Truly "black box"
Persia Strategy:
- Use traditional technical indicators
- Based on rule-based condition combinations
- Partially interpretable
10.3 Applicability Comparison
| Dimension | Persia | Fixed Strategies | ML Strategies |
|---|---|---|---|
| Flexibility | Extremely high | Low | High |
| Interpretability | Medium | High | Low |
| Overfitting Risk | High | Medium | High |
| Computational Needs | High | Low | Extremely high |
| Learning Value | High | Medium | Low |
Chapter 11: Summary
Persia is a unique strategy framework whose core value lies in providing a completely open parameter space, letting machines automatically discover optimal trading strategy combinations.
Core Features:
- Four moving average types
- Eight time periods
- Ten mathematical relationship formulas
- Fully parameterized buy and sell conditions
Greatest Advantage: Extremely high flexibility, can simulate and discover various moving average strategies
Greatest Risk: Extremely high overfitting risk, optimization results may only be effective in historical data
Usage Recommendations:
- Use only for research and learning
- Strictly limit parameter space
- Conduct sufficient validation
- Add risk management mechanisms
- Don't directly use optimization results for live trading
Persia is more like a research tool than a finished strategy. It demonstrates an interesting direction in quantitative trading—letting machines automatically discover trading patterns, while also reminding us of overfitting dangers. For traders wanting to deeply understand technical indicator and time period effects, this is an excellent learning platform.