You are on page 1of 38

Designing a trading

system and testing for

statistical robustness
Who am I ?

 Subhadip Nandy – Independent quantitative trader since 2013

 Net experience in the markets of 18 years
 Was the Research Head of one of the biggest commodity prop
firms in India
 Successfully designed algos on MCX and MCX-SX
 Trading approach is 100% system oriented
 I train on trading systems on the F&O space
What is a trading system ?

 A trading system is a group of specific parameters that combine to create

buy and sell signals for a given security. Trading systems can be developed
using many different technologies, including Microsoft Excel, MATLAB®,
TradeStation, R, Python, Metastock, Amibroker and other platforms and
languages. The buy and sell signals from these platforms may appear in a
file for you to execute or be programmatically executed using a
brokerage that supports automated trading.
What are the advantages of a trading
system ?

 Removes cognitive biases.

 Removes emotion from trading
 Saves time
 You can outsource some of the work
 Backtesting can be done across market condition
 Statistical stress testing can be done to check whether the system is robust
or a function of blind luck
What are the dis-advantages of a
trading system ?

 Requires unique skillsets

 Requires TA or quantitative knowledge
 Requires programming language expertise
 Can be difficult to optimize
 Requires large initial cost in terms of time and money
Creating a trading system

 Now that we are aware what a trading system is along with it’s pros and cons,
we can get down to the core business of creating a trading system.
 1. Define a trend
 2. Define a breakout
 3. Combine the two and create a specific price for entry
 4. Set a logical stoploss point which defends us in case the trade does not go
the way we want but leaves enough space for the market to move and then
go in the direction of our trend
 5. If we take the entry, then what should be our position size depending on our
 6. Where to exit
What is a trend?
Basic assumption

If prices are in a trend, then a pullback

to the main trend is temporary and
sooner or later prices go back in the
direction of the major trend
Basic system guidelines

This system thus should have three main components :

 • A trend detector
 • A pullback detector
 • An entry method through a price breakout which confirms the
continuation of the trend
Trend Detector

 While devising or using a trend detector, one should be aware that any method to
determine trend is always a lagging indicator . To keep things simple without using
esoteric mathematics, we use the simplest of all trend detectors, i.e a simple moving
average. Using the rule that “indicator length should be half the cycle length”, we
assume the basic cycle of a futures start to expiry time of 22 days ( 22 days are there
per month for trading on an average). Taking slightly higher than half, we use a 13
period simple moving average(SMA).
 Whenever prices are above the 13SMA, we consider the trend to be bullish and
whenever prices are below the 13SMA, we consider the trend to be bearish.
 There is no magic involved in the number 13 as you will see for yourself that any other
moving average works just as well in this system.
Pullback Detector

 A pullback is defined as when prices go against the trend, i.e, prices fall in a rising trend
and vice versa
 • A basic/simplest pullback could be defined as when Today’s Close < Yesterday’s
Close in an uptrend and vice versa
 • How far prices will pullback against the major trend is impossible to predict with
 So whenever we get a lower close compared to the previous day and prices are above
the 13SMA, we consider that to be a pullback in a bullish move. Exactly the opposite
holds for a bearish move
Price Breakout

 A price breakout can be defined as a price move in the direction of the major trend
which is large enough to imply that movement has resumed in the direction of the
underlying trend
 We take 55% of yesterday’s range, and if prices move in the direction of the major trend
by that amount since opening, we expect prices to move in that direction throughout
the day ( the number of 55% is statistically derived)
 Yesterdays Range = Yesterday’s high – yesterday’s low

What we are trying to do through the combination of these rules is to catch a ‘trending
day’ which runs in the direction of the main trend
Trend Day

A “ trend day” occurs when there is an expansion in the daily trading range and the open
and close are near opposite extremes. The first half-hour of trading often comprises less
than 10%-15% of the day’s total range; there is usually very little intraday price
retracement. Typically, price action picks up momentum going into the last hour — and
the trend accelerates. A trend day can occur in either the same or the opposite direction
to the prevailing trend on daily charts. The critical point is that the increased spread
between the high and low of the daily range offers a trading opportunity from which large
profits can be made in a short time. We are only interested in trend days in the direction of
the major trend which would increase the probabilities of our success

A trend day generally continues it’s movement in the direction of the trend for the 2 nd day
The system so far - BUYs

 The system so far – Buys

 • Prices need to be above 13SMA
 • Today’s close < Yesterday’s Close
 • Range =Today’s high – Today’s low
 • Breakout Filter = 55% of Range
 • Entry price = Tomorrow’s Open + Breakout Filter
The system so far - SELLs

 Prices need to be below 13SMA

 • Today’s close > Yesterday’s Close
 • Range = Range =Today’s high – Today’s low
 • Breakout Filter = 55% of Range
 • Entry price = Tomorrow’s Open - Breakout Filter

 In some cases the trend will not continue and reverse, hence a stop is required
 • Using the same logic of the breakout filter being statistically significant, if prices move
in the opposite direction by that same amount after entry, we are out with a stop
 • That means the OPENING price becomes our stoploss

 As we are expecting the trend to continue throughout the next day, we exit at the
close of the 2nd day. This serves three purposes:
 1. We let the trend continue to it’s maximum.
 2. We always trade thru ATM options, so no risk of unlimited loss ( extremely important
for position sizing)
 3. Minimum amount required to trade directional naked options thus improving return
on equity ( no futures margins required)

 ** Experienced option traders can use strategies given the IVs, greeks and time to
System conditions summarized

 For Buys : If prices are above the 13SMA and today’s close is lower than yesterday’s
close, then if prices move up 55% of today’s range from tomorrow’s opening price, we
buy with a stoploss set at the opening price
 For Sells : If prices are below the 13SMA and today’s close is higher than yesterday’s
close, then if prices fall by 55% of today’s range from tomorrow’s opening price, we sell
with a stoploss set at the opening price
The Trend Breakout System by Subhadip
Nandy ( codes for Metastock)

 1. Open the expert advisor icon in Metastock and click “New”

 2. Name it “Trend Breakout System ver 1.0 “
 3. Click “Symbols”, then click “New”, Name is “Buys”
 4. Input this formula – (Ref(C,-1)>Ref(Mov(C,13,S),-1)){ previous close great er t han 13SMA} AND
((Ref(C,-1)<Ref(C,-2))) {t he close of yest erday is less t han t he close of t he day before} AND (H> O+ ((
Ref(H,-1)-Ref(L,-1))*.55))) {t oday’s high is great er t han t oday’s opening plus 55% of yest erday’s range}
 5. Under Graphics, choose the UP ARROW symbol, colour BLUE, click OK to save
 6. Now create the SELL signal with a red down arrow, code will be – (Ref(C,-1)<Ref(Mov(C,13,S),-1))
{Close less t han 13SMA} AND ((Ref(C,-1)>Ref(C,-2))) { previous close great er t han t he close of day
before} AND (L< O- (( Ref(H,-1)-Ref(L,-1))*.55))) { low of t oday less t han t oday’s open minus 55% of
yest erday’s range}
 {} cont ains t he comment s, Met astock will ignore what ever is writ ten wit hin t hese parent hesis
Now if you select the ‘Trend Breakout ver 1.0’
and attach it to a chart, it will look like this :
Fixed Risk Position Sizing

 Let us assume that the trader is ready to risk x amount per trade
 His system provides a precise stoploss ( R) ( this is terribly important as no
money management is possible without a clearly defined stoploss point)
 Hence, his position size per trade will be x/R 4. Let us explain this simple
concept with an example. Say a trader trading Nifty futures as per the Trend
Breakout System is willing to risk Rs.20,000 per trade
 Situation 1 : SL is 100 points . Hence the quantity the trader will trade is x/R =
20000/100 = 200 Nifty fut
 Situation 2 : SL is 50 points Hence the quantity the trader will trade is x/R =
20000/50 = 400 Nifty fut
 Situation 2 : SL is 20 points Hence the quantity the trader will trade is x/R =
20000/20 = 1000 Nifty fut
Position Sizing conditions

 Now in order to backtest our system, let

us make the following assumptions :
 We use a net capital of 5 lacs.
 We use a risk of 2% of capital per trade
 3. Our risk per trade will be Rs.10,000/-
 Depending on this fixed risk, we take
Backtesting performance 2018
Equity Curve 2018
PnL distribution per trade
Stress test
Stress Testing explained

Let us consider the year of 2018. The number of profitable trades in the initial backtest
was 20. We consider a standard error ( simply root of 20) which comes to 4.47 and it’s
rounded off to 4. We now assume that in real life trading, the number of profitable
trades will be 4 less than that shown in the backtest. So in real life trading, we assume
that the number of profitable trades will be 20-4 = 16. Then we multiply the average
profit per trade with this new number of profitable trades to get the “Curr(ent) Win”
figure which is obviously much reduced than the original profits.
We do the same standard error calculation for the losing trades thus increasing the
number of losing trades from 15 to 19 and increase the total loss amount.

This is what you can realistically expect and this figure remaining positive even
after taking adverse trades into account proves the robustness of the system.
This result is known as Pessimistic returns. If a system shows a loss after this test,
then probability is high that the system will not perform well in real trading.
Parameters to test the system
Parameters in detail - I

 Win ratio : (Total wins/total trades) . The probability of wins, total wins
divided by total number of trades.
 Payoff Ratio : (Average profit per profitable trade / Average loss per losing
trade ) The return expected per rupee of risk, must be greater than 1.
 Trade Expectancy : (win ratio * avg win)/(loss ratio*avg loss) This must be
positive for the system to be ultimately profitable
 Top 10% winnings : Total amount earned in the highest 10% of winning
 Top 10% losses : Total amount lost in the biggest 10% losing trades
Parameters in detail - II

 Net – Top 10% wins : This figure must be positive, i.e, whether the system is
still profitable after deducting the top 10% winnings
 Returns minus positive outliers : Returns calculated after deducting the top
 Tops wins minus top losses : Best 10% wins minus best 10% losses. This figure
must be sufficiently positive
 Ratio of top wins to top losses : This ratio must be greater than 1. Anything
greater than 2 is great, the more the merrier
 Net minus all outliers : Returns calculated after removing the top 10% of
wins and losses. In terms of a bell curve, removing the outliers both sides
Parameters in detail - III

 Returns % minus all outliers : the net returns after outliers removed on both sides
 Profit factor : (gross profit / gross loss) The profit factor is defined as the gross profit divided
by the gross loss (including commissions) for the entire trading period. This performance
metric relates the amount of profit per unit of risk, with values greater than one indicating
a profitable system. We all know that not every trade will be a winner and that we will
have to sustain losses. The profit factor metric helps traders analyze the degree to which
wins are greater than losses.
 Max drawdown amount : A drawdown is measured from the time a retrenchment begins
to when a new high is reached. This method is used because a valley can't be measured
until a new high occurs. Once the new high is reached, the percentage change from the
old high to the smallest trough is recorded. Drawdowns help determine an investment's
financial risk. Both the Calmar and Sterling ratios use this metric to compare a security's
possible reward to its risk
Parameters in detail - IV

 Max drawdown percentage : Drawdown expected as percentage

 Luck factor : (% of highest winning trade / % of average winning trade). This
explains how much a single trade contributes ( is lucky) to the
performance of the system. We are looking for a low figure on this one. A
system with a luck factor of 6 or 7 means that 6-7 times the average profit
came via a single trade. Hence, in real trading we might not come across
such a trade
 Recovery factor : ( total net profit / absolute drawdown) This figure must be
greater than 2, a lower figure would suggest that the system is not robust
enough to cover the drawdown
 Pessimistic returns : Standard error adjusted returns
Anatomy of a trade – 11th March

 On 8th March, the closing is above the 13SMA and the close is lower than
the close of the day before
 8th March High = 11084 , Low = 11033, Range = 11084-11033= 51
 55% of 51 = 28 points
Anatomy of a trade – 11th March

 On 11th March, Nifty fut opens at 11074

 Buy > 11074+28 = 11102
 SL = 11073
 Position = 10,000/28 = 357 ( roundoff to 375 or 5 lots of Nifty fut)
 ATM options is 11100
 If trading options, we buy 750 ( 10 lots of 11100 CE )
 Exit on 12th March at 11336
 Profits in points = 11336 – 11102 = 234
 Profits in amount = 234 * 375 = Rs. 87,750 /-
Real-time chart – 11 &12 March
Use of options – The naked call/put

 Stops max loss

 We always buy ATM call/put, so effect is roughly 50% of futures move
 Options eliminate black swan risk
 A naked call-put buy is the simplest trade possible
 Position sizing dependent on risk profile
 Average price of naked ATM option is 120 on average
 Max loss can be 100 points on the option
 Trade in options, not futures
Thank You

Twitter : @SubhadipNandy
Email :
Mobile : 97480 52739