PDA

View Full Version : New Optimizer Type: System Quality Number


Pete S
12-13-2007, 06:41 AM
Updated: please download SQN.cs (for NT version 6.5) from the Genetic Optimizer thread in this forum. I don't want to maintain the file in 2 places and it is required for that optimizer as well. Thanks.

This is a new optimizer type for comparing strategies in the Strategy Analyzer called System Quality Number. The formula is

SQN = sqrt(N) * average("Profit") / stddev("Profit")

where N is the number of trades, which encourages a large number of trades, a large average profit, and a small standard deviation. You can read more about Ragingbull's description of this number in the original thread that I coded the optimizer from here: http://www.ninjatrader-support.com/vb/showthread.php?t=4320

To install, take SQN6 if you are running 6.0, or SQN if you are running 6.5.

1. Copy this to My Documents/Ninja Trader 6[.5]/bin/Custom/Type
2. Recompile any of your indicators or strategies -- this will cause the optimizer type to be compiled as well
3. "my system quality number" will show up in your list of optimizer types
4. The SQN value shows up in the Performance column on the grid (see attached screenshot)

Keep in mind that as far as I know, this type of customization is not supported by NT, so if anything goes wrong, a reinstall may be your only recourse. Having said that, I have not had any issues thus far.

Feel free to post issues in this thread and I will try to help.

ryker
12-13-2007, 12:09 PM
Thanks very much for your work and to Raging Bull aswell.
You brought us a nice tool here!

dwt__
01-04-2008, 02:23 PM
You brought us a nice tool here!
AND, a window into just how other fitness functions could be created.

Thanks.

dwt

Ralph
08-03-2008, 10:27 AM
Hi,

I noticed the following 2 declaration in the SQN source file:

public class SQN : OptimizationType
{
public static double sLastSQN;
public static int sMinTrades = 0;

This 2 variables are declared static. If you should ever create more than one instance of this class, then these variables are shared across all class instances. I am not sure this is intended behaviour, especially for sLastSQN.

Regards
Ralph

Paul_J
08-03-2008, 11:30 PM
Hi,

I'm running NT 6.5 so I need SQN.cs. I did a search but I came up empty. Can someone post a link to that file?

Thanks,

Ralph
08-04-2008, 02:12 AM
Hi,

I'm running NT 6.5 so I need SQN.cs. I did a search but I came up empty. Can someone post a link to that file?

Thanks,

http://www.ninjatrader-support.com/vb/showthread.php?t=5932&highlight=system+quality+number&page=2

latkinso
08-12-2008, 10:08 AM
Hi

I have attempted to load the update to your optimizer and
receive this error message;

Type\SQN6.cs NinjaTRaderStrategy TradeCp;;ectopm" does not contain
a definition for 'performance" CS0117 Line 41 column 52

And same error message for line 42 column 33

Any Suggestions?

Thanks

Lynn

anachronist
08-27-2008, 03:51 PM
This is a new optimizer type for comparing strategies in the Strategy Analyzer called System Quality Number. The formula is

SQN = sqrt(N) * average("Profit") / stddev("Profit")

where N is the number of trades, which encourages a large number of trades, a large average profit, and a small standard deviation.
That's an interesting idea, but it penalizes you for having a few big profits in your sequence rather than steady profits. Some strategies simply aren't designed that way.

The system quality measure I'm more familiar with (via Van Tharp), described here (http://unicorn.us.com/trading/expectancy.html) can be reduced to

SQN = net_profit/average_loss

...where average_loss doesn't include "scratch" losses where you lose only commission and slippage. That formula also encourages maximizing both profit and quantity of trades, and minimizing losses.

Other trading platforms let you define your own custom optimization result. I'm still fairly new to NinjaTrader; doesn't NT let you do that too?

-Alex

lgarcia3
04-29-2009, 08:43 AM
I have a question on the code. When you are going through each trade, you call several methods in the Trade class:



tradeProf = (t.ProfitPoints * t.Quantity * t.Entry.Instrument.MasterInstrument.PointValue);



Is ProfitPoints the number of points made/lost in the trade?
Quantity? Is that the number of contracts/Stocks traded in that transaction?
How about PointValue? the value per point per contract in currency?

So, say I trade 1 Contract of S&P Emini, at $50/point, and make 5 points that would be:

tradeProf = 5 * 1 * 50 = 250

Is that what it is?

Thanks!

lgarcia3
05-03-2009, 07:28 PM
I was asking about the code before because this SQN number looked familiar. I don't know who this Van Tharp guy is and I have not read his books; but I think he is claiming something that was published back in 1908. At least if he is claiming this as his discovery; but, again, I have not read his books.

What he calls "SQN" number, is actually the Student t statistics. You can read about it here:

Wiki Student T (http://en.wikipedia.org/wiki/T-test)

I don't know, he may have been the first one to relate trading to statistics and that is why he is claiming it with that name (that is giving him the benefit of the doubt). I'm not a judge. But, definitely, it's not something "new".

I can say this, however, it is useful. I don't think it will "increase" the number of trades; at least not in my experience. It does optimize the number of trades though. And I can tell you also that a big "SQN" number is not necessarily good. In fact, a big "SQN" number may be a sign of over-fitting. So, be aware of that.

About the code, I would need to test some more; but I found it to increase rapidly after 2.5 or so and it would jump very fast. I am not sure why, I may be wrong. When I find it I will let you know.

magicboiz
10-07-2009, 06:22 AM
HI everybody

I've developed a futures strategy. After some optimization with the SQN, I get an SQN = 3.4 with 500 trades

¿3.4.....What does it mean? ¿Dollars? ¿Points? ¿Percent..?

¿Is it good or bad? ¿Is SQN a better indicator than sharpe ratio?

Regards

Anagoge
10-07-2009, 06:07 PM
¿3.4.....What does it mean? ¿Dollars? ¿Points? ¿Percent..?
¿Is it good or bad? ¿Is SQN a better indicator than sharpe ratio?

The SQN number isn't dollars, percent, or any other normal unit. It is just a unit-less measure of risk-adjusted performance (similar to the sharpe ratio). Higher numbers are better. If you want a more tangible number, look at something like cumulated profit, average trade %, etc. If you can get a 3.4 SQN with a few dozen actual or sim trades using realtime data (not historical data subject to curve fitting), then you are in very good shape. Whether the SQN is better than sharpe ratio is for you to decide based on your preferences for risk and return. In general, I slightly prefer it, since it doesn't penalize occasional very large winning periods the way the sharpe ratio does. My other favorite performance measure is a monthly Sortino Ratio, but it is not built-into NT.

pepelucho
11-25-2009, 11:04 PM
I'm getting an SQN of 6.9 with about 400 trades over 3 years, is that good ?