PDA

View Full Version : Optimiser Type


dgregor5
09-05-2007, 12:21 PM
Hi - is it possible to use different optimiser types with NT? if so, who are the best people to contact to develop the appropriate methodologies - I am particularly interested in Genetic Algorithms.............

thx
David

NinjaTrader_Dierk
09-05-2007, 12:33 PM
Unfortunately NT only supports the brute force optimization (testing all possible parameter combinations).

dgregor5
09-05-2007, 12:43 PM
is not possible to use a 3rd party algorithm that can be incorporated into NT ?

NinjaTrader_Dierk
09-05-2007, 12:45 PM
Unfortunately not

dgregor5
09-05-2007, 12:46 PM
any plans ?

NinjaTrader_Dierk
09-05-2007, 12:47 PM
Not right now

vtaran
12-31-2007, 10:53 PM
It's quite easy to replace default brute force optimizer. Override Optimize() method in class derived from OptimizationMethod.
Use Documents\NinjaTrader6\bin\Custom\Type\@DefaultOpt imizationMethod.cs file as a sample. I use Monte Carlo (random) time-limited optimizer. Finds good parameters much faster.

dgregor5
01-01-2008, 03:47 AM
vtaran
thx for the reply. I am aware that it is possible to change the optimiser type in NT, but was not aware of any available NT alternatives (until the System Quality Number thread here in the Support Forum). Do you have details of the Monte Carlo optimiser that you are using, i.e. where did you get it from? is it specific to NT, costs, etc.).

many thx in advance
David

Pete S
01-01-2008, 07:59 AM
There's a difference between Optimizer and OptimizerType. The Optimizer runs the actual test, has the ability to select which parameters to use, etc. The OptimizerType (e.g. the SQN I posted) ranks the result from one iteration. You are interested in the Optimizer.

vtaran
01-01-2008, 06:06 PM
I wrote optimizer myself. It iterates through parameters not sequentially but randomly for preselected time. If brute force optimization is going to take many hours/days I use random optimizer to narrow the ranges (and often it finds parameters very close to optimal). Than default optimizer can be used for fine tuning if required. Later I will write Genetic optimizer. Don't have much time now. Current version of NT Default (brute force) optimizer is too basic. As a minimum it should be multithreaded.

dgregor5
01-02-2008, 04:39 PM
appreciate your comments guys- thx !
David

zoltran
01-02-2008, 05:47 PM
vtaran .. would you mind posting your optimiser?

Jenny
01-18-2008, 03:44 AM
I am very insterested in this topic too. Can you post your optimizer?
Thanks

NinjaTrader_Josh
01-18-2008, 03:52 AM
To get more than the default two optimizer types you will need to do what vtaran did and program your own. The other files in the folder are what you optimize for and not the optimizer type itself.

Jenny
01-18-2008, 08:24 AM
Josh,
Thanks for your reply.
IF zoltran or somebody else can give us the optimizer, it would be great.

Jenny
01-19-2008, 10:35 AM
It looks I have to code my own optimizer type.
Then I try to get random number between 0
~1, I use RAND(), some how NT give an error. What I should use to create a random number?
Thanks

NinjaTrader_Josh
01-19-2008, 03:52 PM
http://www.geekpedia.com/tutorial238_Generate-Random-Numbers-using-Csharp.html

Jenny
01-19-2008, 06:06 PM
Josh,
I copy 2 lines to my code, NT can't compile, what I do wrong? Thanks!
Random randNum = new Random();
randNum.Next(1, 108); // No larger than 108, no smaller than 1

NinjaTrader_Josh
01-19-2008, 06:07 PM
What is the error you are getting?

In the variables section do this:
private Random randNum = new Random();

In the OnBarUpdate() method do this:
Print(Time[0] + " " + randNum.Next(1, 108));
or if you want it between 0 and 1
Print(Time[0] + " " + randNum.NextDouble());

Jenny
01-20-2008, 07:52 AM
Josh,
Good morning.
I try to use it in the file for optimizer to change the index:
index=randNum.Next(parameter.Min,parameter.Max), I have delcared the ....

Jenny
01-20-2008, 08:54 AM
this had been deleted.

Jenny
01-20-2008, 08:57 AM
Please forget about my last post. Here is an updated file:
//
// Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
//
#region Using declarations
using System;
using System.ComponentModel;
using System.Drawing;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// </summary>
[Gui.Design.DisplayName("Random")]
public class RandomOptimizationMethod : OptimizationMethod
{
/// <summary>
/// This methods iterates the parameters recursively. The actual back test is performed, as the last parameter is iterated.
/// </summary>
/// <param name="index"></param>
private void Iterate(int index)
{if (UserAbort)
return;
Parameter parameter = Strategy.Parameters[index];
if (parameter.ParameterType != typeof(int) && parameter.ParameterType != typeof(double))
{
if (index == Strategy.Parameters.Count - 1) // last parameter ?
RunIteration();
else // iterate next parameter
Iterate(index + 1);
return;
}

double value = randNum.Next(parameter.Min, parameter.Max); {
if (UserAbort)
return;

parameter.Value = value;
if (index == Strategy.Parameters.Count - 1) // last parameter ?
RunIteration();
else // iterate next parameter
Iterate(index + 1);
}
}

/// <summary>
/// Runs the optimizer on a given parameter set.
/// This is a brute-force optimizer. It runs back tests on every potential parameter combination.
/// </summary>
public override void Optimize()
{if (UserAbort)
return;
Iterate(0);
}
}
}

NinjaTrader_Dierk
01-20-2008, 09:51 AM
Unfortunately this is beyond of what we can support. You might consider contacting a certified NinjaScript consultant here: http://www.ninjatrader.com/webnew/partners_onlinetrading_NinjaScript.htm