2. How to Run Strategy Optimization

2.1. Entry Point and Common kwargs

Run strategy optimization with qt.run(op, mode=2, ...). Common arguments include opti_method, opti_sample_count, opti_output_count, and others.

2.2. Full List of Optimization Algorithms (with Brief Explanations)

The following are common opti_method values and typical use cases; refer to the qteasy 2.0 API as the source of truth.

Algorithm

Meaning

Typical Use Case

grid

Grid search

Few parameters, discrete space; exhaustive or coarse grid search.

montecarlo

Monte Carlo random sampling

Random sampling when there are many parameters.

GA

Genetic algorithm

Medium-to-high dimensions; continuous/discrete mixed spaces.

SA

Simulated annealing

Medium dimensions; helpful when local optima are a concern.

PSO

Particle swarm optimization

Continuous space with multiple peaks.

bayesian

Bayesian optimization

Expensive evaluations; need good results in few steps.

2.3. Full List of Optimization Run Parameters (with Brief Explanations)

Parameter

Type / Values

Meaning

opti_method

str

Optimization algorithm: grid, montecarlo, GA, SA, PSO, bayesian, etc.

opti_sample_count

int

Number of samples/iterations (e.g., Monte Carlo samples or GA generations).

opti_output_count

int

Number of best results to keep (Top-K).

Objective function

E.g., Sharpe ratio or drawdown; see configuration or API docs.

Constraints

If constraints apply (e.g., max drawdown limit), see configuration.

Backtest date range, asset_pool, and other arguments shared with mode=1 also apply in mode=2.

2.4. Parameter Space

The strategy’s Parameter objects and par_range define the search space; the framework samples or searches within it according to opti_method.

2.5. Minimal Runnable Example

import qteasy as qt

op = qt.Operator(strategies='dma', signal_type='PT', run_freq='d')
# dma 策略带 short_period、long_period 等可调参数
qt.configure(asset_pool='000001.SZ', invest_start='2020-01-01', invest_end='2023-12-31')
result = qt.run(op, mode=2, opti_method='grid', opti_sample_count=100, opti_output_count=10)

2.6. Configuration Highlights

  • Backtest range and asset pool: Same as mode=1; they define the backtest environment for each parameter evaluation.

  • Objective function: Defines what “better” means (e.g., maximize Sharpe or minimize drawdown) and affects ranking and final selection.