The post Seasonal Strategies Built The Right Way appeared first on System Trader Success.

]]>Many commodities, and even some individual stocks or stock groups, have recurring fundamental factors that affect their prices. These forcescan be seen by analyzing a market by day of week, day of month, or day of year. This is called seasonal trading.

Almost everyone who did seasonal analysis back in the 1990’s made a big mistake. That is, you can’t use backtest results which include the period used to discover the seasonal patterns and expect good real-world results.

The problem with this type of seasonal study is the assumptions that needs to be made in the analysis. Say a market rises in price in the selected time frame in 21 of the 23 years from 1980 through 2002. Would a trader have known to make these seasonal trades based on the information that he or she had at the time when a trade would have been made?

For example in 1985, five years into the carefully selected period, would you know the market had appreciated during this particular time frame in just six of the 10 years from 1975 through 1984? Few traders would have taken the trade then, although in the original analysis 1985 may have been the most profitable year. Even assuming that the same trades would have been made, using a static seasonal relationship in a walk-forward simulation is a flawed approach. The proper way to study seasonality is a pure walk-forward dynamic seasonal.

It is necessary to use either all the previous years or a window of previous years to trade the current year and then to shift the window forward. It is also important to use the same rules for defining all seasonal periods and making all trading decisions across all markets.

One approach to seasonal analysis focuses on creating a predictive seasonal. For example, when looking at the 20th trading day of the year and trying to create a five-day price prediction, it would involve taking the difference between the 24th trading day of the year and the 20th. In this way, a seasonal based on how prices will move over the next n days is created. The key is that we only use data through the previous year to calculate the seasonal for this year and we walk it forward. Most seasonal references talk about performance during an in-sample period. This approach is not statistically valid. The only way to do a seasonal that can be used in trading is to develop a rolling window seasonal that holds up walking forward. Seasonality does evolve over time. You might ask why that would happen? Well, for example, corn, was strongly corollated with a seasonal based on the US market, but over time we had two seasonal signals overlaying each other, one from the US market and the other from Argentina, which is the other big corn producer.

Some seasonal calculation methods use raw prices and average the price for each seasonal period, for example daily, weekly or monthly. These types of seasonal calculations require individual contracts or calculations from cash prices. Using the price differences between days allows the calculation of seasonal tendencies from back-adjusted contracts.

We could use average returns for this type of predictive seasonal difference.

The problem is this type of simple classic seasonal can be distorted by a large move on one day. During the mid-1990’s, the solution came to me; use the percentage the market rises or falls to develop seasonal trades. However, you still have the problem of normalizing the seasonal so that it can be traded using the same relative numbers across all markets.

This concept became the seasonal indicator called the Ruggiero/Barna Seasonal Index that integrated both of these factors.

The Ruggiero/Barna Seasonal Index was developed by myself and Michael Barna.

I would like to make one point about the RuggierolBarna Seasonal Index: It is calculated rolling forward. This means that all resulting trades are not based on hindsight. Past data are used only to calculate the sea-sonal index for tomorrow’s trading. This allows development of a more re- alistic historical backtest on a seasonal trading strategy.

The Ruggiero/Barna Seasonal Index is calculated as follows:

- Develop your seasonal and update it as you walk forward in your data.
- For each trading day of the year, record the next n-day returns and the percentage of time the market moved up or down.
- Multiply this n-day return by the proper percentage.
- Scale the numbers calculated in step 3 between -1.00 and 1.00 over the trading year. An output of 1.00 means the market will be the most bullish of the year over the next five days and an output of -1.00 is the most bearish.

The Ruggiero Barna Seasonal is so powerful it can be used as a system all by itself. Look at these results for coffee. Using an 8-year lookback to calculate a walk forward seasonal the Ruggiero/Barna Seasonal produced the following amazing results, no slippage, and commissions deducted since we wanted to look at the seasonal bias. First trade in 2002, 15 years ago.

Let’s look at the yearly breakdown for Coffee using the Ruggiero/Barna Seasonal Index.

Now let’s look at the equity curve for this system.

This approach works across many markets. Remember, this is a true walk-forward analysis!

The only way to develop seasonal-based strategies that can reliability help you trade is using walk-forward seasonality -- that is, identifying the seasonal bias using historical data only and rolling this forward to generate results. Even well-known seasonal companies make the mistake of showing results on in-sample data, and they charge a lot of money for their flawed approach.

The Ruggiero/Barna Seasonal let's you uncover seasonal patterns for any market, and has been traded for over 20 years. It has continued to hold up and produce amazing results over that time.

In 1996, I released my first version of the Universal Seasonal for TradeStation. This was one of my most popular products. This product had open code but the engine of it was done in C DLL This meant that when TradeStation changed the API, this product needed to be totally reworked.

Now, 21 years later, I have redone this product and it now in ** 100% easy language and will work in both TradeStation and Multi-charts**. The key to the universal seasonal is that it uses a walk-forward methodology.

It's called Universal Seasonal. You can get your copy below!

Universal Seasonal has all you need to develop your own seasonal strategies and includes the Ruggiero/Barna seasonal index strategy, developed over 20 years ago based on walk forward analysis and still works today on a wide basket of markets.

If you're interested in creating seasonality based trading systems, Universal Seasonal is a must-have.

-- Murray Ruggiero

The post Seasonal Strategies Built The Right Way appeared first on System Trader Success.

]]>The post Using Metals to Trade Bonds appeared first on System Trader Success.

]]>Sometimes things in the financial markets are pretty obvious if one is willing to see them. Despite all of the angst that has been exhausted since July of 2016 – when the S&P 500 Index broke out to a new all-time high – regarding the 2016 election, the economy, interest rates and the “ultimate” effect that all of it may have the stock market – the market has just kept chugging higher. This is not to say that everything can’t reverse and quickly, it is simply to note that people tend to spend a lot of time looking at stuff that seems “obviously important” and end up getting led astray anyway.

Now imagine the stuff that happens under the surface that they miss completely. Like for example, the fact that the ratio between the price of gold and the price of copper is useful in identifying the trend in interest rates.

No, seriously.

**Gold/Copper Ratio versus 10-Yr Treasury Yields**

***The blue line** in Figure 1 below displays the ratio of the price of gold divided by the price of copper since 1982.

***The red line** displays ticker TNX – an index that tracks the yield on 10-yr. treasury bonds.

Notice anything about these two lines?

The phrase that we “quantitative analyst types” use for this type of relationship is “inversely correlated”. According to my version of Excel the correlation between these two lines is -0.79. For reference, a reading of +1.00 means perfectly correlated and a reading of -1.00 means perfectly inversely correlated.

In plain English this simply means that your eyes are not deceiving you and that yes, there is a strong inverse correction between the gold/copper ratio and 10-yr. treasury yields.

OK, so this is all very interesting, but let’s get down to it. Is there a way to profit from this? Well, it appears so. Follow my logic (such as it is):

a) Bonds prices move inversely to yields (i.e., as yields rise bonds prices fall and vice versa).

b) Therefore, if the gold/copper ratio is inversely correlated to 10-yr. yields then the gold/copper ratio should be highly correlated to 10-yr. bond **prices**.

c) Therefore a rising gold/copper ratio should (in theory) be accompanied by rising 10-yr. bond prices and vice versa.

If this does not make sense, just do what I do: look at the pictures below.

(See also **It’s Soon or Never for Bonds**)

**Using Gold/Copper to Trade Bonds**

Before I launch into this, my compliance people are threatening to taser me again if I fail to mention the following: What follows is not a “trading system” that guarantees profits, nor am I recommending that anyone use the method described next to trade. It is strictly a “though experiment” designed to enlighten people that there are a lot of ways to “play this game” we call trading.

Alright with all of that firmly in mind (and with all weapons reholstered) here goes.

A = Gold price divided by Copper price

B = 30-day simple moving average of A

C = 80-day simple moving moving average of A

D = (B – C);

In other words Variable D represents the 30-day moving average of the gold/copper ratio minus the 80-day moving average of the gold/copper ratio.

Figure 2 displays the value for variable D above – i.e., the 30-day MA minus the 80-day MA.

Simply note that:

a) This value fluctuates above and below 0

b) Our underlying theory is that **positive values for D should be bullish for bond prices** and ** negative values for D should be bearish for bond prices**

Now let’s test the theory.

**Trading Rules:**

*Use a 1-day lag (i.e., a “buy signal” or “sell signal” issued at the close one day is acted upon at the close of trading on the next trading day).

*If Variable D is greater than or equal to 0 then hold 10-year treasury bonds

*If Variable D is less than 0 then DO NOT hold the 10-year treasury bond (an aggressive trader could consider a short position in 10-year treasury bonds)

For testing purposes we use the daily dollar value change for the nearest 10-year treasury bond futures contract traded at the CBOT (stock based traders can consider shares of the ETF ticker IEF that tracks the 10-year bond).

Figure 3 displays the growth of equity achieved by holding a long position in 10-year treasury futures depending on whether the gold/copper ratio (using the 30-day/80-day averages mentioned above) is positive (blue line) or negative (red line).

(See also **January Barometer Flashes a ‘Buy’. Now What?**)

For the record:

*From May 1982 into early May 2017 a long position in 10-year futures when the 30-day MA for gold/copper was above the 80-day MA generated a gain of $98,275.

*By contract a long position in 10-year futures when the 30-day MA for gold/copper was below the 80-day MA generated a loss of -$35,501.

*No allowances are included in these numbers for slippage or commissions. The purpose is simply to highlight the stark difference in 10-year bond performance during periods when this “system” is bullish versus bearish.

**Summary**

So is this the “be all, end all” of bond trading methods? Not at all. How future results might play out if and when we eventually transition into **a bona fide “rising rate environment”** is essentially impossible to know.

But the inverse nature of the relationship of gold/copper versus 10-year yield has persisted strongly for over 30 years, so it may prove to be a very useful tool going forward.

In any event, the real purpose of this piece is to remind you to not always stare at the “shiny object” that the financial price holds up each day, and to recognize the need to – and advantage of – looking at things in unique ways.

**Ja****y Kaeppel**

**Disclaimer:** The data presented herein were obtained from various third-party sources. While I believe the data to be reliable, no representation is made as to, and no responsibility, warranty or liability is accepted for the accuracy or completeness of such information. The information, opinions and ideas expressed herein are for informational and educational purposes only and do not constitute and should not be construed as investment advice, an advertisement or offering of investment advisory services, or an offer to sell or a solicitation to buy any security.

--By Jay Kaeppel from blog Jayonthemarkets.com

The post Using Metals to Trade Bonds appeared first on System Trader Success.

]]>The post Is The Christmas Season Bullish For U.S. Markets? appeared first on System Trader Success.

]]>With the Christmas season upon us, I thought it would be interesting to review how the S&P behaves in the days just before Christmas. Do the days just before this holiday tend to be bullish, bearish, or neutral?

To test the market behavior just before the Christmas holiday I will use the S&P Cash index back in 1960. I will create an EasyLanguage strategy that will enter a trade X days before Christmas and close that trade on the opening of the first trading day after Christmas. Each trade will dedicate $100,000 to purchase shares. Stops, and both commissions and slippage are not utilized in this study.

First let's look at the ten days before Christmas. What happens if we enter a trade X days before Christmas and close that trade on the open after Christmas? By using TradeStation's optimize feature I can systematically test each day over the historical data. The results of each test is the generated P&L for each iteration and is depicted in the bar graph below. Looking at the graph, each bar on the x-axis represents the number of days before Christmas.

It appears that the 10 days before Christmas all show positive P&L. In general, the longer you're holding period before Christmas the better.

Ten Days After Christmas

Using a similar trading system, I will look at entering a trade on open of trading day following Christmas and holding that trade for X days. Below is a bar graph showing the days 1-10 after Christmas. Again, each bar represents P&L and the x-axis is the number of days the trade is held.

Historically, all days after Christmas in our study have returned positive results. Unlike the 10-days before Christmas, in this case it appears there is not much gain for holding beyond five days.

Based on the information above, which seems to show a strong bullish biased for the days immediately before and after Christmas, I'm going to create another strategy that will open a trade five days before Christmas and closes that trade five days after Christmas. I picked five days simply because it was the middle value (1-10) for the days before and after Christmas we tested. Last year's Christmas Trade (December 2017) was a profitable trade. It's pictured below.

When you combine all the trades going back to 1960 we get the following equity curve and performance.

There certainly does seem to be a very strong bullish tendency around Christmas. Can you take advantage of this in your trading? Perhaps. Remember, the code provided below this article is not a complete trading system, but an indicator to help me gauge the market behavior around the Christmas holiday. If you have trading systems or trade a discretionary method around these days before and after Christmas, you might use this knowledge to ignore short signals, or modify your exit.

Below is the free EasyLanguage code used to generate the Christmas Trade as both a TradeStation ELD file and text file. You will also find a copy of the TradeStation WorkSpace and the performance report as an Excel document.

Christmas Trade (TradeStation ELD)

Christmas Trade WorkSpace (TradeStation TWS)

Christmas Trade Strategy Code (Text File)

The post Is The Christmas Season Bullish For U.S. Markets? appeared first on System Trader Success.

]]>The post Seasonality S&P Market Session appeared first on System Trader Success.

]]>In a recent article, Seasonality Study, I took a look at the classic seasonality effect as seen in the U.S. markets. Briefly recapping that article, it shows that the trading days between November through May appear to hold significant gains in the market while the trading days between June and October hold far less profit. In this article I would like to test the market’s intra-day behavior based upon seasonality. This idea came upon me as a reader privately emailed me.

We are all aware that different sessions exist for any market. For example, when dealing with the emini S&P we have a pre-market session, the morning session, lunch time session, and an afternoon session. Often you can see distinct characteristics within each session. To test for any seasonality impact on these sessions, I’ll be using an existing tool, I originally created the article, “Step One In Building An Intraday Trading System“. In this article I use a tool called “Session Test” which allows me to test various intra-day sessions. Using TradeStation’s optimizer I can test my idea across different combinations of sessions and discover how the key concept holds up across each session. Here are the basic sessions:

- “Pre-Market” Between 530 and 830
- “Open” Between 830 and 900
- “Morning” Between 900 though 1130
- “Lunch” Between 1130 and 1315
- “Afternoon” Between 1315 and 1400
- “Close” Between 1400 and 1515
- “Post-Market” Between 1515 and 1800
- “Night” Between 1800 and 530

During this test the strategy will simply buy at the open of the session and close that trade at the conclusion of the session. This mirrors the traditional seasonality study where a trade is opened at the beginning of the season and closed several months later when the season comes to an end.

To test each session I’ll use TradeStation’s optimizer to iterate over each of the sessions. In doing so TradeStation will systematically open and close a trade for each market session and record the trading results. After all the sessions have been generated I can display a bar graph representing the P&L for each session along with an equity graph.

During my testing a single contract of the Emini will be traded. There are no stops and both slippage/commissions are not included in the results. The test will be over the dates from 1997 to October 31, 2015. The free EasyLanguage code used during this study can be downloaded at the very bottom of this article.

Below is the Net Profit graph for each of the eight sessions tested during the “Bullish” season which is from November through May.

Clearly session #8 is out best performer. This session is defined as our “Night” session from 18:00 to 5:30. This really should come as no surprise as there have been other studies which show many gains in the S&P market occur in the overnight session.

Below is the test executed over the “Bearish” season which include the months of June through October.

Once again session #8 is king. However, notice this session makes less money as apposed to the “Bull” season. Yet, session #5 makes slightly more money. Looking at the other sessions, many of them end up deep into negative territory which is different than the “Bull” season. This does make sense as the “Bullish” season does appear to have a more bullish edge.

Below is the equity graphs for each of the sessions.

**Bull Season**

That’s a lot of graphs! The most obvious conclusion is the overnight session really does seem to hold a bullish tendency. This bullish tendency still holds during the “Bear” season, but it does appear to be reduced. Some of the other sessions appear to hold some promises as well. Those would include the “Afternoon” and “Close” sessions. The “Afternoon” session during a “Bull” season appears to be very strong since the financial panic of 2008.

*Overnight*Session during a Bull Season*Afternoon*Session during a Bull Season

Below is the free EasyLanguage code used for this study.

- Seasonality Session Study (TradeStation ELD)
- Seasonality Session Study (Text File)

The post Seasonality S&P Market Session appeared first on System Trader Success.

]]>The post Market Seasonality Study appeared first on System Trader Success.

]]>With October over I thought it would be a good idea to review our Market Seasonality Study.

Back on May of this year, we closed a seasonality trade in anticipation for a traditional weak period of the stock index markets. That is, the months of May, June, July, August, September and October. So what did the market do during those months?

Below is a graph of the market with a "buy" at the start of the weak period and a "sell" at the end of the weak period.

As you can see, the traditionally weak period took off! Only in the last few weeks did it start giving back some of those gains. The weak period returned a $3,375 (3.4%) gain.

We are now entering a traditionally strong season for the stock index market. This is a well known seasonality period. In this article I would like to take a closer look at the seasonality bias which so many investors and traders talk about.

First, I would like to test the popular trading idea of buying the S&P in November and selling in May. I will test this on the cash market going back to 1983. The number of shares to buy will be adjusted based upon a fixed amount of risk. In this case, $5,000 is risked per trade based upon the volatility of the market. As this is a simple market study no slippage or commissions were taken into account. The EasyLanguage code looks like this:

CurrentMonth = Month( Date ); If ( CurrentMonth = BuyMonth ) And ( MP = 0 ) Then Buy("Buy Month") iShares contracts next bar at market; If ( CurrentMonth = SellMonth ) Then Sell("Sell Month") iShares contracts next bar at market;I decided to test the strategy on the S&P cash index going back to 1960. The following assumptions were made:

* Starting account size of $100,000.

* Dates tested are from 1960 through May 2017.

* The number of shares traded will be based on volatility estimation and risking no more than $5,000 per trade.

* Volatility is estimated with a two times 20-week ATR calculation. This is done to normalize the amount of risk per trade.

* The P&L is not accumulated to the starting equity.

* There are no deductions for commissions and slippage.

* No stops were used.

From here we can plug into the input values the buy month (November) and sell month (May). Doing this we generate the following equity graph:

It sure looks like these months have a long bias as those are some nice results. What would the equity curve look like if we reverse the **BuyMonth** and **SellMonth**? That is, let's buy in May and sell in November. Below is the equity curve for this inverted system.

The early years of 1960 to about 1970 the equity curve went lower and lower. Then it started climbing reaching an equity peak of 1987. During this period, the strategy was producing positive results. That equity peak occurred during 1987 should be familiar. That was the year we had the massive one day market crash on October 19th known as Black Monday. That's when Dow Jones Industrial Average dropped 22% in one day!

Since that event the behavior of market participants has been altered. This is not unlike the radical market changes which occurred after the 2000 market peek where much of the trending characteristics of the major markets were replaced by mean reversion tendencies. So far the basic seasonality study looks interesting. However, keep in mind that we do not have any stops in place.

Nor do we have any entry filter that would prevent us from opening a trade during a bear market. If the market is falling strongly when our **BuyMonth** rolls around we may not wish to purchase right away.

Likewise, we have no exit filter to prevent us from exiting when the market may be on a strong rise during the month of May. It's conceivable that the market may be experiencing a strong bull run when our usual **SellMonth** of May rolls around.

In order to avoid buying and selling at the wrong times I'm going to introduce a 30-period simple moving average (SMA) to act as a short-term trend filter. This filter will be used to prevent us from immediately buying into a falling market or selling into a rising market. For example, if our **SellMonth** of May rolls around and the market happens to be rising (trading above the 30-period SMA), we do not sell just yet. We wait until unit price closes below the short-term SMA. The same idea is applied to the buying side, but reversed. We will not go long until price closed above the short-term SMA. Within EasyLanguage we can create a buy/sell confirmation flag called **BuyFlag** and **SellFlag** which will indicate when the proper go-long or sell conditions appear based upon our short-term trend filter.

if ( MinorTrendLen > 0 ) Then BuyFlag = Close > Average( Close, MinorTrendLen )

Else BuyFlag = true;

If ( MinorTrendLen > 0 ) Then SellFlag = Close < Average( Close, MinorTrendLen )

Else SellFlag = true;

The **MinorTrendLen** variable is actually an input value which holds the look-back period to be used in the SMA calculation. You will notice there is an additional check to see if the look-back period is zero. This is done so we can enable or disable this SMA filter. If you enter zero for the look-back period, the code will always set our **BuyFlag** and **SellFlag** to true. This effectively disables our short-term market filter. This is a handy way to enable and disable filters from the system inputs. Below is the performance of both our Baseline system and the system with our SMA filter:

We increased the net profit, profit factor, average profit per trade, annual rate of return, and the expectancy score. The max intraday drawdown fell as well. Overall it looks like the SMA filter adds value.

A standard MACD filter is a well known indicator that may help with timing. I'm going to add a MACD calculation, using the default settings, and only open a new trade when the MACD line is above zero. Likewise, I'm only going to sell when the MACD line is below zero. Within EasyLanguage we can create a MACD filter by creating two Boolean flags called **MACDBull **and** MACDBear** which will indicate when the proper major market trend is in our favor.

If ( MACD_Filter ) Then

Begin

MyMACD = MACD( Close, FastLength, SlowLength );

MACDAvg = XAverage( MyMACD, MACDLength );

MACDDiff = MyMACD - MACDAvg;

If ( MyMACD crosses over 0 ) Then

Begin

MACDBull = True;

MACDBear = False;

End

Else If ( MyMACD crosses under 0 ) Then

Begin

MACDBull = False;

MACDBear = True;

End;

End

Else Begin

MACDBull = True;

MACDBear = True;

End;

Below are the results with the MACD filter:

Utilizing the MACD filter and comparing it to our baseline system, we reduced every so slightly many of the performance metrics. Overall, it does not appear to be better than our SMA filter.

For our final filter I will try the RSI indicator with its default loopback period of 14. Again, like the MACD calculation, I want price moving in our direction so I want the RSI calculation to be above zero when opening a position and below zero when closing a position.

If ( RSI_Filter ) Then

Begin

RSIBull = RSI(Close, 14 ) > 50;

RSIBear = RSI(Close, 14 ) < 50;

End

Else Begin

RSIBull = true;

RSIBear = true;

End;

The RSI filter performed better than the MACD filter. Comparing it to the Baseline, we see it's very similar. With the RSI filter the net profit, profit factor and RINA Index are all slightly lower.

In the end it does appear applying a SMA filter or an RSI filter can improve the baseline results. Both filters are rather simple to implement and were tested for this article with their default values. Of course, you could take this simple study much further.

After performing the different filter tests and choosing the simple moving average filter, I started wondering what it would look like if we applied to the weak seasonality period. Below are the before-and-after equity curves.

It appears the simple moving average filter helps a lot. While we can still see the weak seasonality period equity curve is not nearly as attractive as the strong seasonality period, it did improve to somewhat decent.

It certainly appears there is a significant seasonal edge to the S&P market. The very trading rules we used above for the S&P cash market could be applied to the SPY and DIA ETF markets. I've tested those ETFs and they produce very similar results. The S&P futures market also produces similar results. It even appears to work well on some stocks.

Keep in mind this market study did not utilize any market stops. How can this study be used? With a little work an automated trading system could be built from this study. Another use would be to apply this study as a filter for trading other systems.

This seasonality filter could be applied to both automated trading systems or even discretionary trading. It may not be much help for intraday trading, but it may be worth testing. Anyway, just being aware of these major market cycles can be helpful in understanding what's going on with today's markets and where they may be going in the near future.

Hope you found this study helpful. This seasonality filter (30-period SMA) is what's used on our State of U.S. Markets webpage.

The post Market Seasonality Study appeared first on System Trader Success.

]]>The post ARIMA/GARCH – Straight Out of the Lab to the Trading Scene appeared first on System Trader Success.

]]>Arima/Garch hybrid model is one of the hottest area of research for both time series forecasting as well as modeling markets. I have spent over a year working with this methodology. Large Institutional Traders and Hedge funds are researching methods like this. In my opinion, your days are numbers as a trader if you don’t add this type of research into your trading.

Traders and Quants want predictions to return a single or multiple bars into the future. To achieve this, there are diverse ensemble methods to go with. Among the ensemble method is a hybrid model bears both the autoregressive integrated moving average (ARIMA) model and the generalized autoregressive conditional heteroscedasticity (GARCH) model.

Experts predict that the implementation of machine learning to backtesting and trading platforms will be indispensable few years from now. So will the use of programming language libraries of R and Python. While R boosts of numerous machine statistical and machine learning libraries, Python has a matchless text processing (NLP) to craft sentiment indicators the social media or news sources.

I think this can be one of the most important technologies for traders in the modern computer era on par with Spectral analysis and Game Theory in trading world. The research in this area is just starting, a good percentage of peer review papers are less than 4 years old and some are less than 2 years old. This will be a one of the hottest areas of research for the next 5 to 10 years. If you don’t look at this technology you will have institutional traders making classic methods untradeable over time.

I have been researching ARIMA/GARCH Hybrid models for almost year and I feel I have just touched the surface. I have studied a lot of the published research as well as developing my own research tools in R. My R program ARIMA/GARCH Professional is the results of about 500 hours of work and is outputs many internal variable and advance features of ‘rugarch’ R library. You could try to develop something like this yourself but it requires world class R programming skills.

The ARMA model and ARMA-GARCH model can be used to forecast the trading markets. Out-of-sample forecasting performance is evaluated to compare the forecast ability

of the two models. From a statistical point of view, the ARMA-GARCH model outperform with all of the three commonly used statistical measures. Traditional engineering type of models aim to minimize statistical errors. However, the model with minimum forecasting errors in statistical term does not necessarily guarantee maximized trading profits, which is often deemed as the ultimate objective of financial application.

The best way to evaluate alternative financial model is therefore to evaluate their trading performance by means of trading simulation. We found that both ARMA and ARMA-GARCH models were able to forecast the future movements of the market, which yields significant risk adjusted returns compared to the overall market during the out-of-sample period. In addition, although the ARMA-GARCH model is better than the ARMA model theoretically and statistically, the latter outperforms the former with significantly higher trading measures.

The chosen model will make use of the ARIMA/GARCH mode. This makes use of a mean prediction that an ARCH/ARIMA renders and combines it with a GARCH procedure. A lot of R libraries can execute this but just a single one is deployed as a research tool.

The Rugarch library is written by Alexios Ghalanos where he takes the analysis from interesting academic research to a tool that is capable of both risk and trade analysis and predicting future returns.

His GARCH research has allowed him to analyze how a given model will react to the impact of news events. It also supports GARCH models and submodels explained in the research.

The Rugarch is not the only R library effective. Quantmod can always come in handy too. It helps quantitative traders in developing, testing, and deploying statistically based trading models.

Both split and dividend adjust data are deployed for SPY by which the data finesse the effects. At this stage, we will not be making use of the regressor but the ARIMA/GARCH model. We shall test from 1/1/1995 to 7/25/2018.

Our signal data generated from our prediction model is a ascii file. Thus, we can load this into TradeStation as *data2* and our EasyLanguage code simply issues buys/sell signals based upon our predictive data. The signals represent a prediction that tomorrow will be:

- 1 – up
- -1 – down
- 0 – don’t know.

Below is the EasyLanguage code.

*// MLPro_ArimaGarchSimple simple strategy using predictionsInputs: BuyLev(0),SellLev(0);.Vars:Pred(0);Pred= close of data2;If Pred>BuyLev then buy next bar at market;If Pred<SellLev then sell short next bar at market;// could not make prediction so let's just exitIf Pred=0 andmarketposition=1 then sell("FlatLX") next bar at market;If Pred=0 and marketposition=-1 then buytocover("FlatSX") next bar at market;*

As default zero value is being used, the results corresponds to the one produced when the backtest ran in the course of modeling. Do not forget that in this we used case, spit/dividend adjusted data but TradeStation’s data is split adjusted alone. This is the cause of the disparity between them.

Bear in mind that this is only raw forecasting, with the use of zero as a boundary and filtering out when result is zero just because we cannot predict. This is only a starting point, using the extra information in our advance file can improve performance.

Combining this predictive model with other technical data or models can really create improvement. Think of the predictive model as a filter helping you determine if your stratgy should be focusing on the long or short side!

In my research I have seen external regressors improve results as much as 20%-30%. You can see that ARIMA/GARCH appears very promising. Having the right tools and guidance can allow you to add this tool that large institutional traders are research to your arsenal so you don’t get left in the dust.

Get the tool used to generate this Arima/Garch model by visiting here.

-- By Murray Ruggiero, Using EasyLanguage

The post ARIMA/GARCH – Straight Out of the Lab to the Trading Scene appeared first on System Trader Success.

]]>The post Going Live With Automation appeared first on System Trader Success.

]]>Going live with an automated strategy is one of the coolest, but also scariest things you can do in trading. Here you are letting a computer trade with your hard earned money. Theoretically, the computer makes ALL the buying and selling decisions except for rollover trades. Many people simply can’t do it – the stress and pressure of trading decisions being made outside of their control is just too much to bear.

The flipside though, is that automated trading can be extremely liberating. Turning control over to a computer – as long as you trust its decisions – frees you up to do other tasks (like developing more and more strategies!). Adding automated strategies to a portfolio can be fun and exciting, as well as hopefully ultimately profitable.

Of course, it is assumed that you have a properly tested and vetted strategy ready to go, and an example of which is shown in Figure 1. But once you are ready to go, then what? What pitfalls should you look out for? What kind of “tricks of the trade” are available?

In this article, I’ll discuss some of the basics, and provide a few handy tools for you to use in your automation. This article is far from complete coverage of automation (the perils of unattended trading, and the use of virtual private servers are aspects of automated trading deserving of their own articles, for example). I’ll use the TradeStation platform for all examples and coding, but the concepts apply to all trading software platforms.

When you tested your strategy, you likely used a continuous contract of some sort for your market data. In TradeStation, the back adjusted continuous contract (my favorite type) is denoted with a prefix “@”. So, for example the Crude Oil continuous contract is @CL.

Unfortunately, you cannot trade the live symbol, “@CL” since TradeStation needs to know which contract month you would want to trade. Thankfully, they provide continuous monthly contracts, such as “@CLV14” for October, 2014 and “@CLX14” for November, 2014. Each is identical to @CL when it is the front contract.

So, for actual trading use the symbols such as @CLX14, depending on the current contract month.

Since you tested your strategy with the @CL symbol, which always trades the lead contract, you want to make sure your live trading matches up with it. If the current month is November, you don’t want to trade the December contract, since then you are introducing the Nov-Dec spread dynamics into your trading, which is not what you tested. Always trade only what you tested!

So, how do you monitor that you are trading the correct contract? It obviously can get hairy when multiple strategies, multiple instruments, and multiple charts are involved. To assist me with this, I created a simple paint bar indicator which you can find at the end of the article.

All you have to do is have the contract you want to trade (@CLV14) as data1, and the perpetual continuous contract (@CL) as data2 in your chart. Remember the order is important, since you can only trade data1. The indicator monitors for any difference between these two data streams. As long as October “V” is the current month, the indicator will not plot anything. But, when the contract rolls to November “X”, the paint bar will paint a green bar in the data1 portion of the chart, as shown in Figure 2. That is your signal to roll the position.

Another critical part to successful automated trading is making sure that the strategy position and the real life position match. TradeStation provides a decent way to monitor this, as shown in Figure 3. But, in staring at the charts all day, I found it easy to forget to check the Trade Manager window. So, I created another paint bar indicator, included at the end of the article. It monitors the strategy position and the real world position, and draws a big red bar when there is a mismatch. An example of this is shown in Figure 4.

Unfortunately, this “position mismatch” indicator is a little too good, and gives false alarms quite often. I actually like that aspect, as it keeps me constantly checking positions, but it is left to the reader to improve upon the accuracy of the indicator. The good thing about the version given at the end of the article is that it does not seem to miss position mismatches – better to have a few false alarms than a major miss!

These indicators are especially useful when you have to rollover. They will tell you when to roll, and will ensure you do it correctly. I’ll show that below with an example.

On September 17th, the CL strategy was long 1 contract of October Crude Oil, @CLV14. At the close of September 17, TradeStation rolled the October contract to November. I was alerted to that fact by the green bar, shown in Figure 5. Remember, the green bar shows a mismatch in continuous contracts. So, that was my cue to roll.

Normally, I would use the exchange supplied spread to roll a position, in this case I would sell the October-November spread. That would make me flat in October, and long in November. The exchange supplied spreads are the safest and usually cheapest way to roll. Unfortunately, the TradeStation 9.x platform does not support this, so you have to “leg” in and out of the position in order to roll.

So, my first step is to exit my October long. After I do that, my chart was as shown in Figure 6. The big red bar told me there was a mismatch in position.

The next step is to change the data1 stream to @CLX14. This will eliminate the green bar (which was hidden behind the red bar), but the red bar persists, as shown in Figure 7.

That is telling me I need to do something in November, namely buy. I did that in Figure 7, and I was filled in Figure 8. But you will notice the red bar persists. Now, I simply turn the indicator off and then back on, and end up with Figure 9. No red bar, no green bar. Everything is good!

Of course, there is a lot more to automated trading than just synching up continuous contracts and monitoring live vs. strategy positions. But, these are two critical aspects that many people never fully get a handle on. Properly managing positions and contract rollovers can be critical to your success. As you trade 5, 10, or 50 or more strategies, you’ll be thankful you have these tools to help you monitor your rollovers and your positions.

If you would like to learn more about building trading systems be sure to get a copy of my latest book, Building Winning Algorithmic Trading Systems.

MisMatched Indicator (TradeStation ELD)

— Kevin J. Davey of KJ Trading Systems

If you want to learn more about algo trading get a copy of my book, **"Introduction To Algo Trading"**

The post Going Live With Automation appeared first on System Trader Success.

]]>The post Testing Market Regime Indicators appeared first on System Trader Success.

]]>Often when designing a system it’s important to keep the big picture in mind. What is the overall market doing? The most simple way to accomplish this is to break the market into two regimes: bullish and bearish. We are all aware that price action is a mirror of human psychology of market participants, therefore price action can often be very different between these two regimes. Sudden market plunges that we see within strong bear markets, such as in 2008, behave much differently when contrasted to the continual grinding, upward market we saw after 2009. People behave differently under fear (how low can it go) and pain (look at all the money I lost) vs. doubt (this market can’t go higher) and greed (I’ll just make a bit more before I exit). Since people behave differently under these two market regimes it makes sense that we should design trading systems that take advantage of the different market characteristics for each regime. We want to build a system that dynamically adjusts its trading parameters based upon which market mode we’re experiencing. To do this we can use any number of indicators.

The most simple way to divide the market is to use a 200-period simple moving average (SMA). When price is above it we are in a bull market regime. When price is below it we are in a bear market regime. Introducing this simple concept along can improve the performance of many trading systems. I’ve personally used this technique many times. Yet there are other techniques to divide a market and some of these might produce better results than our old reliable 200-day SMA. In this article I want to take a look at a few different methods.

The indicators we are going to test are:

- SMA(200)
- Rate of Change (ROC)
- Smoothed Adaptive Momentum
- Relative Strength Ranking (rsRank)

The Smoothed Adaptive Momentum and Relative Strength Ranking are two indicators you may not be aware of. First, the Smoothed Adaptive Momentum was created by John Ehlers. It’s a complex indicator and there’s more than I want to get into during this article. Google it if you wish and you can also find the EasyLanguage code here. As for the RS Rank, you can find a little more about it here. I will say this about the rsRank for now, traditionally it’s used as a ranking tool to compare a group of stocks or ETFs to determine which specific instrument is performing best. As its name implies, it ranks each instrument based on how well the instrument has been performing. You can then compare this score to the other stocks or ETFs in your basket of trading instruments. Thus, you can simply pick the instrument with the highest rsRank score when creating a momentum-based trading system. In this article I’m using it for a completely different purpose and I was curious on how well it would hold up.

All of these indicators are also smoothed to help reduce whipsaw. Of course the SMA is a smoothed price indicator so no modification was made to this indicator. Likewise the Smoothed Adaptive Momentum indicator by John Ehlers also contains a smoothing element already applied to the indicator. However, to smoothen the ROC and rsRank indicator I used the same technique found within the Ehlers indicator. It looks like this for the rsRank indicator:

`rsRankSmoothed = ( rsRankValue + rsRankValue[1]<em>2 + rsRankValue[2]</em>2 + rsRankValue[3] )/6;`

The same smoothing technique is applied to ROC as well.

We are going to use a 200-day period for all our examples. The 200 days represent about ten months of trading if you figure out that there are about 20 trading days per month. It’s also a common longer term period applied to moving averages as well. This is not a magic number by any means. It’s a large enough number that we should not see the regime switch too often between bear and bull. The idea is to capture the long term market mode, not every market gyration. Of course I encourage you to perform your own testing as well.

The strategy code to test the effectiveness of these different indicators is rather simple. We are only going long during a bull market regime and closing our position when that bull market regime switches to a bear market regime. In essence we are creating a very simple trend following system. For each indicator the transition is based upon:

- SMA: Bull market when price is above the SMA
- ROC: Bull market when indicator value is above zero
- Smoothed Adaptive Momentum: Bull market when indicator value is above zero
- RS Ranking: Bull market when indicator value is above zero

Here is an example of the rsRank indicator used as a regime filter:

I coded the above rules in EasyLanguage and tested it on the SPY ETF market going back to 1993. All the tests within this article are going to use the following assumptions:

- Starting account size of $50,000.
- Dates tested are from 1983 through June 14, 2013.
- The number of shares traded will be based on volatility estimation and risking no more than $2,000 per trade.
- Volatility is estimated with a three times 10-day ATR calculation. This is done to normalize the amount of risk per trade.
- The P&L is not accumulated to the starting equity.
- There are no deductions for commissions and slippage.
- A hard stop of $2,000 is placed for all trades.

The following results are organized left-to-right by total return. We can see the ROC indicator has produced the best total return over the life of the study. It also produced the fewest trades and the highest number of winning trades. In a more distant second place is the rsRank indicator.

**Regime Testing Indicators on SPY Since 1993**

JE Adaptive | SMA | rsRank | ROC | |
---|---|---|---|---|

Net Profit | $43,264 | $56,070 | $76,353 | $114,732 |

Profit Factor | 1.78 | 3.26 | 4.56 | 12.52 |

Total Traders | 125 | 72 | 48 | 25 |

%Winners | 42% | 34% | 44% | 48% |

Avg.Trade Net Profit | $346 | $779 | $1,591 | $4589 |

Consecutive Losers | 6 | 9 | 6 | 5 |

Annual Rate of Return | 3.25% | 3.92% | 4.83% | 6.21% |

Total Return | 87% | 112% | 153% | 229% |

Buy&Hold Total Return | 260% | 260% | 260% | 260% |

Notice the last row is the buy-and-hold results. None of the “systems” come close to B&H but please keep in mind these are not trading systems. We are testing indicators to see how they compare against one another in the task of picking out bull market regimes.

When looking at the equity graph of the systems it becomes apparent that much of the gain occurred during the tech boom of the late 1990’s. Since that crash, the market has behaved much differently. So I also tested the same set of indicators on the years after 2000. Those results are below:

**Regime Testing Indicators on SPY Since 2000**

rsRank | JE Adaptive | ROC | SMA | |
---|---|---|---|---|

Net Profit | $13,147 | $14,064 | $16,562 | $19,960 |

Profit Factor | 1.75 | 1.38 | 3.90 | 2.4 |

Total Traders | 33 | 80 | 17 | 43 |

%Winners | 45% | 45% | 53% | 42% |

Avg.Trade Net Profit | $398 | $176 | $974 | $464 |

Consecutive Losers | 4 | 6 | 2 | 5 |

Annual Rate of Return | 1.84% | 1.96% | 2.26% | 2.65% |

Total Return | 26% | 28% | 33% | 40% |

Buy&Hold Total Return | 18% | 18% | 18% | 18% |

Once again the results are organized left-to-right by total return. Our ROC rank has fallen to second place while SMA has moved into our number one position generating the highest return, but at what cost? We can see ROC continues to excel in terms of profit factor, the number of winning trades and reducing the number of trades. It holds up well on a number of factors that I like.

Based on these limited tests ROC shows superior results when determining a bull market from a bear market. In summary, put this to use in your own efforts at building a trading system. Use an indicator to determine the market mode and trade accordingly. The point here is to have your automated trading system automatically adapt to a changing market. For example, when the market is bullish you may want to look for longs only while ignoring shorting opportunities. Or if the market is within a bearish mode the criteria for entering a long position might be stricter than when in a bull market. Too often people simply trade the same setup or method during different market conditions. By breaking the market up into two regimes, you are making your trading system dynamic and adaptive to the changing market.

There are ways to segment a market further. Check out these articles as well.

Two Dimensional Market Filter A Better Regime Filter To Boost Returns

File[9]: http://www.systemtradersuccess.com/downloads/free/MARKET REGIME_TESTING_STRATEGY.ELD “TradeStation ELD”

[10]: http://www.systemtradersuccess.com/downloads/free/Market Regime_Testing_2000.tsw “TradeStation WorkSpace”

The post Testing Market Regime Indicators appeared first on System Trader Success.

]]>The post Finding Out What Works, And What Doesn’t Work – Part II appeared first on System Trader Success.

]]>In Part 1 of this series, found here, I ran a simple study of a trading system, in order to look at some of the common components (such as end of day closes, short versus long bar periods) that many system developers add to their trading system. Could some of these strategy building blocks be hurting their development efforts? To answer the question, I analyzed one trading system over 7 different markets for a 5 year period. Even though I was able to extract some conclusions from the study, I also said the following:

“Of course, I made these conclusions based on one study. What if the strategy was different? What if the timeframes or markets were different? What if different years were used for the test period? Will the conclusions reached here still hold? I’ll examine those questions in Part 2.”

To summarize the earlier work, the conclusions from Part 1 were:

- Striving for profit in multiple markets, as a confirmation of a strategy, is indeed possible.
- Swing trading is likely more profitable than intraday trading.
- Longer timeframes are generally superior to short time periods, but this is not a major effect.

In this second part of the study, I’ll now look at a different group of markets, a completely different strategy and some different timeframes. I’ll also try to answer the following questions: Will the conclusions still hold up? What type of insights, if any, do conducting studies like these actually provide? Finally, can studies like these improve your own strategy development?

Previously in Part 1, I tested 7 different markets across a range of commodities.

**(Group 1):**

- Wheat (W)
- 10 Year Treasury Notes (TY)
- Lean Hogs (LH)
- Australian Dollar (AD)
- Heating Oil (HO)
- Cotton (CT)
- the e-mini Nasdaq (NQ)

I picked these at random, one from each major market group. The test period will be from 1/1/2007 to 12/31/2011, a 5 year period that includes some quiet, and some very chaotic, markets.

For Part 2, I will test another basket of commodities.

**(Group 2):**

- Live Cattle (LC)
- Canadian Dollar (CD)
- Copper (HG)
- Natural Gas (NG)
- Sugar (SB)

I will also test the period 1/1/2012 to present, a smaller test period outside of the range previously tested.

Finally, I will assume $5 round turn commissions and $30 round turn slippage.

I will use two extremely simple base strategies for the tests I am running: a simple breakout based on closing prices (Strategies A and B), or a reverse breakout (countertrend – Strategies C and D). In all cases, the breakout length X will be varied from 5 bars to 100 bars.

Here is the code for all four versions of the strategy:

First, I will conduct a test of Strategies A and B for the same period, with the second group of commodities. To keep things manageable, only the group summary results are shown below:

**Strategy A- Breakout, Swing Trading**

**$ Thousands ($K) Maximum Net Profit, 2007-2011**

5 min | 15 min | 30 min | 60 min | 120 min | daily | |
---|---|---|---|---|---|---|

Median Group 1 | $32 | $42 | $37 | $38 | $38 | $39 |

Median Group 2 | $24 | $25 | $27 | $29 | $37 | $38 |

**$ Thousands ($K) Maximum Drawdown for Max Net Profit case, 2007-2011**

5 min | 15 min | 30 min | 60 min | 120 min | daily | |
---|---|---|---|---|---|---|

Median Group 1 | $16 | $19 | $12 | $16 | $19 | $14 |

Median Group 2 | $27 | $45 | $33 | $10 | $15 | $6 |

**% of Intereaction Profitable (100%=goal) 2007-2011**

5 min | 15 min | 30 min | 60 min | 120 min | daily | |
---|---|---|---|---|---|---|

Median Group 1 | 48.5 | 81 | 62.5 | 77 | 74.5 | 88 |

Median Group 2 | 24.5 | 18 | 25 | 30 | 69 | 60 |

**Strategy B- Breakout, Exit of the day**

**$ Thousands ($K) Maximum Net Profit, 2007-2011**

5 min | 15 min | 30 min | 60 min | 120 min | daily | |
---|---|---|---|---|---|---|

Median Group 1 | $19 | $14 | $13 | $8 | $5 | $4 |

Median Group 2 | $27 | $19 | $21 | $18 | $12 | $2 |

**$ Thousands ($K) Maximum Drawdown for Max Net Profit case, 2007-2011**

no data shown for cases where maximum net profit <$0

5 min | 15 min | 30 min | 60 min | 120 min | daily | |
---|---|---|---|---|---|---|

Median Group 1 | $27 | $19 | $21 | $18 | $12 | $2 |

Median Group 2 | $19 | $26 | $10 | $8 | $8 |

**% of Iterations Profitable (100%=goal), 2007-2011**

no data shown for cases where maximum net profit <$0

5 min | 15 min | 30 min | 60 min | 120 min | daily | |
---|---|---|---|---|---|---|

Median Group 1 | 58 | 90 | 97 | 62.5 | 100 | 98 |

Median Group 2 | 49 | 77 | 80 | |

The results of Group 2 are generally in line with Group 1 results, which show that swing trading (strategy A) is better than intraday trading (Strategy B), and that longer timeframes are slightly better than short timeframe bars.

Of course, concluding that long timeframe bars and swing trading is superior based on only a few tests is dangerous. So, let’s look at Strategies C & D (the opposite Strategies of A & B), and see if the results have the same tendencies for different timeframes and test period, on a random subset of Group 1 and Group 2 instruments.

**Strategy C- Reverse Breakout, Swing Trading**

**$ Thousands ($K) Maximum Net Profit, 2012 - present**

10 min | 45 min | 90 min | |
---|---|---|---|

W | $17 | $19 | $17 |

AD | $36 | $27 | $23 |

HG | $73 | $67 | $68 |

SB | $6 | $1 | $3 |

Median-Subset Group | $27 | $23 | $20 |

**% of Iterations Profitable (100%=goal), 2012 - present**

10 min | 45 min | 90 min | |
---|---|---|---|

W | 50% | 70% | 46% |

AD | 88% | 61 | 36% |

HG | 83% | 100% | 80% |

SB | 0% | 10% | 22% |

Median-Subset Group | 67% | 66% | 41% |

**Strategy D- Reverse Breakout, Exit End of the day**

**$ Thousands ($K) Maximum Net Profit, 2012 - present**

10 min | 45 min | 90 min | |
---|---|---|---|

W | $26 | $11 | $10 |

AD | $1 | $1 | $2 |

HG | $10 | $9 | $4 |

SB | $19 | $12 | $8 |

Median-Subset Group | $15 | $10 | $6 |

**% of Iterations Profitable (100%=goal), 2012 - present**

10 min | 45 min | 90 min | |
---|---|---|---|

W | 0 | 0 | 0 |

AD | 0 | 0 | 0 |

HG | 0 | 0 | 0 |

SB | 0 | 0 | 0 |

Median-Subset Group | 0 | 0 | 0 |

For timeframes, the results show a tendency for the smaller timeframes to be better than the longer timeframes, exactly the opposite of what was found earlier. But this effect is small, which could mean it is not actually true, and could be just an artifact of the limited testing. This is a good example why it is dangerous to draw conclusions from only a few tests.

For the swing vs. intraday testing, the results are pretty clear – intraday testing is not nearly as good as swing trading. This agrees with the earlier conclusion.

Through both Part 1 and Part 2 of this study, a lot of tests have been run over various bar timeframes, instruments, strategies and time periods. Yet, it would be dangerous to make any sweeping conclusions based on these tests. Although these results show that intraday trading is less profitable than swing trading, there are surely cases where intraday trading is preferable over swing trading.

So, what can this study actually teach us? I think the following lessons come out of this study:

- Intraday trading is less profitable than swing trading. This does not mean this always holds, but if you do most of your testing intraday and you are struggling to develop a strategy, perhaps opening up the strategy to allow swing trading is a good idea. It could be that you have a good swing strategy, but the end of day exit alone makes the strategy look bad.
- Longer timeframes are better (Part 1 conclusion), except when they aren’t (Part 2 conclusion). So, be careful of making conclusions when the effect is small, or results are contradictory. Since many strategy developers tend to find something that does or does not work and then focus only on that (or avoid it), the lesson here is that the developer should not “box” themselves in. Maybe short timeframes rarely work with your strategies, but that does not mean you should never test them. There will be other strategies where shorter time bars are an asset.
- Since a developer can never test everything, it may be worthwhile to vary your test approach. By looking at different timeframes, instruments, etc., you may discover new paths to take in your strategy development.

The key to successful strategy testing and development is to keep an open mind, and allow the data to point you in the right direction. At the same time, though, don’t let the data trick you into making false conclusions or sweeping generalizations. Remaining flexible in your development approach can lead to new and profitable strategies – ones that you might now be dismissing based solely on past testing.

If you would like to learn more about building trading systems be sure to get a copy of my latest book, Building Winning Algorithmic Trading Systems.

Breakout Strategies (TradeStation ELD)

Breakout Strategies WorkSpace (TradeStation TWS)

— Kevin J. Davey of KJ Trading Systems

If you want to learn more about algo trading get a copy of my book, **"Introduction To Algo Trading"**

The post Finding Out What Works, And What Doesn’t Work – Part II appeared first on System Trader Success.

]]>The post System Performance and Confidence Interval appeared first on System Trader Success.

]]>When you review the performance of a trading model, how do you know it’s worth trading for? How do you know it’s the right system for you? How confident are you that it will continue to profit in the future? When it comes to evaluating your trading model there are many factors to take into account. Some of them are obvious such as Net Profit and Risk-Per-Trade. Others may be a bit more unfamiliar such as Sharpe ratio or Profit Factor. This article is going to be the first article in several where I highlight a method or idea that can help you gauge the quality of a given trading model. In this article I would like to highlight a statistical-based metric that can be used to help indicate the likelihood that a given system will continue to generate profits in the future.

Many people simply look at the net profit of a trading model assuming a system with more profit must be the better system. This is often far from a good idea. More profit may also mean more risk, deeper drawdown, or other compromises to achieve those higher results. When testing trading models during the development process or reviewing a commercially available system before making a purchase, it is advisable to have a few metrics on hand that will allow you to make a wise choice. There is no one single score that will give you the definitive answer. Furthermore, everyone has unique risk tolerances and expectations on what is considered tradable. Yet, we can make smarter choices than simply looking at net profit. Here is one method you should be aware of.

It’s easy to find a trading model that has a positive average profit of $100 and then conclude it could be profitable into the future. But is there a metric we can use to help us predict what might happen into the future? A complicated approach would be to use the Monte Carlo method, but not everyone has access to this however, we all have access to a simple calculator. By visiting a topic in statistics called Confidence Intervals (CI) we can obtain a hint at what’s possible and perhaps find weaknesses in our seemingly profitable trading model.

The average net profit of a trading model is simply the historical P&L for each trade over a given time period. Let’s imagine a trading model that has produced 60 trades. Some of the trades are winners and some are losers. We add the total P&L together for each individual trade and divide it by the number of trades – 60 in this case – and we get $100. Clearly this is well above zero so in the long run this system appears profitable.

However, we also know that individual trades can be very different from our average profit per trade. Some trades produce much larger winning trades while others produce smaller winning trades. Still, other trades produce a range of losing trades. If we graph each trade’s P&L and then draw a line representing our average P&L we would see each individual trade falls around our mean value of $100. In other words, the P&L for any trade will vary around this mean value. We can measure this variation and use it to estimate the likelihood the system might remain profitable.

Statistically speaking, a trading model that exhibits a large standard deviation of profit per trade will have an increased chance of failing in the future. This is true even if the average mean is currently profitable. But what makes a standard deviation too large? This is explained below when we attempt to use our confidence interval to estimate a likely range of average P&L values into the future.

What we wish to do with our confidence interval is estimate with 95% confidence, if our system will probably produce a negative average P&L into the future. In other words, is it likely our seemingly profitable trading model is based upon chance? We can estimate this with our CI formula.

CI = t * SD / squareroot( N )

CI = Confidence Interval

t = T-score (we estimate value to be 2 and the reasoning behind this is beyond this article)

SD = P&L Standard Deviation for all trades

N = number of trades in our sample

With our imaginary trading model we have a $100 average net profit and 60 trades in our sample. Please note that in order for this method to work, you must have a minimum of 60 trades in your sample. Let’s also state the standard deviation for all trades is $400. With this information we can compute our 95% confidence interval.

CI = 2 * $400 / squareroot( 60 )

CI = $800 / 7.746

CI = $103.28

For simplicity let’s round the confidence interval to the nearest dollar which is $103. What do we do with this value? We create a range or band around our average net profit value of $100 by both adding and subtracting the confidence interval value.

upper band = Average Net Profit + CI = $203

lower band = Average Net profit - CI = -$3

We have now created a range of -$3 to $203 for our average net profit. What does this mean? Based on our calculation we have estimated with 95% confidence that our trading model’s average net profit could be as low as -$3 or as high as $203. The important number is the lower band because this represents a worse case situation. In our example, we have a negative value which indicates a losing model. Or at least, a potential losing scenario.

In short, our hypothetical trading model’s average net profit could be based upon chance and in the future could produce a negative P&L. Suddenly what seems like a solid system appears more shaky. Does this mean our trading model should be abandoned? Not necessarily.

In the case of the confidence interval there are two critical factors at play. Those values are the number of trades (N) and the value of the standard deviation between trades. Modification of the standard deviation can be achieved by altering the trading model logic. Modifying stops, targets, and other trading rules will change the standard deviation value. The goal would be to tighten the variation of each trade to reduce the standard deviation. This in turn, would create a smaller confidence interval. However, if you don’t want to modify the system or if you are unable to modify the system there is another way.

Our example system was based on 60 trades. This is really not a lot of trades. Let’s say we find more data to test our system and we get up to 100 trades. Let’s also pretend all the other performance factors stay the same. If we recalculate our confidence interval value we now get a value of $80. This gives us a range of $20 and $180. In this case, we have a system which produces positive value for the lower band. So maybe before we make a judgment on a system that appears borderline we should collect more trades first.

I should also point out that our imaginary trading model we are looking at has $30 deduction for each trade to account for slippage and commissions. So this negative effect is already factored into our confidence interval calculation. If we did not take into account slippage and commissions during our back-testing we would have to deduct this from our final range which would give us -$10 and $150. The impact of commissions and slippage just puts us back into negative territory gain. But we have them accounted for in our back-tested results.

As you can see having enough data points (trades) can have a significant impact on the confidence interval calculation. For system trading there are many reasons for having a large number of trades. Of course continuing to add more and more trades is not going to turn a losing system into a good system. The point here is sometimes you need to have more data before making an informed decision. If you have what you believe is a good system, yet you only have a few data points, the confidence interval calculation may be warning you to get more trades in the test sample.

Our confidence interval calculation makes some assumptions about the data. That is, the data points (trades) have a normal distribution. This of course is not necessarily correct. In many cases our trade distribution looks somewhat normal with fat tails in our distribution. Thus, we must take our confidence interval results with a grain of salt.

A bigger issue, I think is the confidence interval calculation does not indicate if this system has been curve fitted. If we have a killer system with 1,000 trades with a confidence interval range of $100 – $200 that’s great. However, it’s pointless if the system is curve fitted to the historical data and there is no way our confidence interval calculation can tell us. So, what do we do?

Ideally you would validate your new trading model on out-of-sample data to help detect if your model is over-fit to the historical data. Furthermore, you would also perform the confidence interval calculation on the out-of-sample data of your trading model. By doing this, you’ll have more meaningful results. This step will help reduce the possibility of trading an over-fit trading model and give more meaning to your confidence interval test.

But even if we have a solid system that is not curve fitted to the historical data, our confidence interval calculations are no guarantee of success in the future. The markets are dynamic and changing and it’s possible that the distribution of trades will change thus altering our average trade and standard deviation. In the end, even if our system looks great on paper, validates on the out-of-sample data, and our confidence interval looks fantastic, our trading model could fail as soon as we trade it live. If this is the case, what is the point of all these testing and is it worth doing? The short answer is, yes.

In trading there is no guarantee for future results – ever. The point of testing a system is not to prove how much money it will make in the future. The goal is to find reasons why not to trade it. The purpose of any validating test is to find weaknesses so we can address those weaknesses now before we have money on the line. Our job as professional system traders is to manage risk which means eliminating risky actions. There is no certainty. This is one of the reasons this field is so psychologically difficult.

As a final point, by using confidence interval we have another tool to find weaknesses and ultimately gives us more confidence that a particular trading model will likely bring us success into the future.

The post System Performance and Confidence Interval appeared first on System Trader Success.

]]>