14. Machine Learning Stock Selection Strategies (Teaching Framework)
Reference source: docs/_joinquant_migration_source/Example_14_machine learning stock selection.ipynb First Markdown cell.
14.1. Strategy and Ideas
The original idea was “sliding window features + SVM binary classification”;
The teaching framework emphasizes the Qteasy workflow:
feature/prediction->signal->backtesting;The default implementation avoids repeated retraining in the backtesting loop, instead approximating the model output with lightweight rules to avoid performance and reproducibility issues.
14.2. Honesty
If you want to use a real machine learning model, it is recommended to train it offline outside the policy and solidify the prediction results before reading them into the policy.
This makes it easier to avoid forward bias and control the operating costs of the optimization mode.
from examples.strategies.example_strategies import Example14MLSkeleton
import qteasy as qt
stg = Example14MLSkeleton()
op = qt.Operator(stg, signal_type='PS')
op.op_type = 'stepwise'
op.set_blender('1.0*s0')
res = qt.run(
op,
mode=1,
asset_type='E',
asset_pool=['600000.SH'],
benchmark_asset='600000.SH',
invest_start='20190101',
invest_end='20211231',
invest_cash_amounts=[1000000],
trade_batch_size=100,
sell_batch_size=1,
trade_log=True,
)
14.3. Executable script
examples/strategy_example_14.py