#twitter-follow { border: 0;position: fixed; top: 240px; left:0;} #live-support { border: 0;position: fixed; top: 370px; left:0;} #knowledge-base { border: 0;position: fixed; top: 170px; left:0;}

### Optimize a trading strategy using the Sharpe ratio

Updated on 2010-07-06

We all agree that a strategy that returns 50% is better than the one that returns only 30%. But what if the volatility of the daily returns of the first strategy is 50% and the maximum drawdown is 60%, while in the second strategy the volatility is only 30% and the maximum drawdown is 20%.
Like most traders, I will certainly go with the second strategy despite the fact that it provides a lower return. Decreasing risk should be our top priority in the trading and investment world.

It is easier to compare different strategies using a single metric. We can for example us the Sharpe ratio which is very popular measure of return per unit of risk. It will instantly tell us which is the better strategy. In a single measure it includes both return and risk information about a strategy.

Usually when traders perform trading strategy's optimizations using an advanced algorithm such as the genetic algorithm, they put too much emphasizes on strategies' return. They usually set the strategy's return as the fitness formula of the genetic algorithm.

In genetic algorithms, the fitness is a value used as a rank measure. It let the program knows which trading strategy to choose when creating new generations.
As we said, strategy's return is often used to define the fitness of a genetic algorithm. This is good, but we can get much better results if we change the fitness and include a measure that incorporate both return and risk, such as the Sharpe Ratio.

In the Optimizer tool of QuantShare, you can select what to optimize (Trading rules, trading system, neural network model, ranking system), which algorithm to use (Genetic Algorithm or PBIL) and you can also create your own fitness function.

Select "AI" -> "Optimizer" then click on "Create". In the Optimizer form, select "Trading System" then click on "Next" twice. Below, there is a text editor where you can type your fitness formula. As with all scripts in this trading software, you can click on CTRL + SPACE to display the list of available variables.

By default, the fitness formula is set to:
Fitness = AnnualReturn;

This means that the annual return is used to rank strategies.
We can use instead the Sharpe Ratio as a rank measure simply by typing:
Fitness = SharpeRatio;