There are several ways to optimize a trading system in QuantShare. In the first post (Optimization of a trading system), we described two different ways to perform a trading system optimization. The first one consists of optimizing trading rules by specifying optimizable variables within vector-based formulas. The second one allows us to optimize trading strategy' settings, like the maximum number of positions, the initial capital... In this post, we will describe how to perform an optimization using the Money Management scripting language. This technique is the most powerful and also the most advanced. Optimization using the Money Management scripting language: In the simulator form, click on "New" to add a trading system. To create a money management script, select "Money Management" then click on "Add a new money management script". To update a script, just click on "Update Script". There are two ways to create optimizable variables; both can only be defined in the "OnStartSimulation" event. The "Optimize" class: Example: Optimize.OptimizeDouble("var1", 1, 100, 1); The above line creates an optimizable variable called "var1", which varies between 1 and 100 with a step of one. The "Functions" class: Example: Functions.SetNumericInput("var1", 1, ""); This function creates an input. This input can be updated and optimized using a user-friendly control. Click on the "Plus" button next to "Optimize" to enable the optimization of this input. The trading software internally creates an optimizable variable using the "OptimizeDouble" function. In the script, the function "Variables.GetVariable("var1")" allows you to retrieve the content of the variable "var1". It returns a different value depending on the trading system's combination that is tested. Here is an example: You creates a script that stops trading for 20 days each time the trading system's drawdown drops below -10%. In order to test different periods and different drawdown thresholds, you change the period (20) by specifying an input (Functions.SetNumericInput) and the drawdown threshold (-10%) by specifying another input. After you specify different start and end periods for these two variables, and click on "Optimize" in the simulator form, the trading software backtests all the combinations of trading systems; changing the period and drawdown values on each run. Optimize text variables using the Money Management scripting language: As with numeric variables, you can optimize text variables using two different functions. The first function directly optimizes the variable by getting a value from an array you provide (a different value for each optimization run). Optimize.OptimizeText("var2", array); The second function creates an input, which can be optimized using the user-friendly control. Functions.SetTextInput("var2", "field1", "var2"); Values should be separated by a comma. There are several cases where it is useful to optimize text variables. For example, you can specify several database fields, so each time the simulator creates a new trading system, a new database field is used in the trading decision process.
|