Monday, June 8, 2009


TESTING TRADING SYSTEM USING MONTE CARLO SIMULATIONS




Last year we had an article about building a trading system. We designed a simple moving average crossover system where we did some basic backtesting. We will now start a series of articles covering Monte Carlo testing of trading systems to help us further support our trading system testing. Today we will take a closer look at the trading system we designed earlier and do a basic Monte Carlo analysis to see if our decision about not trading the system in real time was correct or not. Later we might also look at how we could improve the system further by looking av walk forward analysis and optimization. The software we use for the Monte Carlo analysis is "Zen Monte Carlo Simulator V5.01e" made by Volker Butzlaff.


Fig.1. OSEBX and equity curve along with buy- and sell- arrows. A green buy arrow occurs when there is a 5 day- and a 25 day- moving average crossover and vice verse when there is a red sell arrow.

Here we can see the OSEBX chart and an equity curve of how the system performs with the buy and sell signals. Starting capital for this single backtest was 100000 NOK. From the chart we can immediately see that the system performs quite well this is partly because the test data is mostly trending. Where the market is moving sideways we see that the system performs poorer. But again it looks not too bad.


                          Fig.2. Backtesting results of the MA Crossover trading system.

The backtesting results that you can see in the figure shows that 34 trades was executed where 16 were winners while 18 were losers. Average profit for the winners were 27292.32 NOK while average loss for the losers were -12456.37 NOK. Max drawdown was -129035.42  NOK (there should ring a bell already here about this trading system). The backtesting data is then fed into "Zen Monte Carlo" for further analysis (Fig.3).



Fig.3. Input data window for Zen Monte Carlo Simulator.


This gives us a trade ratio (TR) of 47% (47% winners), Payoff ratio (PR) of 2.19 (119% higher average win than loss) and finally a Profitability index (PX) of 1.95 (higher number the better and good indication when comparing scenarios and different trading systems).The other numbers put in here is dealing with units, the simulation period and number of simulations to be run (our test period will be run 100000 times. Running the simulation we get our results (Fig.4).



Fig.4. Monte Carlo simulation results.


So what do this tell us? Minimum profit for a year is -37789 NOK, maximum profit for a year is 98492 NOK while average profit for a year is 30388 NOK (remember that we start out with an equity of 100000 NOK). This might not look too bad at a first glance but we also need to take a closer look at the risk of the system. Minimum drawdown for a year is 27292 NOK, maximum drawdown is -264522 NOK(!!!!) and average drawdown is -16185 NOK. We can already say that this trading system is way too risky to trade. If we are really unlucky we would need a trading account of (margin (100000 NOK) + max drawdown (264522 NOK)) 364522 NOK to lose possible -37789 NOK (worst case) in a single year. In our opinion this is a very good reason not to trade this system. This is also confirmed by the ACR and WCR ratios. The results from our simulation can also be viewed graphically (Fig.5).



           Fig.5. Graphical display of Monte Carlo simulation.


How do the results from the Monte Carlo simulation coincide with the backtesting results?
Average yearly profit from backtesting showed a result of (212462.46 / 7 (net profit/years backtested) 30351.77 NOK compared to the Monte Carlo simulated profit of 30388 NOK. The biggest difference between the backtesting and the Monte Carlo simulation do we see by looking at the max drawdown. Bactesting suggested a max system drawdown of -129035.42 NOK while the Monte Carlo simulation showed max drawdown of -264522 NOK (Fig.4 & Fig.6).



                                  Fig.6. Drawdown results from backtesting.


Later we will see if we can improve the system by optimizing the parameters in use and possibly also modify the trading system. We will also look into how the system perform under different market settings by running Monte Carlo simulations on synthetic simulated data. If you have any comments, suggestions or questions please contact us at (contact@stocktradersbulletin.com). We are happy to receive suggestions for improving the trading system.

If you would like to check out the Monte Carlo simulation software used you can find it here:
http://www.zentrader.de

Happy trading!

SB


comments (0)


Tuesday, May 19, 2009


S&P500 THE PAST AND THE PRESENT




We here at Stocktradersbulletin.com has taken a closer look at the S&P 500 to see if we can find any indications of what could come the next years. We build this analysis on daily data dating back to 1970 up until now. By looking at the market in such a big scale easily overlooked signals in our typical day- bar display can be identified. Therefore let us now take a closer look at some of the immediate things we see. Important support and resistance levels are easily identified. The 380 level played a major role throughout whole of 1991 (please note that the use of the word "level" in this article do not mean the spesific number but more a range around that specific number). The 630 level was important part of 1996 but now the more interesting levels come into play. In 1997 the 806 level was broken and must be seen on as very important. In 2002-2003 this level was about to be tested again. S&P 500 ricochet of the level and this was the beginning of our last big rising wave that ended more or less in 2007. The interesting thing is that the level was "active" again end of last year - beginning this year. The level failed for a short period of time but the resent positive market development we have seen S&P 500 is now well above 806 again. Before going any further with this level we need to look at the higher levels also. If we see S&P 500 break out from the 982 level it must be regarded as very positive. 982 could be the first major test for S&P 500 to see if the market will rise of fall again in the time to come. 1200 is not that important level at the moment so we jump straight to the 1550 level. 1550 was first tested in 2000, in 2007 the level was tested again. As we see both times it failed and there was a pullback to 806. This brings us back to the important 806 level. We clearly see a double top formation developed. As we all know a double top is a reversal formation where the distance from 806 to 1550 (744) is the potential for the pullback. This is of course just the general idea about double tops and we should be careful to use that as hard fact. Another possibility is that we see S&P 500 rising above 982, reaching 1550, pulling back to 806 forming a triple top. These formations are also relatively common but for now it is too early to say if this is very realistic or not. If we choose to be optimistic we can see that today's situation looks quite similar to what we could see end of 2002 meaning that the market is just about to start on a new rising wave.





RSI
Looking at the RSI chart we see that the low values seen the last few months has not been seen many times since 1970. 2002 and 1974 with 1974 showing the lowest value is what we can find. What is also showing well is divergences between RSI and S&P 500. E.g. we see an RSI top in 1995 bottoming in 2002 while S&P 500 is still rising topping early 2000 before turning downwards. RSI do not give us many indications of where we are heading right now but what we can say is that the market has been/ is  what we call "oversold". The RSI values are not down at 30 (typical value indicating oversold) this is mainly due to the use of 200 day RSI and not the typical 14 day RSI setting. Therefore do not pay too much attention to the actual RSI value seen here but do pay more attention to the historical RSI tops and bottoms seen in the chart. If we agree that the market is now oversold then we could be facing a new positive development and if we choose we could agree that RSI is about to leave the low for now.  

ADX
Looking at +DI and -DI we can identify some interesting patterns. When +Di and -DI are "dancing" the market are moving more or less healthy. What we seen today is that ADX is quite high while +Di and -DI are separated quite a bit. +Di and -DI seems to be moving towards each other again meaning we are moving towards a more healthy market but it could still take some time before we are on safe ground.

Smaller scale
If we take a closer look at the movement seen from last top up until now we also find various important support and resistance levels in addition to those talked about earlier. The main extra ones are 881, 1121 and 1381. 881 has already been broken but where the first real test will be at 982. If 982 is broken we could see a much more healthy market development the time to come but for now what we can say is that it still looks quite risky but where we also see clear improvements.






To sum up what can be seen on a larger scale is that the market looks more positive than i a long time. RSI is indicating an oversold market but we need to remember that a market can remain oversold for some time before it rises again. On this scale though it seems that the RSI lows are present at relatively short time intervals. +DI and -DI is indicating that the market is improving but the danger is not yet over. The risk is still quite high. If the 982 level is broken we could probably say that we are on a much safer ground.

comments (0)


Tuesday, October 28, 2008


MOVING AVERAGE AND A BASIC MOVING AVERAGE TRADING SYSTEM




Moving average, what it is, how it is calculated, how you can use it and its limitations


Here at www.stocktradersbulletin.com we will from time to time take a closer look at some of the tools that is being used when doing technical analysis of stocks. We will start by looking at something called moving average.

Moving average is a term that is often being used when there is talk about stock- and forex- trading, but what exactly is it and how can you use it if you do your own analysis? You probably know how to calculate the average of a pool of numbers but let us start with the basics.



Average- and moving average- calculation

When you have a series of numbers and you for some reason want the average of those numbers you simply add all those numbers and divide the sum by how many numbers you have. E.g. you have these five numbers: 8, 9, 10, 8 and 10. The sum of these numbers is 45. Divide 45 by 5 and you get an average of 9.

If the five numbers listed above were price data for company ZZZ we could say that last five days average price for ZZZ is 9. Next day we read on the net that ZZZ closed at 13. If we were to calculate the new five day’s average it would become:

13 + 10 + 8 + 10 + 9 = 50 and five day average will now become 50 / 5 = 10 (Fig. 1). What we have done here is to “move” the five day period one step forward by including the latest close and excluding the now sixth day close thereby creating what we call a moving average. This procedure is repeated for every new day so that we will get a series of moving average numbers that we can plot as a line in our charts.



Fig. 1. Five day average calculation.





Plotting moving average

When doing technical analysis we analyze charts where price and other data are plotted. To be able to get something useful from moving average we should plot the data in our charts together with the price curve (Fig. 2). In figure 2 you see price data plotted along price and volume (light blue bars). On top of the price bars we have plotted a five day moving average as a dark blue line. Taking a closer look at this line we see that it is smoother than the actual price movement. If we were to plot a longer moving average using e.g. 50 days moving average we would see an even much more smoothed curve as the value plotted for a specific day is the average of the number of days we have used in the calculation for the moving average.




Fig. 2. Plotting of a five day moving average. The blue line seen in this chart is the five day moving average of the price for this stock.






Types of moving average

The moving average we have talked about in this article so far is what we call a simple moving average. There are many other types of moving averages as well but the most common one beside simple moving average is exponential moving average. When applying exponential moving average, last days values are being weighted thereby making last days movements “more important”. The result of this is that the graph will react quicker to the price changes that occur. In Figure 3 we have plotted two moving averages. The blue line is a 20 day simple moving average and the green line is a 20 day exponential moving average. It is easy to see that there is a difference between the two lines. Even though it is the same number of days that is being used in the calculation of the moving averages we see that the green line (exponential moving average) is following the price development a bit more closely than the more smoothed blue line.

We earlier said that we plot moving average along with price data, but it is also important to remember that moving averages can be applied on all kinds of data and not just on price data. Other examples could be moving average of volume and relative strength index to mention a few.




Fig. 3. Plotting of 20 days simple moving average (blue line) and 20 days exponential moving average (green line). We see that the green line react more to the price changes that occur than the blue line.






A basic moving average trading system

To see how a moving average trading system could be used we will now design a very basic moving average trading system consisting of two moving averages. The coding and plotting of data shown here is done in a software called Amibroker (www.amibroker.com) which is a technical analysis software where you can plot data, program trading systems, optimize- and test- your own trading ideas.


In this example we will use a short 5 day simple moving average and a medium long 25 day simple moving average to form the framework for our trading system. What we want to do next is to design our trading system to buy the stock when the 5 day moving average crosses above the 25 day moving average and sell when the 5 day moving average crosses below the 25 day moving average. The coding done to make this system is seen in figure 4.




Fig. 4. Amibroker code for the moving average trading system.





When we plot these two moving averages we see why we want to buy the stock when 5 day moving average crosses above the 25 day moving average and sell when the opposite occur. Basically what we want is to be on the “right” side as the stock price moves upwards or downwards (Fig. 5).





Fig. 5. We want to own stocks in this company when the blue line is higher than the green line, and sell (or short) the stock when the blue line falls below the green line. The light blue bars seen in the lower part of the chart is the trading volume for the different days.






From the plot it looks like this system is quite promising with regard to being profitable but to make sure that it is actually profitable we need to do some more testing. What we want is a trading system that will perform well over time and in all kinds of market situations. Although the trading system seems promising at a first glance the testing of this system shows something else. As seen from the test report produced by Amibroker the system performance was rather poor over the test period from mid June 2004 to mid June 2008. With a win percent of 33.3 this is probably a trading system that we should leave and not trade as is today. Although the trading system does not perform as wanted the overall idea for the system might still be something to build further upon (Fig. 6).




Fig. 6. Profit distribution for our trading system. We see that we have a few nice returns of investment here but when we just have a few winners we choose not to go further with this system. What we want is a much more even profit distribution that could be e.g. 20 winners in the 5% to 10% range rather than one winner of 100%. Only then can we say that we have a more robust trading system.




It has to be said that the testing done here is very simple and www.stocktradersbulletin.com will look deeper into testing of trading systems in an article at a later stage. Also it should be noted that the testing here was done on one stock which is not a good enough foundation for validating trading systems.



Conclusion

Moving average is a tool that could be used in a meaningful way if it is applied correctly.

From our analysis in the previous section we can say that using moving average alone for your trading will probably not give you the profit you would like to see in the long run. You will simply see too many false signals for when to buy and sell. To minimize the false signals you should use moving average in conjunction with other technical analysis tools. What tools and how you want to do that is entirely up to you but what you should remember to do if you have the chance is to test, test and test your system and make sure that you are not just seeing wishful things before you go ahead and do actual trading with real money.



Final note

What you have read here is just one method of how you could use a moving average. As we have seen the method presented in this article is not a very profitable one but the intention here is to give you some information about moving average and possibly also give you some inspiration from where you can continue with your own ideas and development of trading systems. For more information about trading systems please read our article “Building a trading system” found in our article section at www.stocktradersbulletin.com.




comments (0)


Saturday, October 4, 2008


BUILDING A TRADING SYSTEM




Have you ever wanted to make your own trading system? If so there are certain "rules" that you should follow when doing so. Here at http://stocktradersbulletin.com we will take a closer look at trading systems, how to make them and how to do proper testing of them. We will also take a look at various trading systems and see if they live up to expectations. Later we will also go in more detail about specific technical indicators. If you have any requests or suggestions let us know by contacting us. But first let us take a look at the fundamental parts of building a trading system.

Building a trading system
T
here is much to be said about technical analysis, what indicators to use and how to use them. In this article we will look at some indicators and how they can be combined to form a system that we can base our buy and sell actions upon.

Indicators can be divided into several categories like momentum, volume or trend as the most commonly used ones. The indicators we will focus on and use here are all from one of these categories.

If we take a look at www.stocktradersbulletin.com the analysis carried out there are usually based upon three (four) charts/indicators,

  • Price

  • (Volume, included in the price chart)

  • ADX

  • RSI


Before we take this any further we will now look at these charts/indicators individually.

Price
T
he price chart can be displayed in many ways with candlesticks and line chart probably being the most common ways. To complicate it further we can choose to plot the data logarithmic or linear. What you choose comes down to personal preferences but I would recommend using a logarithmic candlestick way of displaying the bars. The price chart basically tells us how the stock price is moving whether rising, falling or moving sideways. Candlesticks are also a nice way of displaying the data as you can recognize chart patterns. But we will not cover that in this article.

Price chart using candlesticks.


Volume
T
here are many volume indicators available for us to use but here we will look at the actual volume i.e. how many stocks have been traded throughout a day. Generally we speak of volume as a positive signal when the stock price is rising and volume is increasing, and a negative signal when the stock price is falling while volume is increasing. We can often see an increase in volume when the stock price is reaching support and resistance levels. We also often see a slowdown in volume as a price trend is coming to an end. If a stock has been in a nice upward moving trend with a general increasing volume and then all of a sudden the volume starts to decline this usually signals that the trend is coming to an end.

From this chart we clearly see that the volume is generally increasing while the stock price is falling. This is a negative signal and further fall in price can be expected.


ADX
D
irectional Movement indicator is a trend indicator developed by Wells Wilder. The indicator is usually plotted as three components

  • ADX

  • +DI

  • -DI

Basically what this indicator tells us is if a stock is trending or trading (moving sideways). The ADX line (blue line in the chart below) gives us the value of the indicator and as a general rule of thumb says that a reading of 25 and above indicates that the stock is trending, while a value lower than 25 indicates that the stock is trading. If you have a look at the chart you also see two more lines. The green line +DI and red line –DI tells us if the trend is negative or positive. When +DI is above –DI and ADX is showing values above 25 the stock is in a positive trend. When –DI is above +DI and ADX are showing values above 25 the stock is in a negative trend.


RSI
R
elative Strength Index is a momentum indicator developed by Wells Wilder.
This indicator is what we call an oscillator where the values oscillate between 0 and 100 but usually between 15 and 85. RSI measures the stocks own strength based upon previous
readings. It is most common to let RSI be based upon the last 14 day’s readings. As RSI is an oscillator we can use it as a measure to see if the stock is oversold or overbought. This means that if the stock has experienced a selling pressure lately RSI values falls leaving the stock to enter the oversold area. Oversold levels are usually defined as RSI values lower than 30 while overbought is usually defined as RSI values over 70. Some might also say that when the value crosses the 50 level upwards this is a good signal indicating strengthening in the stock.


Putting it all together
It is when we combine the information we get from the different indicators we really get the most out of technical analysis.

Divergence
When we recognize divergence between different indicators or indicators and price it is usually a strong signal that we should pay attention to. From the set of indicators we have in our setup here the most common divergence to look for is between price movement and RSI. If we see a falling trend in price but a rising trend for RSI values over the same time interval we have detected a divergence. A divergence like this could signal that the falling price trend is coming to an end and the stock price could start rising again. If the price trend is upward while the RSI trend is falling this usually signals a coming fall in price.

Here we see a divergence between price trend and
RSI trend. As expected it turned out that the falling
price trend was coming to an end and a rise in stock
price occured.


Trend or Trading
When you use oscillators like RSI you should also use an indicator telling you if the stock price is trading (moving sideways) or trending. Here we use ADX as our “Trend or Trading” telling indicator. When ADX tells us the stock is trading the actual RSI value becomes more reliable and valid. Oscillator indicators like RSI perform better when a stock is in a trading range. When we use RSI, its value is 20 and ADX tells us the stock is in a trading range we have much more confidence to say that the stock is now oversold and we could get a rise in price soon. If on the
other hand a stock is in a strong upward trend and RSI value is 80, this do not necessarily mean that the stock is overbought. When a stock is trending the RSI values become “exaggerated” in the direction of the trend. As you can see from this it is very important to combine indicators and not just analyze a stock based upon one indicator.


Trendlines, support and resistance
As in this article you have probably heard the words trendline, support, resistance and trend channel when someone talks about technical analysis. Basically this is not more than lines drawn at the charts. These lines are used as aid in predicting where future movement for indicators and price will be. There are many ways in drawing these lines but we will not focus on that in this article. The easiest way is just to go ahead and try for your self. The more you do it the better you get at it. Here you see an examples of how you could draw some trendlines (green and brown lines), trend channels (red lines) and support- (green line) and resistance- (brown) lines.


A few words on money management
Money management is a large subject in its self but before we do any trading we need to have at least some idée about money management. Money management is like trading with a security guard telling you when to get out of the shop when they close. If you do not get out in time you can be in great trouble. The most important thing you need to remember when it comes to money management is STOP LOSS. Before you even buy a stock decide what your stop loss level is i.e. when to sell the stock. This will define your risk level and can vary from person to person. But never risk more money than you can afford to loose.

There are many ways of how and where to set your stop loss limit depending upon personality and money available. Trend lines, support and resistance levels are all good methods of where to set your stop loss. Indicators can also be of great help. Experiment and find your way of doing it but do not skip it – Stop loss is very important.

Final note
W
hat is described in this article is just one way of using technical analysis.

I strongly suggest that you play around yourself and find a set of indicators that you feel comfortable with. Just remember a few points when you do so

  • Select a set of 3 – 5 indicators for your setup

  • Use indicators that tells the “story” differently from each other i.e. choose 1 – 2 indicators from the different indicator categories

  • Learn those indicators inn and out, the more you know your setup the better understanding you have for how to make money from it

  • Make your setup personal, one person’s setup might not be the correct one for another person as this varies due to risk, personal behavior etc.

For many more analysis of actual stocks please go to www.stocktradersbulletin.com


Disclaimer
The author of this article hereby disclaim all responsibility of any profit or loss people might have based upon this article.

www.stocktradersbulletin.com

comments (0)



1 - 4 of 4

RSS  


Articles


Stocktraders Bulletin take a closer look at trading strategies, trading systems, the market in general and other relevant topics



TAGS




RECENT POSTS



Testing trading system using Monte Carlo simulations 


S&P500 the past and the present 


Moving average and a basic moving average trading system 


Building a trading system 




ARCHIVE



june 2009


may 2009


october 2008





TOPICS



TRADING SYSTEMS (3)


TRADING STRATEGIES (0)


MARKET COMMENTS (0)


OTHER (0)


MARKET OVERVIEW (1)



admin*









Today's chess puzzle