# Algorithm optimisation using permutations

#### xbuster

Hi!

I've a question. I've developed number of quantitative trading algorithms and now looking for the way to optimize input parameters.

I've decided to "run" the algorithms with various permutations of input parameters and the store historic trades in database.

Now what I'm looking is easy way to compare between all results that created by all permutation runs and be able according to rules I define to find the best choice.

I had in mind some library that I can use coding let's say in C# to get some results like: gain, sharpe ratio, maximum drawdown etc and then I can build some function that will choose the best permutation.

Please let me know if I'm thinking right. Please advise on some tools, libraries, batch processes that I can use.

#### Springer

Well your best solution is to use the CS IMSL Library:

IMSLCS

The only downer is you won't be able deploy your solutions to other workstations.

If that's a big deal for you, I recommend writing your own optimizer. I came across plenty of examples of the simplex, BFGS, metaheuristics out there.

#### xbuster

Thank you!

Looks like overkill for my problem, but I'll definitely check this out. Any other ideas?

#### GoIllini

##### Market Crises= Gray Hair
Based on what you're saying, I believe that finding a guaranteed absolute maximum for this optimization problem is actually NP-Hard as there could potentially be O(2^n) local maxima and no way to be sure which local maxima is going to be highest or whether it will be higher than all the edges until you check that local maxima. In other words, your problem's scope and complexity is going to double (or worse) every time you add an extra dimension to the function, and unless you keep the function to optimize very limited in scope, there's nothing you can really do to work around this.

There are some tools to handle optimization problems across a limited number of variables- most of them involve randomized hill-climbing algorithms and can usually find the absolute maximum relatively easily for a smaller number of variables.

#### xbuster

Thank you GoIllini & Springer.

I think I didn't explain myself properly. What I'm looking for is a "Tool" or "Library" that can take as input trading log and will allow me easyly calculate various statistics like maximum drawdown, sharpe ratio etc. (I don't want to create code for implement statistical functions by myself). It's very important that I can use code to run that "Tool" or "Library" in order to programmaticaly calculate statistical indicators that I choose.

After I'll have such tool my goal is to construct function "F" from various statistical indicators according to weight I choose for each and then look for maximum "F" value in permutations of runs of my algorithm.

#### Springer

Sorry xbuster i read to much into your first sentence about being able to "optimize input parameters".

Anyway, I don't recall coming across a library in CS with the performance measures you're looking for (why not write one?). There are a couple measures (Sharpe) in the "tseries" package in R though, I'm sure there are more packages I admittedly didn't look that hard. And if you're nervous about creating the code for the measures R is good for making a quik and dirty attempt of it.

http://cran.r-project.org/web/packages/tseries/tseries.pdf

#### xbuster

Thank you. I see that there are a couple of parameters that I can use.

You are right I don't have the time and guts to write library of my own. I think there is at least one that will suit my needs, but I didn't find it yet.

Here is example for various statistical outputs from one of the Utilities that I use. I would be very happy to find a library that can help me calculate most of them.

Total Net Profit
Gross Profit
Gross Loss
Profit Factor
Final Account Equity
Return on Starting Equity
Percent Profitable
Max Number of Shares
Minimum Number of Shares
Average Number of Shares
/Percent of Equity
Average Length of Wins
Max Number Consecutive Wins
/Percent of Equity
Average Length of Losses
Max Number Consecutive Losses
Win/Loss Ratio
Win/Loss Ratio (%/%)
Return/Drawdown Ratio
Modified Sharpe Ratio
Sharpe Ratio
Average Annual Profit/Loss
Ave Annual Compounded Return
Average Monthly Profit/Loss
Ave Monthly Compounded Return
Average Weekly Profit/Loss
Ave Weekly Compounded Return
Average Daily Profit/Loss
Ave Daily Compounded Return
Number of Drawdowns
Average Drawdown
Average Drawdown (%)
Average Length of Drawdowns
Worst Case Drawdown
/Percent of Equity
Date at Trough
Length of Drawdown
Worst Case Drawdown (%)
/Equity Value
Date at Trough
Length of Drawdown
Longest Drawdown
Start of Drawdown
End of Drawdown
Percent of Equity

#### GoIllini

##### Market Crises= Gray Hair
Thank you GoIllini & Springer.

I think I didn't explain myself properly. What I'm looking for is a "Tool" or "Library" that can take as input trading log and will allow me easyly calculate various statistics like maximum drawdown, sharpe ratio etc. (I don't want to create code for implement statistical functions by myself). It's very important that I can use code to run that "Tool" or "Library" in order to programmaticaly calculate statistical indicators that I choose.

After I'll have such tool my goal is to construct function "F" from various statistical indicators according to weight I choose for each and then look for maximum "F" value in permutations of runs of my algorithm.

I was referring to the second tool you'll need to find the parameters that maximize the multivariable function "F" (this is non-trivial- it's not like looking at a function of a single variable and identifying the absolute max by observation), and my point is that it's probably feasible to optimize across less than 5-10 variables, but it's probably not feasible to optimize across 50-100.

You may have to code some of this up yourself.

#### joel_b

At that point would you develop decision trees based on your own preferences to find a preferred local maxima point? I mean given x variables and a solution being unsolveable, what is the preferred next step? Just getting into all of this. Is Evolutionary Computing being used significantly in Financial Engineering?

Replies
3
Views
2K
Replies
11
Views
2K
Replies
5
Views
1K
Replies
1
Views
388
Replies
20
Views
3K