Sunday, April 7, 2019

The Science of Trading


A lot of people ask me about the scope of "The Science of Trading", here's my simple version, still work in progress, enjoy!


Sunday, October 20, 2013

Goal / Target Setting and Performance Measurement for Futures Trading


What is the reasonable goal or target of expected return we need to set for ourselves to make taking the higher risk in futures trading worthwhile ?  Everyone has got their own numbers.  How do we grade ourselves?  Everyone has their own way as well.  I'm going to share a quick and dirty way here.

First, we use the leverage in the product that we are trading to set the goal or target of expected return.  Let's take FCPO for example:

The settlement on Friday for most active month (Jan14) was 2401.  Contract multiplier is 25 and the margin (both initial and maintenance) at the moment is RM4500. 

Leverage = actual contract size / initial margin
                = (2401 x 25) / 4500
                = 13.34
Let's round  it to 13.

If we take risk-free rate here as our BNM's OPR at 3% now, then the expected return (goal / target) we should be looking at for taking the risk to speculate in FCPO should be 13 x 3% which is 39% per annum!  Of course that is the ideal target or 100 marks equivalent in our exams.  In actual trading we won't be putting up just the exact initial margin but maybe 2 to 3 times more per contract.  If your trading rules is to put up 2 x the required margin then your expected return would be lower down by half to 19.5% per annum as the leverage is lower by half.  Putting 3x margin would lower down your target to 13% return per annum.  Of course with position sizing algorithm, your return should be higher.  The example shown here is pure basic 1 contract. 

As you can see if your system needs RM30,000 to trade a contract, your expected return becomes 6% which may not be that attractive anymore.  This will be a quick guide for you to search or develop a trading system that gives you a favourable reward to risk ratio.

How do we measure our own performance?  Quick and dirty way would be the same way we grade in exams.  If 50 points is the equivalent of making 3% (risk-free rate) or just pass then we need 80 points and above to get A.  If we use 2x margin per contract, you would need a return of (0.6 x (19.5-3) + 3) = 12.9% and above per annum to get an A!  Of course statistics shown that most traders would get an F which is losing money!  Trading would be one of the most challenging subjects in life to get an A year after year, let alone trying to be an outstanding student which is to beat the target every year.

That's my quick and dirty way to set the target and do self performance measurement in futures trading.  Cheers & Happy Trading!

Sunday, October 6, 2013

Blind Faith or Calculated Risk? How Many Consecutive Losses to Expect?


A lot of system traders when develop or looking for a trading system would only want a high win rate or high percentage of winning trades (other than high return) thinking that that is the most important thing and will minimise their losses or drawdowns when trading it.  I am here to tell you not necessary!

Having a high win rate doesn't mean you will never suffer many consecutive losses (which I'll talk about here) or even the trading system will make money in the long term (I'll explain more maybe in future article)! 

But how do I know how many consecutive losses to expect?   I'll show you a quick Excel spreadsheet that I hope would help some traders understand trading edge better.  The example below shows a system with 70% win rate in a 10,000 permutation simulation with their respective numbers and percentage of consecutive win and loss trades.  How many consecutive losses is the maximum in this sample of simulation? 9!!!  Multiply that with your average size of losing trade and you'll roughly get the idea of how much minimum starting capital needed in the trading system (plus margin for the number of lots you are trading if you don't want margin call or intraday force liquidation of your positions). 

How do you know if you'll start with consecutive winnings first or consecutive losses first?  Now who tells you luck is not important in system trading?  Lets say you have bad luck, imagine 6 months to go through max consecutive losses when you start then another 6 months trying to climb back to breakeven, that is 1 full year of pain, I can't blame you from giving up on system trading.

Even a system with 70% win rate you may suffer 9 losses in a row!  What if during actual trading, the win rate drops to 60%? Will your ratio of average win/average loss big enough to still have positive edge? Or the system will go into losses or stop working which is what usually happened as the win rate that we get is usually fully optimised, a drop in win rate when trading live is almost for sure!  What about usual trend-follow system with 30-40% win rate?  Can you still take the next trade after suffer 8th consecutive losses?  Will telling yourself "fear is not real" help??? Talk is always easy.

Here's the sample screen:


Cheers & Happy Trading!

P.S.:  How many max consecutive losses for a system that is 50%?  Ever wonder why it is more common than what we expect to see 15 consecutive "big" or "small" in Genting or any Casino?  That is why doubling down after losses will never work in the long run.  Money management will not help if your edge or average trade is negative!

Wednesday, December 29, 2010

Programming Chart Pattern in Excel - Part 3

                             
Here's the updated screen shot that anonymous requested.  The first one shows the short in 2008 and the second one shows the long in around mid this year. 

Please also take note that this is consider cherry pick and I am in no way promoting these trading rules.  Run the back-test and optimize the parameters on your own before even consider trading it.





Cheers & Happy trading!
                                     

Programming Chart Pattern in Excel - Part 2

                                                  
As expected, Excel realised the "strangeness" in the output on my previous post.  I realised the ambiguity in the rules given when I did the programming to let beginners know that when writing your algo, you can't assume that the programmer can use common sense to fill in the blanks left by the rules, it has to be clear and precise otherwise it will be GIGO (garbage in, garbage out).

To make some sense out of the rules given, here's my interpretation of the blanks being left out (in addition to the updates given by Excel that I've missed as it went into SPAM's tab) and the output from the updated version.

1.  The z bar lower close compare to z-1 happen while market is in uptrend (y continuous higher highs AND x continuous lower lows).
2.  Market is considered to be in uptrend until they are in down trend (b continuous lower highs AND a continuous  lower lows) and vice versa.
3.  Buy-stop order instead of buy (that's is just my mistake on typing the order type, I assume that you know it is a buy-stop order when the buy price is much higher, I am sorry, thanks for the correction, Excel)
4.  You could define different parameters for up trend and down trend, although you have to be careful on the long or short bias in your system when you use different values, usually it is consider bad if one side is easier to be fulfilled than the other.  You would have trouble when there is a regime or paradigm shift.  I hope you understand what I mean :).

Here's the updated screen (done in <10 min):


Oh yes, one more thing Excel, I am sorry that I am lazy to do the charts since the numbers already speaks to me :) and personally I think this could be further improved to be a good trend-following system. 

Cheers & Happy Trading!
                      

Tuesday, December 28, 2010

Programming Chart Pattern in Excel - Part 1

                                             
In response to Excel's comment on my previous blog, here's the screen capture (graphical requested by Excel) of the rules (programmed in MS Excel using only in-cell formulas) given by Excel on the comment section on my previous post.

This is the ouput from  < 30 minutes of programming.  I am sure it can be further improved.


All the parameters in red color can be changed and calculations will be updated automatically!

Just do the reverse for Sell and plug-in your modules for back-testing and you are set to begin optimizations(since you already have the Buy/Long, Stop-loss and Profit target price)!

Cheers & Happy Trading !
                                   

Friday, July 23, 2010

Verifying Historical Volatility Calculation

              
This article was written for you, Bryan.

Since you brought up the question of whether volatility is an arbitrary value in your comment on my previous article, I've been curious to find out if I am still half as good as I was a few years back :) .  Since most of the files I did last time were lost, I spent many hours trying to find and finally managed to dig out an annualized 30 day historical volatility of KLCI from 2001-2006 that I've downloaded from Bloomberg (industry standard other than Reuters) last time.

The first thing I did was to plug-in the KLCI index value into the Excel that I've created to calculate the volatility of FCPO and put Bloomberg's data side by side to compare.  Then I tried to find the period that has been used by Bloomberg to calculate the annualized 30 day historical volatility. 

After a few trial and error, I managed to get the same exact value of KLCI's annualized 30 day historical volatility value with Bloomberg.  Bloomberg uses 260 days instead of 252 trading days in a year.

As usual, the screen capture is as below:




Cheers & Happy trading!
                                          

Tuesday, July 20, 2010

FCPO Volatility Measurement

         
Since I've heard a lot of people talking about how hard it is to trade our FCPO these days because of the high volatility, I've decided to do some facts checking of my own.  To have our own view in the ocean of opinions surrounding us every day that could influence and cloud our judgment is the first step towards becoming a good systems developer.

Since every subjective statement is relative, I've written a simple Excel spreadsheet to measure and compare FCPO's volatility since end of 2006 until first week of July 2010 and see if it is true that recent volatility is higher than average between this period.

Since most of the trend-following systems are using daily data, I've decided to use the daily closing price (unadjusted though) to measure the annualized monthly volatility.  I don't wish to go into the detail definition of volatility measurement as you can easily google and read them.  Okay, okay, I know you are lazy, here's a quick definition I copied from Wikipedia : Volatility refers to the standard deviation of the continuously compounded returns of a financial instrument within a specific time horizon.

As usual, a picture is worth more than a thousand words...

As usual, surprise!  FCPO's volatility recently is the lowest in about 4 years that I've measured!
              
If you believe that low volatility means that market tends to be in cycles more than trend, then naturally a trend-following system would be going through the usual drawdown, how bad the drawdown is just a function of balance between risk and reward that you choose. 

As usual, too aggressive and you'll have higher probability of reaching maximum drawdown that you are able to stomach, too conservative and the return may not justify trading in futures market.  Again as usual, there is no one size fit all solution because everyone is different!  That is why trading is always challenging and interesting!   Cheers & Happy trading!

                                    

Tuesday, June 15, 2010

Evaluating Trading Returns

                                         
Too often when beginners are evaluating and comparing systems' performances, the first and only thing that is on their mind is they want to see and compare which has the highest % of return only.  In my opinion, that could be quite dangerous. 

Remember that nothing is really free in this world, when you see a system that has a very high % of return, the next few things you should look at (other than at least total trades of more than 50 has been generated) is how much startup capital was used to get that % of return?  What is the Maximum (Open & Close) Drawdown as a % of the startup capital used?  What is the Standard Deviation of trades as a % of startup capital used?  Can you verify the performance yourself?

In short, the % of return is only meaningful when you look at the risk at the same time.  They are the different sides of a same coin!

To show you what I meant, I have two different performance summary for you to compare and choose.  If you love high % of return alone, you would probably choose the first one.  However, if you have lower risk appetite and don't mind a bit lower % of return, you would probably choose the second one, if you have to choose one.

The 1st one...
            
The 2nd one...


Actually both of them are quite similar, its just that the high % of return for the 1st one is due to much lower startup capital being used compared to the 2nd one.  If you can stomach drawdown of more than 90% or you always think that you are the lucky one and would always escape that drawdown when you start trading, then by all means go for the higher % of return one.  If you can stomach only maximum drawdown of about 30-40% , then you may want to consider the 2nd one, if you have to choose between the two.  Cheers & happy trading!


Disclaimer: Taken from CFTC RULE 4.41 – HYPOTHETICAL OR SIMULATED PERFORMANCE RESULTS HAVE CERTAIN LIMITATIONS. UNLIKE AN ACTUAL PERFORMANCE RECORD, SIMULATED RESULTS DO NOT REPRESENT ACTUAL TRADING. ALSO, SINCE THE TRADES HAVE NOT BEEN EXECUTED, THE RESULTS MAY HAVE UNDER OR OVER COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS, SUCH AS LACK OF LIQUIDITY. SIMULATED TRADING PROGRAMS IN GENERAL ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFIT OR LOSSES SIMILAR TO THOSE SHOWN.

AND

WHATEVER YOU READ HERE SHOULD BE USED AS LEARNING AIDS ONLY AND SHOULD NOT BE CONSTRUED AS INVESTMENT ADVICE. IF YOU DECIDE TO INVEST REAL MONEY, ALL TRADING DECISIONS ARE YOUR OWN RESPONSIBILITY.

                                                                 

Wednesday, May 12, 2010

My View On Systematic Trading

     
I received an email from "Blurrturtle" that asked "What are your rules for system trading?"

When I first got this email, I was thinking whether this is a trick question.  System's trading by definition is already trading with a set of rules.  So naturally I was wondering if "Blurrturtle" wanted the set of rules in my trading system or just basic guideline on systematic trading.  I believe he/she meant the second part.

Novice trader may be wondering, why are there so many rules to systematic trading?  First you have a set of rules that govern what, where, when and how you trade, then you have another set of rules to make sure that you follow the previous set of rules!  I'll try to explain why in my future postings.

Here's my simple set of rules for systematic traders:
1. Do proper back-testing and optimization.  Make sure you know your systems performance well then ask yourself if you are comfortable with the max drawdown (usually it will happend sooner and bigger than you think) and how long it takes to recover? If not, don't trade the system or find another one.
2. Make sure you have sufficient startup capital (identified via your back-testing) before start trading.
3. Have in place a method to tell you that you should stop trading the system when it is no longer working.
4. Just strictly follow your system (without fighting with yourself and the market) until 3 happens.  This is usually the hardest part.

I hope that answers the question posted by "Blurrturtle".  Cheers & Happy trading.
        

Friday, November 6, 2009

S&P 500 Index Futures - Result (If Go Live Since 2009)

                           
Since only one person actually did the live test and post the answer after about a week, I might as well give you all the simple answer.

Anonymous is correct, if we use the same strategy and trade live since the beginning of this year (2009), we would have a profit of USD 3,877.50 (trading only 1 contract each time).  Out of 25 trades made, 16 or 64% is profitable with an average trade or expectancy of USD 155.10 and a profit factor of 1.53.  Not fantastic but not too bad either.

Here's the screen for the beginning of the year:





And here's the latest trade until yesterday 5th Nov 2009:




Disclaimer: Taken from CFTC RULE 4.41 – HYPOTHETICAL OR SIMULATED PERFORMANCE RESULTS HAVE CERTAIN LIMITATIONS. UNLIKE AN ACTUAL PERFORMANCE RECORD, SIMULATED RESULTS DO NOT REPRESENT ACTUAL TRADING. ALSO, SINCE THE TRADES HAVE NOT BEEN EXECUTED, THE RESULTS MAY HAVE UNDER OR OVER COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS, SUCH AS LACK OF LIQUIDITY. SIMULATED TRADING PROGRAMS IN GENERAL ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFIT OR LOSSES SIMILAR TO THOSE SHOWN.


AND

WHATEVER YOU READ HERE SHOULD BE USED AS LEARNING AIDS ONLY AND SHOULD NOT BE CONSTRUED AS INVESTMENT ADVICE. IF YOU DECIDE TO INVEST REAL MONEY, ALL TRADING DECISIONS ARE YOUR OWN RESPONSIBILITY.
                                               

Wednesday, October 28, 2009

Out-of-Sample Back-test Result

                              
If you have done your exercise, you would have got the result which looks similar to the screen below:




Not too bad, although not as good as the in-sample test, the out-of-sample test shows a profit of 633 points or USD 15,825.00 before transaction cost. You should be able to program it in by now.

If you have put in a little more effort, you would have found out that the number of winning trades is 111 and the number of losing trades is 59 which give us a winning percentage of 65.29% and a losing percentage of 34.71%. As usual, if the winning percentage is high you’ll have to sacrifice with a bit lower average winning per trades; here it is 19.8 points against -26.5 for average losing per trades.

The average per trade or expectancy of the strategy on S&P 500 index futures (2003-2008) is USD93.09 (before transaction cost). The profit factor would be 1.40. Not that fantastic on the out-of-sample test but what if we were to go live trading using it since the beginning of 2009 until now? Can anyone tell me whether it makes or loses money?


Disclaimer: Taken from CFTC RULE 4.41 – HYPOTHETICAL OR SIMULATED PERFORMANCE RESULTS HAVE CERTAIN LIMITATIONS. UNLIKE AN ACTUAL PERFORMANCE RECORD, SIMULATED RESULTS DO NOT REPRESENT ACTUAL TRADING. ALSO, SINCE THE TRADES HAVE NOT BEEN EXECUTED, THE RESULTS MAY HAVE UNDER OR OVER COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS, SUCH AS LACK OF LIQUIDITY. SIMULATED TRADING PROGRAMS IN GENERAL ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFIT OR LOSSES SIMILAR TO THOSE SHOWN.


AND

WHATEVER YOU READ HERE SHOULD BE USED AS LEARNING AIDS ONLY AND SHOULD NOT BE CONSTRUED AS INVESTMENT ADVICE. IF YOU DECIDE TO INVEST REAL MONEY, ALL TRADING DECISIONS ARE YOUR OWN RESPONSIBILITY.
                              

Tuesday, October 27, 2009

Trading Strategy Refinement

                             
So far we have completed the step 8 of the whole process of design, develop and built a simple trading system and I used SMA (5) crossover SMA (10) as an example. You now actually have a simple trading and back-testing system already! All you need to do is to expand the system, continue to read more and build and test more trading strategies until you have found one that you are comfortable and have confident trading in.

If you have done the earlier exercise and completed the simple back-test system, you would have noticed that the SMA (5) crossover SMA (10) actually lose quite a lot of money on S&P 500 index futures! That is the reason why I want to use the S&P 500 as an example for our exercise. The screen shot of the bottom portion of the completed basic system is here:



Does it mean that the simple moving average crossover strategy cannot be used? One simple way you can try and find out is to change the periods in the SMA crossover that we used e.g. SMA (5) x SMA (15) and step through each time with fixed increment and see the results! I know, that means a lot of work. Some of the commercial software can do the stepping automatically and it is normally meant for the professionals. That would reinforce the concept that nothing is really free in this world as well as time is money!

Another interesting way (which is the focus of my using of S&P 500 index futures as an example) to sometimes accidentally find your trading strategy is when you back-test a strategy that you thought should work but turn out to be a loser, you can inverse it to make it a trading strategy! For example in this case we could inverse the SMA (5) crossover SMA (10) and turn it into counter-trend strategy or trend fading strategy.

Let’s try to change the rules and reverse the buy and sell. Here’s the screen shot of the in-sample.




As predicted, we now have a winner on SMA (10) crossover SMA (5) counter trend strategy on our in-sample. What do you think the strategy will fare against the out-of-sample? This is your exercise again. I will post the result on my next article. Happy trading and good luck!
          

Disclaimer: Taken from CFTC RULE 4.41 – HYPOTHETICAL OR SIMULATED PERFORMANCE RESULTS HAVE CERTAIN LIMITATIONS. UNLIKE AN ACTUAL PERFORMANCE RECORD, SIMULATED RESULTS DO NOT REPRESENT ACTUAL TRADING. ALSO, SINCE THE TRADES HAVE NOT BEEN EXECUTED, THE RESULTS MAY HAVE UNDER OR OVER COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS, SUCH AS LACK OF LIQUIDITY. SIMULATED TRADING PROGRAMS IN GENERAL ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFIT OR LOSSES SIMILAR TO THOSE SHOWN.

AND

WHATEVER YOU READ HERE SHOULD BE USED AS LEARNING AIDS ONLY AND SHOULD NOT BE CONSTRUED AS INVESTMENT ADVICE. IF YOU DECIDE TO INVEST REAL MONEY, ALL TRADING DECISIONS ARE YOUR OWN RESPONSIBILITY.
                                                        

Monday, October 26, 2009

Designing and Developing a Simple Trading System – Part 5

                               
In this article, I’ll show you how to complete the rest of the fields of our basic trading and back-test system that I use as an example.  You can expand the columns and start adding in things that you wish to calculate later on.   

Click and select cell S2 then type in Open Position

Click and select cell S12 then type in =IF($N12<>"","L",IF($Q12<>"","S",S11)) click and drag the lower right corner of the cell and fill the rest of the rows.

Click and select cell T2 then type in Entry Price

Click and select cell T12 then type in =IF($N12<>"",N12,IF($Q12<>"",Q12,T11)) click and drag the lower right corner of the cell and fill the rest of the rows.

Now you will have a column showing your open position as well as the entry price of your open position.

To start calculating the profit and loss of each trade as well as the cumulative profit and loss, first click and select cell V2 then type in Profit / Loss

Click and select cell V13 then type in =IF(S12<>S13,IF(S12="L",T13-T12,T12-T13),"") click and drag the lower right corner of the cell and fill the rest of the rows.

Click and select cell W2 then type in Cumulative P/L

Click and select cell W11 then type in 0

Click and select cell W12 then type in =IF(V12<>"",V12+W11,W11) click and drag the lower right corner of the cell and fill the rest of the rows.

The last column is fairly easy; I’ll leave it as an exercise for you. If you can’t finish it, that means your interest and passion is still not enough, maybe trading is not suitable for you yet.

If you manage to finish it, you’ll realize something important which I’ll explain in my next post. Happy trading and good luck.

Oh, I’ve forgot, the screen should look something like this:


                                             

Friday, October 23, 2009

Why and how do we do back-testing?

              
This posting is for you, Turtle (in your previous comment you ask about the period used for the historical data that you have and their differences and relevance).

The answer, in my opinion is surprisingly simple. Just imagine what will happen if NASA engineers build a rocket and launch straight away without any simulations and refinements were being done? Statistically of course, we can’t rule out the chances that it will be successful on the 1st launch without any prior test being done (I will come to that when I have the time) but we all know that the chances would be very small, maybe less than 0.00001%?

The same concept goes with pharmaceutical companies that design and develop drugs that would eventually become the medicine that we take. They would usually go through a few phases of clinical trials which would last for at least a few years before being approved to the market. The same also goes for companies that design and build cars and the list goes on…

Now, what makes us so special that we can immediately go live trading without any simulation or test (to prove that the strategy has edge) being doing on the strategy that we are going to use, if we actually have one and really stick to it? There are so many variables or things that could go wrong when we go live trading but the least we could do is to reduce that chances of failure on things that we have full control of such as our trading strategy and its verification.

However, having said that most beginners thought that once they have done the correct back-testing then the strategy will definitely work. Unfortunately nature just doesn’t work that way. If I were to show you now the studies that I’ve done using Monte Carlo simulations (which I will later) on trading strategies’ possible outcome when go live, and if we were to take the outliers (extreme events) into full consideration, you won’t start trading! It is almost like if you are expecting that the drugs that pharmaceutical companies produces will have to pass with zero side effects when they do their trials before being allowed to go to market. I don’t think any would be passed if they do their trials properly!

We do statistical test via sampling process because it is either impossible to get the whole population for us to study or the time and other constraints make it not worthwhile to study the whole population. The same goes with trading. It is not practical to back-test 50 years of data as not many product would have that long of a history! Even if you take all 50 or 100 years of data, it is still relatively small if you think that our financial markets are actually still very young, what if it survive another 5000 years?

However, the more data we study, the more (higher chance) the test result would better reflect the actual population, but it will never be 100%! Now, Turtle, if you have the historical data for FKLI & FCPO since 1996 and have verified that they are correct, then why would you only want to choose only 2006 onwards to back-test? As I have said in my earlier posts, when we test our trading strategy, we should actually try very hard to fail it and not the other way around. If we can’t fail it only then we would be more confident of its chances of success in the future. Therefore we would use the data that has all the different market cycles in it. A full market cycle is usually between 8-12 years at the moment. Trust me, generally the performance result of our strategy would degrade the longer the data we used.  All systems break at some point in time.

Now there is no hard and fast rule on how exactly you want to perform your statistical test, but the general rule would be to separate them into two equal period, in this case 1996-2002 and 2003-2009. The more advance commercial software would allow you to automatically step through all the possible different combinations of period and perform the test!

You can choose either period as your in-sample (personal taste) e.g. 1996-2002 which you will develop, test, optimize and re-test until you get the best compromised result. After that just treat the period 2003-2009 as if you start trading at the end of 2002 with real money (usually call out-of-sample), see what happen to the strategy that have passed the in-sample test. If it pass with good result, then chances are good that it will continue to perform well in the future (notice I didn’t say for sure). If it perform badly then you must not change the parameters or optimize your strategy on the out-of-sample anymore. It just means that either you have overly curve fitted your strategy to the in-sample data or your strategy is not robust enough to withstand the changes in the underlying structure of the market.

Remember, the only thing that is constant about the market is that it is constantly changing! I hope that answers your question about the differences and relevance of choosing different period.

Do let me know if you are still confused. It is ok, trust me, it took me a few years to fully understand the concept and apply them (without any outside guidance and help of course).
                          

Thursday, October 22, 2009

Designing and Developing a Simple Trading System – Part 2

              
Ok, let’s go back to our S&P 500 in-sample and see if our earlier SMA (5) crossover SMA (10) strategy works on it. At the moment, we will begin our step 5 which is to start programming the strategy in MS Excel together with the buy and sell signal.

The raw S&P 500 index futures daily back-adjusted continuous data would look like below:




The first thing we add is the SMA (5) column. Click on cell J7 then type in =AVERAGE($F3:$F7)

Then fill the rest of the cells below with the formula by click-and-drag the bottom right corner of cell J7. There you go; you have created your 1st calculation on Simple Moving Average on Excel. It is that easy.

Repeat the similar process this time on cell K12 with this formula =AVERAGE($F3:$F12) and you have a SMA (10). The screen should look like this:



Now we have a S&P 500 index futures historical data (in-sample) spreadsheet with SMA (5) and SMA (10) indicator already. Isn’t that easy? I will show you, especially for anonymous who ask in the comment section in my previous article, how to program the buy and sell signal into this spreadsheet on my next article.  You won't believe how easy it is.
                  

Wednesday, October 21, 2009

Designing and Developing a Simple Trading System – Part 1

                                                 
Before I start, I would like to wish lp happy birthday!  You are as sweet as ever.

First, a quick recap.  You’ll need a historical data separated into two different periods (in-sample, out-sample) preferably each is more than 4-5 years of data consist of date, open, high low, close, volume and open interest (if possible).  I would like to side track a bit first by showing you what your eventual basic system will look like on FKLI data downloaded from Bursa Malaysia from 2004-2009 then I would follow on with the developing process using S&P 500 index futures.  The main reason is to show you different ways of using quantitative methods to design your trading strategies.

For our first simple system, assuming that we don’t like to have big losses but don’t mind a bit more whipsaws (remember it is always a balance, or trade-off), I’ve simply selected SMA (5) and SMA (10). The rules again:

1. Go Long 1 contract on next day market open when the daily closed SMA (5) crosses above daily closed SMA (10); if got Short position, Long 2 contracts (close Short contract and open new Long contract).

2. Go Short 1 contract on next day market open when daily closed SMA (5) crosses below daily closed SMA (10); if got Long position, Short 2 contracts (close Long contract and open new Short contract).

The eventual screen shot of this system would look like this (forget about margins, commissions etc. first):





Let’s scroll down and look at the profit and loss (P/L) of this very basic system:





You can see that the strategy is profitable on FKLI from 2004-2009. It made 705.5 points so far or equivalent of MYR 35,275.00 and even the open position is profitable.  Remember that the signal is generated at the end of the day and the entry price is the next day's openning price.

Please bear in mind that this has not taken rolls, slippage and commissions into consideration yet! We’ll come to that part in the later stage of development. We’ll use this strategy and go through the building and testing on the S&P 500 index futures on the next posting.
                         
Disclaimer: Taken from CFTC RULE 4.41 – HYPOTHETICAL OR SIMULATED PERFORMANCE RESULTS HAVE CERTAIN LIMITATIONS. UNLIKE AN ACTUAL PERFORMANCE RECORD, SIMULATED RESULTS DO NOT REPRESENT ACTUAL TRADING. ALSO, SINCE THE TRADES HAVE NOT BEEN EXECUTED, THE RESULTS MAY HAVE UNDER OR OVER COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS, SUCH AS LACK OF LIQUIDITY. SIMULATED TRADING PROGRAMS IN GENERAL ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFIT OR LOSSES SIMILAR TO THOSE SHOWN.


AND

WHATEVER YOU READ HERE SHOULD BE USED AS LEARNING AIDS ONLY AND SHOULD NOT BE CONSTRUED AS INVESTMENT ADVICE. IF YOU DECIDE TO INVEST REAL MONEY, ALL TRADING DECISIONS ARE YOUR OWN RESPONSIBILITY.
                                             

Tuesday, October 20, 2009

Trading Strategies – Part 2

                
Majority of beginner traders would spend most of their time searching for a perfect entry.  They would form a strategy based on a few observations on chart patterns and then start trading, after one or two losses they would fine tune or switch to a new strategy and the process keeps repeating until either they have no more money to trade or they would find other excuses such as the market is rigged or being manipulated or I don't have time for it.

The market is unpredictable and full of random movements in the short term.  As a system trader, we don’t try to predict where it will go after we enter, the market will do what it needs to do, our job after entry is to know what point to exit, and it is the exits that determine our profits or losses!  Most beginners simply looking at the wrong place for the right answer.

In the initial stage, it is best not to limit yourself and explore as many trading ideas as possible.  After that, try to write down those ideas into a step-by-step formula or algorithm if possible, that is as clear and precise as possible.  Trust me; a lot of time you’ll find out that many good ideas is not really tradable when you try to program them.  For example, if you have a trend-following position strategy such as SMA crossover and you set your stop-loss point at 20 points trading FCPO, it just won’t do.  It is good on theory to take your losses when they are small, but bear in mind that small is a relative word!  If you use a simple 25 period ATR (average true range) to measure FCPO, the intraday range is about 50-60 points at the moment!  That means there is a very high chance that you would get stop out of your position at the same day you enter.  The best solution in this case is to use a percentage instead of a fixed price.  Of course there are many other ways, one of the famous one made popular by the turtles would be a factor of the ATR e.g. get out when the price hit 2 x ATR of your entry price.

I know, you would be saying are you nuts?  If the ATR (25) of FCPO now is 60 points that means you would only get out after you loss 120 points!  That is right, if you are a position trader.  Just imagine if your system has 5 consecutive losses over the pass 10 years of back-test, which is very common!  That would be 5 x 120 points = 600 point = 600 x MYR 25 = MYR 15,000!  And you wonder why a lot of retail traders blow out trading FCPO holding overnight position starting with MYR 10,000!  What is the lesson here?  Know the minimum startup capital needed for your chosen strategy.

Remember, a complete trading system must at least have a setup, entry, stop-loss, exit, and position size management.  Money management is about managing the size of losses as well as maximizing the profits.

What constitute a correct algorithm?  For traders trading their own account, the system must be able to enter when the market move according to your entry criteria, must be able to get out when market meets your exit criteria.

I will give you two different examples.  Let’s say you know that SMA is a lagging indicator, you want to use it as your trend-following strategy, but you have also notice that a lot of times after the crossover, the price is already too high (or too low for Short), a retest (a common process to shake-out the weak hands) will happen, and you set your entry rule to buy only on retest of the previous 3 day’s low (or previous 3 day's high for Short).  What is the problem with this perfectly logical rule?  The problem is, you may not be able to enter at all if there is no retest or the retest does not reach the 3 day’s low price!

Another example would be a triple SMA (10, 20, 50) crossover strategy.  You can have a strategy that go Long when SMA 10 crosses SMA 20 and SMA 20 is above SMA 50 and the closing price is above SMA 50 and to turn Short when SMA 10 crosses below SMA 20 and SMA 20 crosses below SMA 50 and the closing price is below SMA 50.  There is no problem so far.  But some traders decide to exit Short early with just SMA 10 crosses above SMA 20 and the closing price is below SMA 50. Now you have a problem.  As there will be instances where the closing price is maintain above SMA 50 when the SMA 10 crosses above SMA 20 and SMA 20 crosses above SMA 50.  What’s the problem?  Your system had just issue a Long entry signal but there is no exit Short signal yet!  How are you supposed to turn Long while still maintaining your Short position trading one account?  There is a conflict here, please don’t laugh, you can find the above said strategy (only different in the SMA period used) in a highly rated trading book!  The fact is, if you didn’t program the rules in and does your own verifiable back-test in excel, you would have thought that it is a very good strategy.  A lot of strategies seem very good on the surface but are not feasible when you try to implement them.

For step 3 & 4, using my previous example on the steps in designing a trading system, which is deciding on your trading strategy as well as putting it in a clear instruction, I will use the most common and quite often still among the best strategy which is a Simple Moving Average (SMA) crossover.  The rules?

1.   Go Long 1 contract at next day market open if closing price SMA (x) crosses above closing price SMA (y), if got Short position, buy 2 contracts.
2.   Go Short 1 contract at next day market open if closing price SMA (x) crosses below closing price SMA (y), if got Long position, sell 2 contracts.

It is that simple!  It is also a stop-and reverse system; meaning you will have open position all the time.

I will show you how you can do it on your own in MS Excel on my following posts. Until next time, good luck and happy trading!
      

Monday, October 19, 2009

Trading Strategies - Part 1

               
The 2nd step in the systematic trading systems design and testing phase is to read and really understand as many trading strategies as possible.

To use our earlier analogy, the car that you design and build for the race would be your trading system.  What type of car do you want to build?  How do you put those pieces together?  Does it work on grass or uneven roads?  Immediately we can see that it is more of an art rather than science and is quite complex!  Everyone would have different taste on things that they want to put on their car, there is no one size fit all solution again!

However, my general guideline would be to focus on winning the race!  Beautiful car (on concept or in reality) but mediocre performance will not work.  What type of road conditions do you expect most of the journey?  What type of different weather do you expect?  What about your own strengths and weaknesses?  Are you fast at night or day time, on tar roads on sandy one, fast at corners and winding roads?  Perform better when it rains or hot and dry conditions?

There are so many different trading strategies exist at the moment I can’t possibly discuss them all.  However, it is best to have a few different strategies that would take advantage of the different market cycles e.g. trend-following, counter-trend, for sideways and congestion such as mean-reversion, for spreads such as mean-convergence etc.  Please remember that there is no secret strategy that would be able to consistently take advantage of all the market mispricing all the time!  There is always a trade off.  Usually a strategy that is good on one type of cycle would be bad on others.  Your task is to find a strategy that you have confident in trading and to find the balance so that it would not perform too badly on the cycles that it is not designed to capture and to maximize the profits when it perform well.

For example, if look at trend-following strategies, they usually have a % of winning trades that is below 50% (some about 30%) but they make it up in the average profit per trade of usually more than twice the average loss per trade.  Whereas in counter-trend strategy, usually the % of winning trades are higher than 50% (some about 70%) but the average profit per trade is usually much less than average loss per trade.  Improving one measurement such as % of winning trades would usually suffer on the average profit per trade.  That is life; you gain some you lose some!

Try to use the simplest strategy such as Simple Moving Average as your benchmark to compare the worthiness of your new strategies.  For those of you that have experience, you would definitely think that SMA is only use for trend-following, but as I will show in my next example, we can also use SMA as a counter-trend trading strategy, and quite a good one as well.

Please make sure that for every strategy that you are interested in, you can objectively put them into clear rules that anyone who read it would be able to take the same signal and execute the same order as you design it to be (forget about slippage first).  Leave all the subjective judgments, opinions and guesswork behind.

Therefore if you are a systems trader, a lot of chart patterns such as double top, head-and-shoulders, cup-and-handle, support and resistance, flags and pennants, triangle, wedges, wave count etc can’t be used (not that they are not good) unless you can define them clearly and be able to program them!  The task is definitely not for beginners!  This process is actually quite useful in detecting the charlatans who always use vague strategies to fool beginners.  Those strategies always look very good on paper but useless when you want to apply in real trading.

A good book to start would be The Encyclopedia of Trading Strategies.  If you want to know almost all the common technical indicators (over 100), their algorithm and back-test performance summary then you can refer to The Encyclopedia of Technical Market Indicators, 2nd edition by Robert W. Colby or go to the chart school section of stockcharts.com and refer to the Technical Indicators section.

The general strategies that a beginner can use to design their trading system would be (in random order) SMA crossovers, EMA crossovers, Oscillators such as MACD, RSI, Stochastics, ADX-DMI and CCI, Parabolic , Pivot points reversal, Donchian channel breakout, Volatility based breakout e.g. Bollinger Bands breakout, ATR (average true range) breakout.  You can add in the comment section if you think I have left out some good programmable strategies that would benefit beginners.

Please take note that technical indicators are just the ingredients, it is how you use them that defines your strategy.  So, again there is no such thing as good or bad indicators!  It is how you deploy them that counts.  You could also create more complex strategies by mixing and matching different indicators, however please bear in mind that complexity doesn’t equate robustness and efficiency.  Sometimes simplicity is the best policy as there are fewer variables that will cause the systems to break down or to maintain!
                            

Sunday, October 18, 2009

Historical Data - The Analogy

                        
Before I go into step 2 which is on trading strategies, I would like to expand on the analogy I used earlier which is comparing petrol in our car before go round the world to our trading capital. 

Just imagine now that instead of a nice and relax tour, it is a car race and the price money would only be given to the first 5% of racers around the world that finish the race and the amount increases (non-linear) if you finishes earlier.  To make the matter worst, the price money would come from the rest of the 95% with the last few pay more than others!  Those who didn't finish the race would have to pay everything they have!  Now would you join the race?  If you did join, won't you give your all to be among the top racers?  And to be among the top racers do you think it can happend overnight?  Or by just reading a few books, listen to "pros"'s advice, watch a few training videos, listen to audio tapes or attend a few seminars?  Do you think it would be that easy?  How many years did Michael Schumacher learn and practice before he became Formula One champion?  Furthermore, since the barriers to entry in Futures trading is much lower compared to the rest of the fields it would be even more competitive!

If you want to be among the top racers naturally you'll have to focus and learn everything you can grab your hands on regarding the race such as the route to final destination (types of different road conditions), what type of  car would you use, build your own or using other people's design, the sample terrain to test and then fine tune your design again and always be prepared for emergencies or even better to have preemptive measures, before deciding on a winning strategy (e.g. to go fastest on tar road but slow on others or moderately fast on all types of road conditions and weathers) and make sure that you have the discipline to follow it, but also allowing yourself some freedom to adapt and change if the actual race condition differs from your in-house simulation.

In this analogy, the process of collecting historical data would resemble collecting different terrain information before you design and test your car on.  Naturally you want to collect as many as possible within the constrains of time and financial capability.  It wouldn't be hard to see that if you have collected wrong data to build you simulator, the car you design is useless at all (for the race) even if you have used the state of the art technology to design, test and refine it correctly!