Optimize a Trading Strategy: Genetic Search

In computer science and operations research, a genetic algorithm (GA) is a metaheuristic inspired by the process of natural selection that belongs to the larger class of evolutionary algorithms (EA). Genetic algorithms are commonly used to generate high-quality solutions to optimization and search problems by relying on biologically inspired operators such as mutation, crossover and selection.

For mathematical details you can refer to this wikipedia article. Long story short we can use the following genetic search procedure to find the best trading parameter candidate for any given trading algorithm:

[1] Creation: Create a list of objects each of which holding the trading parameters as their properties. The initial values for these properties can be randomly picked. We call these objects “individuals”.

[2] Evaluation: Evaluate the fitness of the individuals using some sort of criterion (e.g. expected final account balance). The criterion is directly related to how you envision that one set of trading parameter values is considered to be better than another. Please refer to our previous article to avoid a common pitfall. Choose the top few individuals with high fitness scores. We call these individuals “parents”.

[3] Reproduction: Mate the parents by somehow generating new sets of trading parameter values from the parents’ trading parameter values (e.g. taking weighted averages). We call these newly generated sets of trading parameter values “children”. If needed, give the children a small chance to mutate by slightly changing their trading parameter values.

[4] Elimination: Evaluate the fitness scores of the children. Examine the fitness scores of all the parents and children and remove the bottom few individuals with low fitness scores so that the entire population is brought back to its original number. At this point, we can proceed to the next round of reproduction-evaluation-elimination cycle.

[5] Termination: After enough rounds of reproduction-evaluation-elimination cycles, we’d find that the highest fitness score in the population can no longer be improved from one cycle to the next. This means the solution has converged, the best candidate has been found, and the procedure can be terminated.

If it hasn’t sounded too complicated so far, here is a concrete implementation in ~150 lines of code in the context of simplified Avellaneda-Stoikov market making: https://gist.github.com/cryptochassis/198b4d34837ec88676febd146140cdd3. Admittedly sometimes mathematics can be big headaches. However, we’d like to kindly remind our readers that algorithmic traders (i.e. us) make a living not based on sheer good luck but rather based on rigorous math in solid theoretical foundation plus flawless implementation in code. This is the edge that we have.

If you need help in math or coding, feel free to let us know by joining us on Discord https://discord.gg/b5EKcp9s8T. 🎉 We specialize in market data collection, high speed trading system, infrastructure optimization, and proprietary market making.

Disclaimer: This is an educational article rather than investment/financial advice.

--

--

More from Open Crypto Trading Initiative

An ongoing effort to embrace and promote open solutions for the crypto financial services industry