Module 2 Systematic Trading

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 40

Systematic Trading

Trading Based on Rules


Trading Systems
• Discretionary: entries and exits are determined by intuition; the
trader uses their own judgement to decide how to enter and exit a
trade.
• Non- Discretionary trades are those in which entries and exits are
determined mechanically by a computer.
• One possible approach is a bit of both
Advantages and Disadvantages of
Discretionary & Non-Discretionary System
Discretionary Non- Discretionary
• Easier to do start with and does not • Provides a mathematical edge as determined by testing
and designing
require such a deep understanding • It avoids emotions
• It requires continuous judgement. It • Risk Control
• Once created follow-ups require little work
is a path that is filled with excitement
• Difficult to create
and anxiety • Extrapolating from history may not be as effective
• EMOTIONAL PITFALLS hamper • Regime changes
performance • It requires periodic updates, which is a source of confusion
for the designer. Should you wait and give it a chance or
• Most who do not understand it will should you revamp the system
• Requires strong quantitative skill
not profit. One also needs heavy
• Needs to be logical and explainable
discipline. • Needs Clean data
Systematic trading and necessary decisions
• Stock Selection: Which stocks should I trade? Big Cap, small Cap, A-
categories only, sector specific (pharma), growth stocks/dividend
stocks or everything listed in the DSE/CSE.
• Position Sizing: What % of my portfolio will I commit to one position.
• Entries: When to Buy. What is the criteria for buying a stock
• Stops: When to get out of a losing position
• Exits: When to get out of a winning position
• Tactics: How to buy and sell
Four Main Categories of Technical Systems
• Trend Following
• Pattern Recognition
• Reversion to the Mean
• Exogenous Systems
Trend Following
• From our knowledge of trading systems, we know that markets trend
at times and trade in a range at other times. The most profitable
background is a trending background where the moves are larger and
generate fewer transaction costs.
• The system acts in the direction of the trend as soon as it can be
reliably detected. It will buy high and sell higher.
• Schwager believes that slower, longer trends are better because the
trends are larger, although less frequent, and the whipsaws are
minimal.
• Some add the ADX indicator to detect the emergence of a trend
Trend Following Sub Types
1. Moving Averages: It can consist of one or multiple moving averages.
Buy when the price moves over a moving average. Sell when prices
move below the moving average. In the multiple strategy one needs
to use at least two moving averages. A longer one is the slower of
the two that is used as a signal. The shorter one (faster of the two)
is the one that generates the signal. When the shorter one moves
above the longer one, we buy. When it moves below the longer
one, we sell.
2. Breakout system. We construct bands and channels using a criteria.
Once it breaks out upwards, we buy. Then we must also set a stop
and exit.
Simplified Break Out Strategy
Example of a Simple System
Single Moving Average Conditions
• Trade Big Caps: ( Because they are heavily covered by brokerage firms, they are more
likely to reflect the current state of the company and the information surrounding the
business, there is foreign participation making it more likely that the stock will be
efficiently priced) – lets trade SQUAREPHARMA: MKTCAP 19,700 Crores
• Position Sizing: 15 to 20 %. See risk management module to see some of the logic
behind position sizing selection. Here I have a constant size of 100,000 BDT per trade.
• Entry Buy when the price CLOSES above the 20 - day simple moving average line.
• Sell when the price CLOSES below the 20-day simple moving average line.
• Exit: The exit is the selling condition here. My exit condition is the same for stops. If
the price closes below the 20 SMA line I will sell.
• Tactics: Buy and Sell when prices move above/below the 20-day simple moving
average line.
Single Moving Average Trading
Moving Average System Performance Summary
(Please find in excel Moving Average Example Tab)
System Performance Summary

Entry Entry with Commission @ 0 .25% Exit Exit with Commission @ 0 .25% Profit % After Commission Trading Size Trading Profit/Loss Cumulative Profit
Trade 1 192.30 192.78 227.50 226.93 17.71% 100,000 17,714.68 17,714.68
Trade 2 202.80 203.31 210.30 209.77 3.18% 100,000 3,181.03 20,895.71
Trade 3 211.90 212.43 212.60 212.07 -0.17% 100,000 (170.06) 20,725.65
Trade 4 213.50 214.03 213.10 212.57 -0.69% 100,000 (685.17) 20,040.48
Trade 5 215.50 216.04 226.60 226.03 4.63% 100,000 4,626.37 24,666.85
Trade 6 229.10 229.67 240.20 239.60 4.32% 100,000 4,322.13 28,988.98
Total Profit Generated 100,000 28,988.98

Condtions
SQUAREPHARMA (Big Cap)
Trading Script
Constant Position Size: All trades will be BDT 100,000
Position Size
Buy when the price closes above the 20 day SMA (Simple Moving Average)
Entry
Sell when the price closes below the 20 day SMA (Simple Moving Average)
Exit
Not applicable here
Stops
Buy/Sell when the price closes above/below the 20 day SMA
Tactics

1 Year Return (Approx) 28.99%


Common Pitfalls of a Trend Following System
• They suffer from higher slippage cost. In the e.g., we assumed that all the trades (entry and exit) were made at
market on close, the closing price. Suppose you did not get it. Instead of making the first trade at 192.30 we could
not buy at the closing price and instead had to buy the following day at the opening price of 193.00. It would eat
at our profits. In this e.g., the effect is small. But suppose we had to buy 2.5% higher the following day. These small
changes would eat at our long-term performance.
• Whipsaws are common: Trades 3 and 4 are entering and exiting very close to each other. We are incurring trading
costs and possibly slippage too. These two trades are net losses after commissions. If these kind of trades become
too common, then it will affect performance. To protect oneself from whipsaws one can, add additional criteria. I
will buy once closing price keeps above the moving average for two consecutive days. It would avoid some of the
whipsaws, but it could also mean a missed opportunity if the stock rallies hard after the entry signal is satisfied.
• The largest problem is the small number of consecutive losses that produce significant drawdowns. If the stock is
in a trading range this will be common. It also has the characteristics of making huge profits when it can catch on
to a move. Small frequent losses and large rare profits are a characteristic of this system. Most people find it
difficult to keep patience with this system.
• ** Note the example shown here is taken from a period when the market rallied hard. There will be cases where
this system might be quite unprofitable. Test out a system with a long-time frame across multiple cycles, trading
range, upswing and downswing.
Pattern Recognition
• They require some interpretation
• They are difficult in the sense that selecting the criteria is not as
straightforward.
• Some system traders use short term patterns and limit their exposure
with specific position stops and price or time targets.
• Generally, such systems are partially discretionary because they
require some interpretation during the trade entry.
Pattern Recognition: Double Bottoms
Issues with Pattern Recognition
• Entry: I enter after a double bottom has formed. How do I define a double bottom though.
Should it be when the lows are exactly the same 8.00 and 8.00. If the first low is 8.00 and the
second one is 7.70 where the price closed at 7.90 would I consider it a double bottom or would I
view it as a stock who has broken previous support of 8.00. Is the third one 15.50 and 15.70 a
double bottom?
• Exit: I will sell once the stock rallies 15% (Arbitrary condition: because going over 100 double
bottom patterns seem to indicate that they usually tend to rise 15%). Another condition could
be time based. I will sell when the stock has rallied 15% or after 2 weeks of buying. Historically if
most stocks tend to rally within the first two weeks it could have statistical merit. If it does not,
they tend to breakdown. Or in a bullish market I might consider putting my money to better use.
These are some of the considerations one must make. They all require judgement (Discretion).
• Stop: In case the stock does not rally I will sell it when prices close below the low price of the
double bottom. ( the pattern requires two lows that are near each other, so I will select the
lower of the two for my stop).
Mean Reversion
• Reversion to the mean are based on the buy low and sell high philosophy within
a trading range.
• They require a certain amount of volatility within the peaks and valley of ranges;
otherwise, transaction costs, missing limits and being stopped out of false
moves chew up potential profits. Generally, these systems are discretionary.
• They make use of oscillators such as stochastic, RSI, MACD etc.
• Stops are necessary
• Generally, they do not perform well
• Buying or selling within Bollinger bands are another approach, but some studies
have shown that it is better to buy on the breakout instead of trading within
them.
Mean Reversion Example within a Bollinger
Band
The problem Highlighted
• The issue becomes apparent when we look at the purple arrow.
• Suppose we buy at the close price of 354.50
• We cannot sell but the next candle is a big bearish one.
• We decide to sell as soon as we can. We sell on the 2nd day after entry.
Suppose we were waiting for a good price, hoping for a rebound and
did not exhibit discipline. We finally decide to sell at the closing price
of 340.60.
• After commission we make a loss of 4.42%
Mean Reversion with Bollinger Bang E.g. 2
Problems Faced
• Bullish graph that offers only two trades. The first was profitable the
second one does not seem that promising
• That is another issue. It will not usually provide too many signals.
Whenever it does it offers it when the stock is moving down. It is
against basic technical theory; you do not trade with the trend.
• Should only be considered when one is comfortable with their skill
and discipline.
Mean Reversion Problem 3
Mean Reversion Problem 3
• Suppose I wait for a trading range to form.
• Finally, after an adequate time has passed, I finally decide that I have enough
evidence where they price seems to trade within a range.
• In this e.g., the range is 13.08%.
• I need to set a criteria for entry.
• Suppose the low is 31.70. Because I may not exactly get it at that price, I decide I
will buy when stock closes below 32.00 and sell as it nears the top of it’s trading
range of 35.80 (suppose I decide to exit whenever it closes above 35.00).
• Unfortunately, prices fall, and I must incur a loss. These can be very common.
Again, if I had set a stop, I will sell as soon as the stock closes below 31.70, I
would cut my losses significantly.
Exogenous Signal Systems
• Some signals are generated from outside the market being traded.
• Interest rates are a good e.g.
• One follows those external signals and then decides to buy and sell
according to some set criteria.
• Of course, it could also act as an additional filter to any other system.
Which System is the best?
• John R Hill and George Pruitt, who test all manner of trading systems
https://futurestruth.com/ maintain that the best and most reliable
systems are trend-following systems.
• Within the trend following systems, the breakout systems have the
best characteristics- specifically the Bollinger Band Break out system
(not the one we used in the e.g.) and the Don-chain or channel,
break out systems.
• You can check these out. Remember to understand the way they are
traded. We do not have short selling and it could be a huge part of
their system.
Testing a system and their problems
• Testing a hypothetical system is necessary and it often will be tedious
because so many will turn out to be unsuccessful.
• It is very time consuming and difficult to do.
• First you will need clean and accurate data. This can be a demanding
aspect.
• Make sure to test out of sample so as the design and criteria of the
system is not curve fitted.
• We need to create a robust system.
Creating a system (Rough Outline)
1. Selecting the data source and cleaning it
2. Testing Trading Method: Criteria Selection
3. Testing the Parameter set
4. Optimization
5. Testing out of sample data
1. Data Selection
• The data must be impeccable. Without correct data: garbage in and
garbage out.
• Data source should be the same as what will be used when the
system is running in real time.
• As a rule of thumb, the data should be long enough to provide at-least
30 to 50 trades (entry and exits). The more the better.
• The data should cover multiple period where the market travelled up,
down and sideways. This ensures that the test has enough history
behind it and enough exposure to different market circumstances.
• Should I use adjusted or unadjusted. Adjusted is the way to go here.
2. Testing Trading Methods
• Design the system
• Create the criteria for entry, exits and stops.
• Entry is when should I buy the stock. Should I use closing prices or
something else.
• Exits are when the stock is profitable. When should I sell a stock when
it is profiting?
• Stop is when the stock is at a loss after entry. This is incredibly
important to control the risk of losses. Make sure you follow this
religiously.
3. Testing Parameter Set
• The initial test of a system is run to see if the system has any value.
• The parameter selected initially should be tested to see if they fall in a
range or if they create very different results if a slight change is made
to the parameters. Suppose I use a moving average system but if I
change it from 20 days to 22 days the results change massively. It
might not be stable. From a profitable system it becomes a losing
system.
• When the results tend to remain the same or similar, the parameter
set is said to be stable.
4. Optimization
• Once you get a parameter set that seems to be stable you move onto
this step.
• Optimization is simply changing the parameters of a system to
achieve the best results. Suppose we found out that the moving
average system is profitable if we use anywhere between 20- 30-day
SMA. Now Optimization is when we see that 26 works best.
• The biggest problem with this step is curve-fitting. We keep changing
the criteria’s until we find something that works well. It can occur
randomly. We are just fitting the criteria on the past data until we find
something that works.
5. Out of Sample Test
• When we collect the data, we set aside a part of the data that will be used out of
sample ( the one that we will use for steps 2-4 is called the in-sample data)
• Once we design a system, we test it first with the in-sample data. We check if the
parameter set is stable. We optimize the trading method. But we know that curve
fitting might be an issue.
• Therefore, after the trading method works well with the in-sample data, we then
test it with the out of sample data.
• If the trading method works with the out of sample as well, we can move onto
trading with actual money.
• Generally, when we slice the data (70-80% is used as in sample testing) & (20-30%
is used as out of sample).
• The in sample and out of sample have different ways of dissection.
Performance Evaluation of a Trading System
• When analyzing the system, we look at the system components.
• We look at the profit, the risk and the smoothness of the equity curve.
• We want to know how robust the results are. Robustness simply means
how strong and healthy our results are; it refers to how well our results
will hold up to changing market conditions.
• This is important. We do not know what the future holds. It may not
reflect past markets hence we need to take as much measure as we can
here.
• No system will be fully robust. But we can try to make it as much as
possible.
Performance Evaluation
• Once we create a system and start trading it, we must monitor how well the
system is working.
• We need to evaluate how the system is working
• This performance evaluation is performed not only when trading but also
when using in/out of sample data during the construction of the system.
• They are very important methods to understanding the characteristics of the
system.
• Please check the system trading excel sheet to see how we evaluate the
performance of an arbitrary system. Please find it in the systematic trading
excel file under the tabs Arbitrary Performance, Profit Measure & Risk
Measures
# Trade Entry with Commission Exit/ Stop with Commission % Profit
1 100 102 2.00%
2 92 107 16.30%
3 103 95 -7.77%
4 100 103 3.00%
5 105 107 1.90%
6 110 105 -4.55%
7 101 97 -3.96%
8 92 96 4.35%

E.g., of
9 91 85 -6.59%
10 88 92 4.55%
11 87 90 3.45%

Performance
12 92 97 5.43%
13 100 120 20.00%
14 125 117 -6.40%

Evaluation
15 120 126 5.00%
16 131 137 4.58%
17 140 132 -5.71%

(arbitrary
18 137 129 -5.84%
19 125 118 -5.60%
20 121 126 4.13%

trading results) 21
22
23
120
130
136
127
133
142
5.83%
2.31%
4.41%
24 142 136 -4.23%
25 139 145 4.32%
26 150 165 10.00%
27 161 170 5.59%
28 165 158 -4.24%
29 155 149 -3.87%
30 143 146 2.10%
Profit Measure
1. Gross Profit / Gross Loss: Gross Profit is the total profit from only profitable trades. Gross
Loss is the total loss from only losing trades.
2. Net Profit: Gross Profit – Gross Loss
3. Profit Factor (Total Profit/Total Loss): To be profitable it must be above 1. Anything above 10
is dangerous and points to curve-fitting.
4. Number of Trades: 30 (# the number of trades from the system)
5. Percent profitable: The number of winning trades / number of losing trades. In this
hypothetical system it comes to 63%.
6. Average Net Profit: Net profit / # of trades. Should be the same as the average profit/ loss of
all trades.
7. The Largest Winner / Gross Profits: This is a ratio between the biggest winning trade and the
total profits from all profitable trades. Suppose it is 75%. This means of all the profit that the
system made, 75% came from one trade. Now it could have been random and might not
repeat again. The lower the number the better the trading system. Essentially a lower one
would indicate that it does not rely solely on one big trade but on many trades.
Risk Measures

• Maximum consecutive losing trades is important because a long


string of consecutive losses invariably causes a large drawdown and,
thus, a high potential risk for the system. In this case, the number of
successive losses is four trades in a row. It suggests that two whipsaws
took place during the test period. Whipsaws can be controlled with
stops.
• Sharpe ratio, the ratio of excess return (portfolio return minus the T-
bill rate of return) divided by the standard deviation of the excess
return. The excess rate of return has severe problems when applied to
trading systems.
Maximum Drawdown
• A maximum drawdown (MDD) is the maximum observed loss from a
peak to a trough of a portfolio, before a new peak is attained. Maximum
drawdown is an indicator of downside risk over a specified time period.
• Max Drawdown = (Trough Value – Peak Value)/(Peak Value)
• Maximum drawdown is a specific measure of drawdown that looks for
the greatest movement from a high point to a low point, before a new
peak is achieved. However, it's important to note that it only measures
the size of the largest loss, without taking into consideration the
frequency of large losses. Because it measures only the largest
drawdown, MDD does not indicate how long it took an investor to
recover from the loss, or if the investment even recovered at all.
Maximum Drawdown
Conclusion
• In this module, we turned our attention to mechanizing these reactions. A model is simply a plan or set of rules
of when to buy and sell securities. A system uses the model as its base and lets us determine a priori how we
will react to particular market situations.
• Having a system in place helps us follow a well-thought-out plan and prevents us from haphazardly trading
based on emotion.
• Of course, our basic objective in creating a system is to make a profit. Although this sounds like a
straightforward goal, the goal of making a profit is not as simplistic as it sounds. Of course, we test our system
to see how well it performs. But—and this is an important but—just because a system performs well using
past, historical data in a trial situation does not guarantee that we will have the same stellar results in future,
real-time trading.
• The most basic reason for this performance differential is that the market never repeats itself exactly; the
system is operating in a different market environment than the one in which it was tested. There are also some
system design and testing issues of concern.
• The system designer must be careful about data choice and not to overfit the data in the sample period. As we
have seen in this chapter, even a system that has a high net profit in a test period is not necessarily a system
that will perform well in the future. The system designer must consider a host of statistics about the system
performance to determine whether the system is suitable for future trading.

You might also like