Menu

Trading system design and optimization

4 Comments

trading system design and optimization

The idea behind an optimization is simple. First you have to have a trading system, this may be a simple moving average crossover for example. In almost every system there are some parameters as averaging period that decide how system system behaves i. The optimization is the process of finding optimal values of those parameters giving highest profit from the system for a given symbol or a portfolio of symbols. AmiBroker is one of the very few programs that allow you to optimize your system on multiple symbols at once. To optimize your system you have to define from one upto ten parameters to be optimized. Optimization decide what is a minimum and maximum allowable value of the parameter and in what increments this value should be updated. AmiBroker then performs multiple back tests the system using ALL possible combinations of parameters values. When this process is finished AmiBroker displays the list of results sorted by net profit. You are able to see the values of optimization parameters that give the best result. Optimization in back tester is supported via new function called optimize. The syntax of this function is as follows:. With normal backtesting, scanning, exploration and comentary modes the optimize function returns default value, so the above function call is equivalent to: In optimization mode optimize function returns successive values from min to max inclusively with step stepping. After entering the formula just click on Optimize button in "Automatic Analysis" window. AmiBroker will start testing all possible combinations of optimization variables and report the results in the list. The last columns of result list present the values of optimization variables for given test. When you decide which combination of parameters suits your optimization the best all you need to do is to replace the default values in optimize function calls with the optimal values. At current stage you need to type them by hand in the formula edit window the second parameter of optimize function call. To display 3D optimization chart, you need to run two-variable optimization first. Two variable optimization needs a formula that has 2 Optimize function calls. An example two-variable optimization formula looks like this:. Once optimization is complete you should click on the drop down arrow on Optimize button and choose View 3D optimization graph. In a few seconds a colorful three-dimensional surface plot will appear in a 3D chart viewer window. An example 3D chart generated using above formula is shown and. By default the 3D charts display values of Net profit against optimization variables. You can however plot 3D surface chart for any column in the optimization result table. Just click on the column header to sort it blue arrow will appear indicating that optimization results are sorted by selected column and then choose View 3D optimization graph again. By visualizing design your system's parameters affect trading performance, you can more readily decide which parameter values produce "fragile" and which produce "robust" system performance. Robust settings are regions in the 3D graph that show gradual rather than abrupt changes in the surface plot. Curve-fitting or over-optimization occurs when the system is more complex than it needs to be, and all that complexity was focused on market conditions that may never happen again. Radical changes or spikes in the 3D optimization charts show clearly over-optimization areas. You should choose parameter region that produces a broad and wide plateau on 3D chart for your and life trading. Parameter sets producing profit spikes will not work reliably in real trading. AmiBroker's 3D chart viewer offers total viewing capabilities with full graph rotation and animation. Now you can view your system results from every conceivable perspective. You can control the position and other parameters of the chart using the mouse, toolbar and keyboard shortcuts, whatever system find easier for you. Below you will find the list. SPACE - animate auto-rotate LEFT ARROW KEY - rotate vert. AmiBroker now offers smart non-exhaustive optimization in addition to regular, exhaustive search. Non-exhaustive search is useful if number of all parameter combinations of given trading system is simply too large to be feasible for exhaustive search. Exhaustive search is perfectly fine as long as it is reasonable to use it. Let's say you have 2 parameters each ranging from 1 to step 1. That's combinations - perfectly OK for exhaustive search. Now with 3 parameters you got 1 million combinations - it is still OK for exhaustive search but can be lenghty. With 4 parameters you have million combinations and with 5 parameters In that case it would be too time consuming to check all of them, and this is the area where non-exhaustive smart-search methods can solve the problem that is not solvable in reasonable time using exhaustive search. Here is absolutely the SIMPLEST instruction how to use new non-exhaustive optimizer in this case CMA-ES. Optional Select your optimization target in Optimization Analysis, Settings, "Walk-Forward" tab, Optimization target field. Now if you run optimization using this formula, it will use new evolutionary non-exhaustive CMA-ES optimizer. The optimization is the process of finding minimum or maximum of given function. Any trading system can be considered as a function of certain number of arguments. And you are looking for maximum of given function. Some of smart optimization algorithms are based on nature animal behavior - PSO algorithm, or biological process - Genetic algorithms, and some are based on mathematical concepts derived by trading - CMA-ES. These algorithms are used in many different areas, including finance. Enter "PSO finance" or "CMA-ES finance" in Google and you will find lots of info. Non-exhaustive or "smart" methods will find global or local optimum. The goal is of course to find global one, but if there is a single sharp peak out of zillions parameter combinations, non-exhaustive methods may fail to find this single peak, but taking it form trader's perspecive, finding single sharp peak is useless for trading because that result would be instable too fragile and not replicable in real trading. In optimization process design are rather looking for plateau regions with stable parameters and this is the area where intelligent methods shine. Example stop criteria can include: To use any smart non-exhaustive optimizer in AmiBroker you need to specify the optimizer engine you want to optimization in the AFL formula using OptimizerSetEngine function. The function selects external optimization engine defined by name. AmiBroker currently ships with 3 engines: Standard Particle Swarm Optimizer "spso"Tribes "trib"and CMA-ES "cmae" - the names in braces are to be used in OptimizerSetEngine calls. In addition to selecting optimizer system you may want to set some of its internal parameters. To do so use OptimizerSetOption function. The function set additional parameters for external optimization engine. The parameters are engine-dependent. All three optimizers system with AmiBroker SPSO, Trib, System support two parameters: The behaviour of each parameter is engine-dependent, so same values may and usually will yield different results with different engines used. The difference between Runs and MaxEval is as follows. Evaluation or test trading single backtest or evaluation of objective function value. RUN is one full run of the algorithm finding optimum value - usually involving and tests evaluations. Each run simply RESTARTS the entire optimization process from the new beginning new initial random population. So Runs parameter defines number of subsequent algorithm runs. MaxEval is the maximum number of evaluations bactests in any single run. If the problem is relatively simple and tests are enough to find global max, 5x is more likely to find global maximum because there are less chances to be stuck in local max, as subsequent runs will start from different initial random population. Choosing parameter values can be tricky. It depends on problem under test, design complexity, etc, etc. The easiest answer is to: Another simple advice is to multiply by 10 the number of tests with adding new dimension. That may lead to overestimating number of tests required, but it is quite safe. It is important to understand that all smart optimization methods work best in continuous parameter spaces and relatively smooth objective functions. If parameter space is discrete evolutionary algorithms may have trouble finding optimum value. If your trading system contains many binary parameters, you should not use smart optimizer directly on them. Instead try to optimize only continuous parameters using smart trading, and switch binary parameters manually or via external script. Standard Particle Swarm Optimizer is based on SPSO code that is supposed to produce good results provided that correct parameters i. Runs, MaxEval are provided for particular problem. Picking correct options for the PSO optimizer can be tricky therefore results may significantly vary from case to case. Example code for Standard Particle Swarm Optimizer: OptimizerSetEngine "spso" ; OptimizerSetOption "Runs", 1 ; OptimizerSetOption "MaxEval". Tribes is adaptive, parameter-less version of PSO particle swarm optimization non-exhaustive optimizer. For scientific background see: In theory it should perform better than regular PSO, because it can automatically adjust the design sizes and algorithm strategy to the problem being solved. DLL plugin implements "Tribes-D" i. Original source codes used with permission from the author. OptimizerSetOption "MaxEval", ; You should increase the number design evaluations with increasing number of dimensions number of optimization params. Trading default is good for 2 or maximum 3 dimensions. CMA-ES Covariance Matrix Adaptation Evolutionary Strategy is advanced non-exhaustive optimizer. DLL plugin implements "Global" variant of search with several restarts with increasing population size CMAE. DLL comes with full source code inside "ADK" folder. By default number of runs or restarts is set to 5. It is advised to leave the default number of restarts. You may vary it using OptimizerSetOption "Runs", N call, where N should be in range Specifying more than 10 runs is not recommended, although possible. Note that each run uses TWICE the size of population of previous run so it grows exponentially. There is another parameter "MaxEval". The default value is ZERO which means that plugin will automatically calculate MaxEval required. It is advised to NOT to define MaxEval by yourself as default works fine. The algorithm is smart enough to minimize the number of evaluations required and it converges very fast to solution point, so often it finds solutions faster than other strategies. It is normal that the plugin will skip some evaluations steps, if it detects that solution was found, therefore you should not be trading that optimization progress bar may move very fast at some points. The plugin also has ability to increase number of steps over initially estimated value if it is needed to find the solution. It should be noted, as it is the case and many continouos-space search algorithms, that decreasing "step" parameter in Optimize funciton calls does not significantly affect optimization times. The only thing that matters is the problem "dimension", i. The number of "steps" per parameter can be set without affecting the optimization time, so use the finest resolution you want. In practice it converges a LOT faster. Starting from AmiBroker 5. To access this functionality, click on drop down arrow next to "Optimize" button in the New Analysis window and select " Individual Optimize ". In "Current symbol" mode it will perform optimization on one symbol. In "All symbols" and "Filter" modes it will process all symbols sequentially, i. Optimization backtester is NOT supported yet 2. For explanation of these limitations see Tutorial: Efficient use of multi-threading. Eventually and may get rid of limitation 1 - when AmiBroker is changed so custom backtester does not use OLE anymore. But 2 is probably here to stay for long.

Trading systems backtest and optimization with NinjaTrader

Trading systems backtest and optimization with NinjaTrader trading system design and optimization

4 thoughts on “Trading system design and optimization”

  1. aleks01 says:

    The following is a guide only to the legislation currently in place that impacts on equality. and diversity issues, and is not a comprehensive list.

  2. akkond says:

    Most tarot cards are produced up of the Major Arcana and the Small Arcana.

  3. andrey36484 says:

    This post is for the women who are short on grace for themselves.

  4. andrejsx says:

    I did feel like there was a little too much info-dumping, though.

Leave a Reply

Your email address will not be published. Required fields are marked *

inserted by FC2 system