QMT quantitative trading software use strategy (2) - strategy writing

[Strategy Editor] is specially designed by Xuntou for model developers. It integrates model list, function list, function help, model basic information, parameter settings, backtest parameters and other parts. It has code highlighting and automatic completion. A convenient model editing and development environment integrating convenient functions

Writing a Python policy requires defining an encoding format, such as gbk, at the beginning. After that, you can choose to import a third-party library, and the selected third-party library can only be run if it is in the white list of the brokerage management terminal. The definition of Init method and handlebar method is required. The Init method will be called once at the beginning of the strategy operation to initialize the required objects (wrapped in the ContextInfo object), set the stock pool, and so on.

 

The Handlebar method will be called K line by K line on the historical K line, and the system will save the changes made by the function. During intraday trading hours, the handlebar function will be called along with the market push (tick data). When a tick data is the last tick of the K line, the changes made by the handlebar called by this tick will be saved by the system. If there is a trading order , will be sent when the first tick of the next K line arrives; other ticks can print the running results, but the changes made by the handlebar will not be saved, and no trading signals will be sent. After writing and creating the model, set the basic information and backtest parameters of the corresponding model.

Name: Fill in the model name Shortcut code: By default, the first letter of pinyin is automatically generated according to the model name. If you need to customize it, you can manually change it, which is used for quick reference of the keyboard wizard. Model description: Simple description Model function classification: Save the current model to a certain Classify the following positions: The position of model backtesting or running, there are three display positions: sub-chart, main chart overlay, and main chart. The default main graph variety when the model is backtested or running, and the reweighting method can be manually switched: Provides 5 reweighting methods: no reweighting, pre-reweighting, post-reweighting, equal-scale before-reweighting, and equal-ratio post-reweighting methods for quick calculation: limit the calculation range, the default is When 0, the model operation will start calculation from the first K line of the default product (main chart) set by the model, and if it is set to n, the calculation refresh interval will start from the current K line and then the previous n K lines: Used to set the strategy operation time interval. The refresh interval is set, that is, the strategy runs the encryption formula according to the current market every once in a while: The source code of the encrypted formula can only be viewed by entering the password. Afterwards, you can only use the password to export to the local. Usage Notes: A brief description of some precautions for the use of the model, which can be left blank

 

The strategy editor-basic information backtest mode means that the strategy is calculated based on the historical market, and investors can observe the performance of the strategy's annualized rate of return, Sharpe ratio, maximum retracement, information ratio and other indicators obtained in the historical market.

Backtest parameters include: Start time, end time: Set the model backtest time interval benchmark: Set the reference benchmark initial capital for model returns: Set the initial capital margin ratio for model backtesting: Set the margin ratio slippage for futures: Set backtest matching Slippage when simulating the impact cost of real transactions Handling fee type: Support calculating the handling fee according to the transaction volume ratio or fixed value Buying stamp duty: Set the buying stamp duty ratio Selling stamp duty: Set the selling stamp duty ratio Minimum commission: Set single transaction The minimum commission amount for the transaction Buy commission: Set the commission ratio when buying the target Flat yesterday commission: Set the stock and futures flat yesterday commission ratio Flat today commission: Set the futures flat commission ratio Maximum transaction ratio: Control the maximum trading volume in backtesting It should not exceed the ratio of transaction volume in the same period * maximum transaction ratio. You can click the '? ' button for details

 

Strategy editor - backtest parameter users can also set the parameter value in the parameter setting, the parameter name is the variable name, and it can be called in the model. The latest value is the variable default value, used in run/backtest mode. Among them, the minimum/maximum/step length items are traversal parameters. The initial item can be left blank. The minimum/maximum is included in the traversal interval. As shown in the figure, the three variables will traverse (20-3+1)[(160-140)/10+1][(-150+250)/ 10+1] combinations.

Strategy Editor - Parameter Settings Click the formula evaluation, and you can select the indicators supported by the backtest mode, such as unit net value, maximum drawdown, etc., as the evaluation standard.

 

Strategy Editor - Formula Evaluation Click Optimize, the evaluation result pop-up window displays the backtest results under different parameter variable combinations, and select the optimal parameter combination according to the results. You can sort by clicking on the desired indicator. It should be noted that before the evaluation, it is necessary to supplement the data for the selected variety and cycle.

 

 

 

Guess you like

Origin blog.csdn.net/LIUTIAN902/article/details/126607457