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!
  

Thursday, October 15, 2009

Historical Data

                     
The 1st step before you start designing your simple trading system is to collect the historical prices of the products that you want to test your strategies on.  Many in statistics would refer this as sample collection process.

In my opinion, it is one of the most important processes that will determine the chances of success or failure of your trading systems.  Why?  Imagine if you have a strategy that is trend following and you have collected and test your strategy on crude oil futures data from Aug 2007 - Mar 2009!  Your strategy will be able to ride the trend on the way up as well as on the way down giving you a rate of return that would be very high.  Even though you may have done every calculation correctly but the robustness (the ability to withstand different cycles) of the system was jeopardize because your sample size is not reflecting the actual population's profile.  If you are a computer programmer, that’s what you call garbage in garbage out.  The analogy would be to choose only 10 males to do your survey before designing a car or mobile phone.

This is also how the unscrupulous systems sellers or trading coachers or some “professionals” fool most beginners.  They would usually choose a strategy that will match perfectly with a certain period (usually very small) of the historical data and show you the performance summary that is too good to be true.  But if you were to verify the strategy on your own with longer term data and more trades, you’ll see that it is not as rosy as it seems.  If it is really so good they would have sold everything they have and trade on their own already no matter what they choose to say to the contrary such as “my interest is coaching and help people”, “I’m giving back to the society” nonsense!  But if you are ok accepting advice from someone who can't do what they teach, then by all means, don't let me stop you.

Therefore a few general guidelines are very important when you choose your period of historical data.  First, we must at least make sure that the period is long enough (generally more than 5 years and would generate at least more than 30 trades) and the data has all the different cycles of the market such as bull, bear, range (bigger cycles of ups and downs) and congestion (tight ups and downs).  The next thing is to go through all the data and look for possible errors such as prices that deviates too far away and cross check with other sources if possible.

As futures contracts have expiration, we’ll need a way to make it into a continuous data.  Sometimes you’ll have huge gaps between the most active month (most trading volume and highest open interest) and the month after it and it’ll affect your entry, stop or exit signal unnecessarily and affect your back-test result when it rolls over.  Either you do some adjustment when the expiration nears or no adjustment at all or you just continue with new data when the old one expires (roll on expiration).  There is always a trade-off in choosing different ways of adjusting the data.  The professionals would mostly use back-adjusted data (google yourself) but unless you can download free or at a reasonable fee from the internet, it will be too tedious for us mere mortals to do the adjustments ourselves.

The best is to use back-adjusted continuous data, but if you can’t get the data, then you’ll just have to use the roll on expiration method but you’ll have to check all the trades and make sure that they are not affected by a huge gap when rollover.  In addition, you’ll have to factor in the rolls into your performance summary as sometimes they are not favorable to your positions when you roll them.

You can start by downloading the FKLI and FCPO historical data which is available free on Bursa Malaysia’s website http://www.bursamalaysia.com/website/bm/market_information/market_statistics/derivatives/downloading.html

Usually you’ll get 3 complete years of daily data before the current year in Excel format.  Just download the FKLI and FCPO from 2006 – 2009.  For FKLI, after downloading, just construct a continuous data from the spot month contract section (date, open high, low, close and volume).  As for FCPO, just use the next two month section.  You’ll notice strange change in open position column on the 16th of every month as the expiration is on the 15th of every month. The data is in continuous roll on expiration or unadjusted format.

But for my example, I’ll use the S&P 500 index futures continuous back-adjusted data from 1997 – 2008 (12 years) which you can download free from the internet.

I’ll use the data from 1997 – 2002 (6 years) as our in-sample to design, test and optimize on, using a simple strategy as an example to show the development, testing and optimization process in my future postings.
       

Wednesday, October 14, 2009

Trading Systems On Excel

                             
Why MS Excel? You may ask.  I know, it has its limitations and fair shares of ridicule such as “it is meant for amateurs”, “poor man’s tool”, “it is unreliable, especially the rand function is not really random” etc.

In my opinion MS Excel has grown and improved quite a lot.  In fact, the benefit of using it now as a fast starter tool for beginners and average users outweighs its shortcomings.  It is good enough for most of us.  Most importantly a lot of users can start immediately without paying extra for other software.  That is a huge cost savings as some of the trading systems development and testing software cost easily few thousand dollars not to mention you have to pay yearly subscriptions.  In addition, there are plenty of reference books or online help available.  However, if you are planning to back-test a portfolio consist of multi-market and multi-timeframe strategies then Excel is not for you.

The files we have created using Excel are also very portable and we have less worry that the company behind it would stop supporting it suddenly.  On top of that, we can also check and verify the coding or scripting logic easily.  Anyway, if you are a rocket scientist or advance trader, this blog is not meant for you.

There are many different steps that beginners can follow and learn to create their own simple trading and back-testing systems.  Usually different “professionals” would stress their own unique terms to differentiate from others but nevertheless the overall process is quite similar among each other.  Here is mine in summary (I will explain each step in more detail in my future postings):

*please note that my focus is for futures systems traders holding overnight positions and are trading their own account.

1. Collect all the relevant historical data on the markets and products that you are interested in, as many years as possible, the longer the better.  It is better to have it when you don’t need it than to need it and you don’t have it.  This step can be done parallel with other steps below.  This step would also help you to know more markets and products.

2. Read and know as many trading strategies as possible.  Of course in order to do that you’ll also have to know as many market indicators as possible. Two good books to start is The Encyclopedia of Technical Market Indicators and The Encyclopedia of Trading Strategies.

3. Decide on a few trading strategies (preferably different styles as well e.g. trend-following and counter-trends) that you like better and are comfortable with, even after knowing very well with their strengths and weaknesses.  You can even mix and match or create your own if you want to.  You can forget about finding a secret trading strategy that wins all the time or can catch all the highs and lows, it does not exist.  I am sorry for destroying your dream.

4. Write down the strategies in a step-by-step, clear, detail and non-conflict (such as buy and sell at the same time or holding long and short at the same time) format.  Make sure that even a 16 year old teenager can follow and will execute at the same price (forget about slippage first).  This is the part where you transform  from being trading based on pure chart pattern reading but vague in implementation such as double top, head-and-shoulders, cup-and-handle, support and resistance, doji reversal etc. into something accurate and precise!

5. Program them in MS Excel complete with signal for buy and sell (beside a portion of historical data of a product).  By this stage you have your simple trading system already.  If you can't program it and get precise entry signals on Long or Short, you still don't have a mechanical trading system!

6. Extend the program to include the exact entry prices for Long and Short.  You have a stop-and-reverse system already.

7. Add in the Stop-loss and Exit for Long and for Short complete with their prices.  Now, you have a simple complete trading system already.

8. Start adding in the calculations for the profit and loss for each trade in points and in the traded currency, separating the longs and shorts and you now have a simple complete back-testing system!  It is that easy.

9. Create a summary sheet referencing each calculation that you have and you have a performance summary!

10. Try changing the values used in your indicators as well as stops and exits and record them down then do a comparison and now you are doing an optimization!

11. After you have got the result that you are satisfied, change the first portion of data with another portion of the same product but different period.  This time see if the result is as good. If not, don’t optimize further, you can refine your strategy and start the testing process again or just repeat step 4 & 5 with different strategy then repeat step 7 & 10 & 11 for the 1st portion of data until you get both in-sample and out-sample result that you are satisfied.  Trust me, it is fun and challenging.

12. Verify if you have enough startup capital to trade (see previous posting).  If yes, you can start trading, with strict discipline to stick to your trading system through thick and thin!  You are supposed to do all the thinking, discretionary, artistic and imagination exploration while doing the development and testing.  If not just save until you have more than enough capital or find another startegy or market that meets your capital requirement.

13. Record each trade and monitor your trading result closely.  If the result deviates from your back-testing result, do a Monte Carlo simulation to verify if the deviation is significant.  If it is, stop trading (remember you are the master, not your urge to trade) and go back to the drawing board.  If the deviation is not significant, continue trading and repeat this step again.

*money management can be added once the basic system is done correctly.

There you go, simple guidelines for would be beginners on systematic trading.  I will begin sharing and discussing the individual steps in my future postings.  Some of the good reference books for beginners and intermediate traders would be Quantitative Trading Strategies, The Evaluation and Optimization of Trading Strategies and Trading Systems That Work.  Just enjoy the journey!
  

Tuesday, October 13, 2009

Deciding the Right Amount of Startup or Seed Capital

                          
OK, let’s start with one of the most important thing before you start trading: deciding how much capital to put in. Before I start showing a common method that is being used by many system traders, I would like to stress that this is just a guideline, there is no such thing as one size fit all rules to follow, just know your own strengths and weaknesses and adjust accordingly. The method here tends to be more conservative, therefore the return rate on startup account would be lower as well. Remember that it is always about finding the balance in trading; if you want to have a higher chance of surviving the worst drawdown, then you’ll have to start with more capital, but that in turn would limit your rate of return on startup capital.


As an example, let’s say you have decided to use my earlier example which is RSI 55/45 trend-following system to trade FKLI. You have done your statistical back-testing and obtain the following result (don’t worry, I’ll discuss the process of statistical back-testing on my following posts).



The first thing in this case that you’ll have to look at is the maximum drawdown near the bottom. It can be expressed as an amount or percentage. Since we’ll be deciding on the startup capital, we’ll look at the amount only. A drawdown is basically the amount of losses in your trading account from current peak level to the lowest point (valley) before the next peak. The maximum drawdown therefore is the largest drawdown from the back-testing period. That would represent the worst equity fall before your account goes up again.

If you look at the performance summary, there are two maximum drawdown values. First one is maximum closed drawdown and the other is maximum open (intraday) drawdown. Since this is a trend-following position-trade based on daily data, we’ll hold position overnight. Remember this is just trading 1 contract. The maximum close drawdown only measures the positions that have been closed whereas the maximum open drawdown takes into consideration the intraday worst point in your open position as well. Therefore the maximum open drawdown is usually larger than maximum close drawdown. Occasionally they may be the same if you close the position at the worst point but it can never be smaller.

What most beginners tend to forget is that the maximum open drawdown is more important if you are deciding on the worst case scenario. What we want is to find the level that will likely survive the worst drawdown and still above the worst case of margin set by the exchange for that product so that you don’t have to top up any more capital for margin call or risk your open position being liquidated by your broker. Of course systems sellers would definitely want you to be able to start with minimum capital therefore they will tend to focus on the maximum close drawdown. Just be sure you know the difference.

Now here comes the part that is most controversial and you’ll have to adjust to your personal objective. If you are a very optimistic person then you would probably believe that whatever period you have used in your back-testing is the worst that is going to be, then you can set your startup capital = maximum open drawdown + worst (highest) margin set by exchange. In this example you’ll need a minimum of RM 21,850 + RM 8,000 = RM 29,850. Remember this is the minimum amount trading only 1 contract and you are being very optimistic! How many retail speculator you know start trading FKLI with that amount and are discipline to trade only 1 contract?

Let’s say you have read Nassim Taleb’s Fooled by Randomness and The Black Swan, and still have the courage to trade, you would want to be more conservative in setting the level of startup capital. Most professionals and authors of books on systematic trading would recommend a safety margin or factor of 2 x maximum open drawdown (based on the belief that the worst is always in front of you). If you were to follow them, then the startup amount would be = (2 x RM 21,850) + RM 8,000 = RM 51,700. That would also take care of the slippage, rolls and commissions which is very often neglected by system sellers!  Now, how many do you think start with this amount using the particular RSI strategy and trade only 1 contract?  Ever wonder why most authors said only about less than 5% of winners in futures speculation? To make the matter worst, that drawdown is over 40% of your conservative startup capital! How many people can still believe in their systems and follow the signal on the next trade after suffering that amount of losses? They would tend to second guess and overwrite their systems by then.

To summarize things up, in order to know the right minimum amount of startup capital to trade, you’ll have to have a set of trading rules that represent clearly your trading strategy (that you’ll follow), otherwise there is no way of measuring accurately the amount of maximum open drawdown using your strategy. Then you’ll have to get a historical data that is correct and has all the different cycles of the market (I’ll go into that when I start posting on designing systems) and do a simulation of trades based on your trading rules. Calculate the lowest level (include intraday worst case) from current peak level of equity, then multiply that amount by 2 and add the highest margin ever set by the exchange for that product for that period and that is your MINIMUM capital to start trading. It is that simple!  You just have to find the balance point yourself.
                     

Monday, October 12, 2009

How Much Capital Is Required ? First Things First!

       
One of the strangest things that I have found out about trading was that majority of the normal traders or speculators start trading with an arbitrary amount of capital, and is usually the maximum amount that they can come out with (usually between 5K-20K) and of course approved by broking houses that need the business.  Even most "trading coachers" seldom show you the quantitative method of determining minimum capital to trade their "holy-grail" or "sure-win" strategies!  I doubt they have one as most of their strategies are nothing but vague systems.  A lot of them didn't even really trade!

Why is it strange?  It would be a lot clearer if I may use an analogy.   Please also bear in mind that sometimes analogy is good in bringing the core message across but the comparison may not be always exactly correct.  So if you strongly disagree, do feel free to voice your opinion in the comments section below.

If you are going to drive (in this case petrol driven car) to a destination and do really want to reach it (self-sabotage is entirely different topic) which is quite far away say about 500-600km (it may be part of a very long journey, say round the world).  I am sure one of the most important thing you would always do is to make sure that your car has more than enough fuel to get to the next petrol station before reaching your next destination, if your petrol cannot last you until your next destination. 

If you replace drive with trade, car with trading method (discretionary traders) or systems, destination with profit target, then the petrol would be your capital!  Most people have no clue how important the amount of seed or startup capital is to their trading success or failure.  When they don't realize the importance, naturally they won't put much effort into the methods in which will help them decide the minimum required capital to start trading that will ensure them a higher probability of success (sometimes they have a feeling that they are under-capitalized but they do it anyway).  Therefore, they just put whatever amount that they can afford and is more than the minimum required margin set by a broking house.  I say broking house because some charge lower than the margin required by the exchange (which also help increase the failing rate)! 

What if the next petrol station is closed? What if the destination has no petrol station? Do you see consecutive losses here? Does your car still have enough petrol to go to the next station?  Remember, anything that can happen will happen in trading eventually!

Notice a lot of other things in this analogy are also very relevant to trading? For example you can replace the terrain as the product or market that you are trading, driving mostly day time or at night as your trading style (trend or counter trend) etc.  Notice also that therefore the focus of my blog is to show that anyone can design and build their own car that will match their driving skill and on the terrain that they want to drive!  At least after learning all that, when someone approach you and want to sell what they claim is Ferrari or Veyron (ultimate trading systems) to you very cheap when you will be driving on savannas, you can tell them thanks but no thanks, you don't even have to verify their claims.   I will expand the analogy as I go along. Of course, some comparison may not be as clear cut or may stretch a bit too far because trading and driving are two different activities.

Imagine majority of people starting a long journey with petrol below reserve level in the tank (minimum margin required by the various exchanges for various products)!  And they wonder why they kept blowing up their accounts!  Not to mention that they may not even have a  car (method) or is using other people's car (other people's method) or did not check out the routes (know the market profile) to their destinations!  Isn't that strange?  Do let me know your opinion if you don't agree with me. 



Why is it so important to start trading with a level of capital above the minimum required capital (your own reserve tank level) which varies according to certain factors?  Confuse with so many reserve levels?  Don't be, generally there are only two levels, one which is your own (higher) and one which is  set by the various exchanges (lower).  I will explain, in a scientific way of course, and will be posting one of the most used methods in my next posting.  Of course you can show us your method if you have one and is willing to share.  For now, happy trading and good luck.
     

Saturday, October 10, 2009

Disccretion vs. System or Mechanical or Algorithmic Trading

        
Please bear in mind that altough my blog focuses on systems or mechanical or algo trading, it doesn't mean that I discredit discretionary trading (meaning you evaluate and decide on each trade, some like to call it gut feel).  The best system traders so far can't beat the best discretionary traders such as Paul Tudor Jones or George Soros!  If you are hoping to turn 10K or 20K into millions in a short time (1 or 2 years), then you can forget about going mechanical trading.  No systems on record so far can match the best discretionary traders.  Therefore I do not wish to go into the endless debate about which is better.

I prefer system here simply because it is the scientific way, objective, clear and reproduceable by anyone, quantifiable and verifiable by anyone, can be extended to trade multiple markets and multiple time-frames in the future, consistent and void of human judgement, opinions, emotions and biases (while trading). 

In my opinion, there is not much difference between the two.  In fact, in the early stage of system development process, a lot of discretion or the art portion of trading is involved (that's why I say even system trading is an art).  For example what strategy to use, how do you use it, is it sound, can it stand the test of time, whether to use filters, the parameters to be chosen during optimization, what about stops and exits, the balance between chosing most profitable or most robust systems etc.

The analogy I often use is the process that the pharmaceutical companies go through before the drugs that they design, develop and test become the medicine we take.  Would you take a drug that has not been clinically (scientifically) tested (usually more than 10 years)?  If yes, then it is just like putting real money to trade before a strategy or plan is being formalized or being tested as having an edge (discretionary trading).  It is based more on blind faith and luck alone at first and hope that you won't be financially ruined (some traders gone through a few times) before you gain your trading insight.

After such a long intro, I would start to discuss the things to look for in a performance summary report and what they mean in my future postings.  Then I would start to show you the simple steps in designing, developing, testing, evaluating of trading systems and the detection of possible leakage while doing live trading.  Until then, happy trading and good luck!
        

Thursday, October 8, 2009

SMA 10/50 On S&P 500 Index Futures

As promised, I've backtested the S&P 500 index futures from Jan 1996 until Sep 2009 (continuous front-month daily data) using the simple SMA 10/50 crossover that performed quite well on our FKLI.  It is a stop-and-reverse system trading 1 contract. 

Here's the performance summary:


and here's the equity curve (before cost) chart:


Ouch!  Losing money again!  Although not as bad as the RSI 55/45 or MACD with SMA 20/50 filter that we have tested, but still not good.  From here we can also see how fast the best of the world smell opportunity and how quickly they take advantage of it. 

As more and more people compete against each other to grab the money, the opportunity disappear quickly.  Therefore, a good trading system will eventually degrade and breaks overtime!  If you want to trade in those market and hope to make money long term, you must at least have a strategy to constantly monitor and detect any leaks in your trading rules.  And of course if possible, deploy a self-adaptive system that has some form of artificial intelligence (AI).  If that is too much for you, don't be afraid, I'll show you a more simple way of doing the detection in my future postings.

I hope by now you would at least start to appreciate if you or someone you hire could make a return of 8% annually instead of constantly looking for 100% or even 500% compound annual return over a long period of time that is highly unlikely.  You should have a certain amount of skepticism when someone is trying to sell you a system that has a very high level of return consistantly.

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 7, 2009

MACD With SMA Filter

I've shown in previous post that a simple trend-following system using RSI(14) that perform quite well in FKLI and FCPO but perform miserably on Light Sweet Crude Oil futures and even worst on S&P 500 index futures which represent a more mature market.

To show you how difficult it is to trade in these market especially S&P 500 using a simple trading system that uses common indicators as strategies, I've backtested S&P 500 using our earlier MACD with SMA 20/50 as filter that has performed quite well on FKLI.

That means the system will go Long when the MACD(12,26,9) line crosses above signal line AND the closing price is above SMA 20 (closed). It will turn Short only when the MACD(12,26,9) line crosses below the signal line AND the closing price is below SMA 50(closed).  Backtested period Jan 1996 - Sep 2009 (continuous front-month back-adjusted) daily data with basic 1 contract (stop-and-reverse).

Here's the performance summary:




and the equity curve (before cost) chart:



The system that perform quite well on FKLI done badly on S&P 500 index futures from Jan 1996 - Sep 2009 !  That again shows how tough it is to compete with the best of the world. 

In my next post, I'll backtest one of the best (so far) performer on FKLI which is SMA 10/50 and see if
it can successfully exploit inefficiencies in S&P 500 index futures, if there is any and if it is that easy.  We shall see.


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 6, 2009

World Market - Crude Oil, S&P 500 (More Mature Market)

A quick summary up until now.  So far our simple RSI(14) 55/45 system is profitable on FKLI and FCPO (refer to earlier post).  Both traded on the same exchange which is Bursa Malaysia.

Now, before we order and celebrate with Louis XIII de Rémy Martin Limited Edition, let  me use the same simple strategy (before adding filters and optimization) on two other more mature world product that is very famous, namely S&P 500 Futures (CME) and Light Sweet Crude Oil Futures (Nymex).  One representing equity-based index futures (cash settlement) and the other commodity based futures (physical settlement), both traded in US dollar.  The period selected is Jan1996 - Aug2009 with continuous front-month back-adjusted EOD data.

First, the performance summary report for the crude oil futures:


Not too bad, still profitable, although the standard deviation of return is a bit too high, meaning that the return is quite volatile.  Notice a single largest profit of around USD96K?  If we were to take that away the strategy is not attractive at all.  So, it perform not as good in Light Sweet Crude Oil Futures (compare to FKLI & FCPO).

Now, let us see the result on S&P 500 Futures:


Ouch!  Losing money big time on S&P 500 index futures!  In fact, I can't even backtest with less than USD300K trading just 1 contract!  Furthermore, I didn't even put in the commissions and slippage.  Why is it so?

My hypothesis is that in a more matured and more higher level of competitiveness, you just can't use a simple strategy and hope that it will be sufficient, as there will be less chance of seeing and picking low hanging fruits! 

At this stage if you still insist on using the strategy to trade the FKLI and FCPO only, then you have to constantly monitor your trading performance and be on alert for any market paradigm shift, knowing that the basic strategy  doesn't work on a more mature market.

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.
    

RSI Strategy On FCPO - It Works Again !

Remember the simple trend-following that uses RSI(14) that I've backtested on FKLI and it works?  Guess what, I've backtested the strategy on FCPO(Crude Palm Oil Futures) from Jan 1996 - Sep 2009 (EOD continuous 3rd-month unadjusted data) using basic 1 contract and stop-and-reverse strategy.  

The same logic that uses RSI(14) to catch early trend by going Long when daily RSI value crosses above 55 and trend-follow until turning Short when the daily RSI crosses below 45.  The hypothesis is that in a strong uptrend, the daily RSI(14) will cross above 55 and seldom drop below 45, and the reverse is also true for going Short.  The backtest is done without any stepping optimization and filters, just pure default settings of RSI(14) and arbitrary RSI value of 55-45.  That means the result can be further improved if you are interested in it and think that the logic behind is sound.  Of course you'll have to start performing proper statistical backtest (I will discuss in my future postings) on different products to get a robust system.

Here's the performance summary result:


and here's the equity curve (before cost) chart:



Nothing much to say here except that it is a profitable strategy on FCPO (a very volatile product).  In fact, it perform better (CAGR, Sharpe ratio basis) than the FKLI that we have tested!  It just shows that commodity generally tend to trend more than equity therefore a trend-following strategy will perform better over a long period of time, in this case more than 13 years. 

However, further optimization and improvement will have to be done as the volatility of return (a risk measurement) is relatively huge and the max-close-drawdown-to-starting-capital is too big for most people to stomach (over 50%)!  Notice the largest profit on 1 contract? Over RM46K or 1852 points?  Can you hold your urge to take profit that long?  Or  can you handle the almost 300 point largest loss per contract?  Just make sure you don't have heart attack!  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.
      

Sunday, October 4, 2009

How Much Can We Trust Backtesting?

I believe a lot of readers would be wondering how much can we trust the result of statistical backtesting based on historical data.   I guess a lot of you have definitely came across articles or gurus that equate doing live trading based on backtested result as "driving with rear view mirror" or something similar.

I would like to point out that the analogy is not quite correct.  In live trading, if we have sufficient capital to withstand a few drawdowns, we will survive losing trades.  In fact. there is no way to avoid a few losing trades once in a while.  However, when we drive, we can't afford to make a wrong turn or go straight when the road in front is winding, in fact, we can't really make a single mistake, as that would likely be disastrous!

Having said that, we must also realise the limitations of statistical backtesting as historical data is the only sample that we have and to make an educated guess on the likelihood of repeating patterns of the mass human psychology (market) and we can't be 100% sure that the same will happen again in the future, although a variation of the sample is likely to happen again as long as human has flaws!  I know this is confusing, as we have no choice, but to make a deterministic (same input, same output) conclusion (trading system) by just studying a sample (historical data) from hundreds of thousands of possible variations of the future!

To make the matter worst, the process of doing backtesting is susceptible to a lot of human biases, assumptions and errors such as worng historical record, selecting a bull or bear only cycle (period too short or sample size too small), curve-fitting the strategy to match data, wrong programmming or calculations etc.  One of the most dangerous example is hindsight bias (giving advice such as buy high sell low, or quickly take profit when market is ranging) and seeing one occurance and start assuming that the secret has been found! 

Remember, we can't prove that a hypothesis is correct, all we can do is repeating the process of trying to prove it wrong so that after thousands or millions of tests, we can have a degree of confidence in our model's successfulness in describing the pattern that it tries to capture.  The hypothesis just remains as the best solution so far.  We only need one observation that our model does not correctly describing the pattern to fix it or throw it away (such as failing an out-of-sample test)!  Just think of this as innocent until proven guilty.  If no one can prove you guilty, you remain innocent so far, it doesn't mean that you are really innocent!

On top of that, we need to do a stress test of the trading system using out-sample data and simulations on the variations of the result.  At the moment, one way of testing the trading system's result is to generate random sample data of the future via Monte Carlo Simulation which by itself is not perfect as certain assumptions about the pattern of distribution of the future data (possible data points of the results) has to be made, for example, a normal distribution, which may or may not be representing the real future data as the future is always unknown.  Besides, how many retail speculators or even the so call gurus know how to design and build their own Monte Carlo Simulator or even do and interpret the result from a commercial progam not to mention it usually is quite expensive.  Furthermore, can you really trust the simulation results?  Is there any correlation between the random inputs generated by the random number generator?

If I have scared you already, please don't be.  There are at least hundreds of ways we could have been knocked down by a car when we cross the roads but we still do it, why?  Simple, once we really understand what we are doing and are in control, we would have the courage to take the risk already, in fact, it has become second nature for us to take calculated risks in our everyday life without we second guessing them! 

Just always respect the market and have faith that humans will always have flaws!  I will try to explain how to design and evaluate robust trading systems for normal people like you and me in my future postings.  For now, good luck and happy trading!
     

Friday, October 2, 2009

Trading Strategies - The Problem and Solution

Please bear in mind that when I posted the performance summary report that showed losing money on a common use of RSI(14) counter-trend strategy backtested on FKLI, it doesn't mean that RSI as a counter-trend generally or the strategy spesifically cannot be used at all.  It may be possible to achieve a robust and working system by combining the strategy with some static or dynamic Stops as well as Exits.  You just have to test each hypothesis.

What I wish to point out here is that although trading is very simple; just Entries and Exits only, it is not easy to implement a long-term profitable trading strategy whether the strategy is discretionary or systematic.

Why is it so?  In my opinion, trading is just like the nature, a balancing act between two different forces and there is no such things as definite right or wrong.  You may be thinking of winning trades and losing trades but you are missing the bigger picture, winning and losing trades are just the result of our trading strategy which is in turn, the reflection of our internal believe system and wisdom. 

The right starting point to the solution is to realise that Entries and Exits represent the two different opposite sides of human nature.  If you are of the type that seeks instant gratifications or pleasures (majority of us) then you will most likely prefer to go Short when the market goes higher and higher or buy when the market kept dropping lower and lower as that is common instinct.  We are merely reacting to our basic needs.  If you analyse closely, this is just counter-trend Entry!  Where is the Exit?  How do you do it?  Most people have no clue.

As I've said before, counter-trend Entry is just one side of ourself that seeks instant pleasure, it usually is easy, we just do it.  If that is the case, the other oppsosite side would represent the one that is most difficult or challenging to us (remember two opposite forces), the Exit.  In counter-trend trading, it is counter logic to exit with a loss when after you have Shorted, the market goes higher and higher, as the price is even more attractive to add Shorts than to buy and cut your losing positions!  The reverse is also true for Longs.  When the market goes lower and lower, human nature is such that it is even cheaper to buy more, rather than to cut the Longs by going counter logic which is Sell to cut loss!  If most products are trending(over long-term), then you will have a problem with your Exit strategy.  You can't afford to win small(5 points) 4 times and lose big(25 points) merely 1 time consistantly!  You would have negative expectancy in your trading strategy, hoping will never change your odds.

That is the reason why trading is simple, but not easy.  And that is also why most successful traders (<5%) tend to be trend-follower as solving and implementing counter-trend exits(when most products tend to trend) represent a more difficult challenge than choosing trend-following which is counter logic and harder on Entry (buy when price goes higher) but relatively easier on the Exit as taking profit when the price goes even higher when we go Long or goes lower after we have Shorted (this generalization although is dangerous, but is true as long as most product tend to trend).  Furthermore, the logic for Exit is consistant with the logic for Entry in trend-following systems!

That's why most people choose the easier way to start, which is to Sell when they see market goes higher and higher or to Buy when the market drops lower and lower, which by itself is not the problem, but have no clue about how to Exit when the price goes against them and that is the biggest problem.  Who in the right mind would counter their own logic of Entry and willingly buy when the price goes higher after they have shorted? 

The conflict of logic between Entry and Exit in addition of no Exit plans at times caught them off-guard and delay the cutting loss process, especially when market move fast against them.  At the end they tend to close the positions unwillingly (always a sign of problem)!  And the cycle repeats again.  That's why not many people can implement trend-following strategy which is more difficult to start a trade.  It is human nature to give up too easily or listen to so call "expert"'s advice as they don't have to learn and bear the painful responsibility of admitting that their decisions were wrong.

Personally, the right Exit in trend-following strategy is even harder as one needs to withhold the temptations to take profits early.  That is however, entirely different topic.

Please bear in mind that the relationship between Entries and Exits in counter-trend and trend-following would have changed side if suddenly most products starts ranging all the time.  The Exit for counter-trend would become easy as taking profit to exit Shorts by buying when the market drop and selling to take profit when the market goes higher seems in sync with our instinct and logic! 

Until that day arrives, we'll need wisdom to defer our instant pleasure-seeking nature, the need to be validated by others, the need to prove that we are correct all the time(therefore focussing on short-term result) and go Trend-Following, although not easy, but easier than finding a good exit solution for counter-trend trading strategies that consistantly work and has a good risk-to-reward ratio in a trending environment.  At the same time, you must remain sensitive to market paradigm shift and if needed to, change your approach accordingly to match the ever changing environment.   Good luck and Happy trading!
     
       

Thursday, October 1, 2009

Trading Systems - RSI Strategy That Works

Finally, after a few simple testings, I've managed to use RSI as a simple trend-following strategy and it works(on FKLI).  In fact the logic behind it is sound as well, although the backtested result has a profit factor of 2, it is not as impressive compared to other strategies which I have yet to post. 

The idea is that when a market is in a strong uptrend, the daily RSI(14) value will  go above 55, and seldom drop below 45 when retrace downward and when the market is in a strong downtrend, the RSI(14) value  crosses below 45 and seldom reach 55 in upward retracements.

Therefore we could design a system that go Long when the RSI(14) rise above 55 and turn Short when the RSI(14) penetrates below 45.  Lets backtest the idea with Bursa FKLI from Jan 1996 - Sep 2009(continuous front-month EOD data without adjustments) with basic 1 contract.

Here's the performance summary report:


and here's the equity curve (before cost) chart:



*(please note that we have break-even trades here)

In fact, considering that the trading system uses only RSI(14) indicator with default settings and without any complex optimization, the performance is the best so far comparing to those that I've posted such as EMA(3/7), EMA(3/30),MACD without filter, Bollinger Bands and the BBZ system.  It only lost to SMA(10/50) which is the simplest !  The next question is, does it work on FCPO?  What do you think?

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.