DayTradingProphet.com

Attempting to survive the stock market one day at a time

Neural Network Update 8-19-08

I had planned on posting everytime my new neural networks made a prediction concerning the market’s 2 day direction as I discussed here. However, my neural networks have yet to make a single prediction since I discovered them. Hopefully, soon a prediction will be made.

I have also been working on several new neural networks as well as helping design an online backtesting platform. I will release more info about these projects in the upcommign weeks.

Potentially a Good Neural Network!

The long awaited day has finally arrived. I have developed a Neural Network that is actually worth something, or have I? I have been down this road way too many times to get excited at this point. Too many times I have had a NN that looked great in testing and then flopped going forward. Because I have made so many mistakes in the past, I tried to be extra careful this time. With any luck maybe this will be the one.

Overview
The neural network was designed to predict the movement in either the DOW or S&P over the next 2 days. I generated two neural networks. One was trained on the SPY the other trained on the DOW. The data used is from 2001 until today. Randomly 15% of the data from each training set was removed and set aside for a validation set.

Validation
Before doing any testing, I established what the baseline was. Both the DIA and SPY go up approximately 51% of the time over any 2 day period. This value was them compared to the results produced by the Neural Nets. To validate the results each network was tested using it’s validation set. The results had to be inline with the training set in order to continue. After being burned many times in the past by only using a validation set, I decided to go a step further. Since both the DOW and S&P trade very similar to one another, I ended up validating a network trained on the DIA by validating it against the SPY and a network trained on the SPY validated against the DIA. The good thing here is, although they both have similar movements, the actual values calculated for the inputs are no where near the same which creates a bit of noise. If the network was overly curve fitted to the training data, it would fail miserably with this added noise. The fact that the networks performed very well during cross validation leads me to believe I may finally have a useful NN.

Net Naming
For simplicity I named each NN based on what it represents. For example: Spy-2 means this NN was trained on the SPY, and predicts if today close > close in 2 days

Key Testing-Validation Statistics

Neural Net Name % Correct ON SPY % Correct ON DIA % Correct ON QQQQ
SPY-2 67.3% 62.5% 63.8%
DIA-2 73.6% 70.0% 64.2%

As you can see the Neural Nets appear to have an edge in their predictions. Because I am just dying to set myself up for failure, I have decided that I will post the daily predictions produced by these nets. One thing to keep in mind, the neural nets do not make predictions everyday. Most days no predictions are given by the nets. If you want to see what happens next, subscribe to my RSS feed so you don’t miss anything.

Neural Network Inputs: Data Scaling

When it comes to designing a neural network, inputs are king. It’s kind of like the saying “you are what you eat”. Well, this certainly applies to neural networks as well. If you train your network using “crap” inputs, then the network is doomed before you even begin. The question then becomes, what are good inputs? If I knew the answer to that, I would be sitting on an island in the Caribbean instead of here.

I still don’t know what “good” inputs are. However, I do know a few tricks that help with scaling your data. For now lets assume you have some inputs you want to test. You might be thinking I will just plug in the last 15 days of Open, High, Low, Close values. Not so fast. Entering the true price values will do you no good. Think about it for a minute. If you enter the values $35.50 $35.10 $36….so far everything seems fine right? Assume you trained your network with that data. Now whats going to happen when this same stock is now trading at $120? The network is no longer going to see any patterns. Because of the inputs it was given, the network was trained to find patterns in small price movements around $35.

Luckily, making that mistake is not very easy to do. Once you begin looking into neural network packages you will realize that most require the data to be in the range of [-1,1]. Now the question becomes how are we going to scale the data to fit within this range?

One thing you could do is find the highest value over the past 15 days. Then divide each day by that value. For example: 15 day high is $37. You would divide $35.50/$37 which gives you .959. Then $35.10/$37 = .949. Notice a problem? There is not much variance in your inputs. This will make it harder for your network to find patterns.

Solution
The best way I have found to scale my inputs is to first find the lowest value over the 15 days. Then find the highest value over those 15 days. Now just apply the following formula:

Input Value=(price-low)/(high-low)

Back to our example above. Lets assume the highest value was $37 and the lowest value $34. Applying this formula we see that Input Value =(35.50-$34)/($37-$34) which = .5 and our second input at $35.10 = .367

Now we have a few things going for us:

  • Variance in our inputs.
  • Data in a format that no longer depends on “hard coded” values.

The neural network can now do what it does best. Find generalizations in the data. Any pattern the network finds may now be applicable to other stocks. Regardless of whether that stock currently trades at $10 or $100.

If you like this article then subscribe to my feed

Stock trading with neural networks

Due to my background in computer programming, I have always fantasized about designing a program capable of extracting money out of the markets like an ATM. Every time I would train a neural network that was able to accurately pinpoint entries and exits, I thought for sure my day had arrived. Soon after those hopes would always come crashing down, because I would realize that it was only accurate on the data it was trained with. Give it some new data and flipping a coin would have been more productive.

Regardless of my past failures, I still find myself trying over and over again. It generally just starts with an idea late at night. I think to myself, I haven’t tried those inputs, or tried to predict that output yet. Then, like clockwork I set it all up and run the test then…failure again.

You would think that after so many failures, I would finally admit to myself that when it comes to trading, neural networks are a waste of time. I just can’t do it. I know the answer has to be out there somewhere. Neural networks are incredible tools for finding patterns in data. If the market truly isn’t random, then in theory a neural network SHOULD be able to find a tradeable pattern.

Instead of trying to design a neural network capable of trading on its own, I am now trying to design neural networks to augment my manual trading. I hope to create a neural network that can simply give me better than a 50-50 prediction as to the direction of the market tomorrow. By itself this may seem useless, but think about it for a minute. If with any degree of certainty you could know that tomorrow the S&P will close green, or close red. Couldn’t this information be very powerful in your trading decisions?

I am pretty sure this won’t work, but I can’t stop now.

Trading based on statistics

In the never ending search for an edge, sometimes looking at statistics can help. Below I have compiled a few simple statistics that I think might help.

The following statistics were gathered by looking at every stock that trades on the NYSE over the past 2 years. The reason I chose the past 2 years is because we have seen two important cycles during this period. The strong bull market from 2006 to mid 2007 and a strong bear market from mid 2007 till present. Having both of these cycles will allow us to draw more meaningful conclusions.

Condition Total Days UP Down
Baseline 1,383,838 50.32% 49.68%
Today Close < Yesterday’s Low 336,415 52.5% 47.5%
Today Close > Yesterday’s High 356,594 48.4% 51.6%
Today Close 2.5% > Yesterday’s High 47,062 45.5% 54.5%
Today Close 2.5% < Yesterday’s Low 50,706 52.2% 47.8%
Today Close < Yesterday’s Low AND Tomorrow opens higher than today’s close 167,614 67.1% 32.9%
Today Close > Yesterday’s High AND Tomorrow opens lower than today’s close 165,813 32.7% 67.3%

Important Results:
1. Anytime the market closes either up or down, there is a slight edge to the market closing the opposite way on the following day. I would imagine this is due to mean reversion.
2. The greater the move in one direction the higher the likely hood the next day will reverse.
3. Using tomorrows open to confirm the direction can improve results drastically.

The statistical edge for all of these are VERY small, but these statistics can still have a place in your trading tool box.

How to find a trading Strategy? Pt.3

In the last article How to find a trading Strategy? Pt.2 we saw that our entry pattern has a small edge over random entries. Even such a small edge, should in theory be enough to develop a fairly profitable strategy. Now we are going to look at a few ways we can improve this entry through the use of vairous filters. I am not a fan of using many filters. I like to keep the strategy as SIMPLE as possible. Once you add too many filters you normally just end up with a strategy fitted to the past data. So, for this project we will be looking to add no more than 1 or 2 fiilters that MAKE SENSE. That is important. Adding a filter ONLY because it improved the performance but for no real justifiable reason is a sure sign you are curve fitting.

Lets get started
First, before adding any filters we need to understand how our pattern entry works. This pattern looks for a time when the stock has been severly beaten down. The reason we look for this, is normally stocks do not move in a straight line up or down. There is a bit of mean reversion that takes place in any trend. At this point we have only been looking at the past 4 days with RSI(4) to see how much punishment the stock has taken. So, we make no assumptions whether or not the stock is in a long term up trend or long term down trend. As our results using the SPY and USO showed, it can profit under either condition.

This pattern is already picking entries that come after heavy selling. However, if we are going to buy here we would want as much of the selling to have already taken place as possible. So the first thing I decided to try was putting in the condition that the stock has closed down for all 4 of the days. This did not improve performance that much. Mostly because its a rarer occurance, and because 4 straight days down can be a signal of a more severe and longer term correction than what we are attempting to capitalize on.

Knowing the market’s tendencies
Next, I remembered that a statistical test I ran a long time ago showed a slightly increased chance that the next day would be an up day if today was down. So with this knowledge I decided to test adding a filter that said if today < yesterday then buy. The adition of this filter made a huge difference in both the PL chart and overal profit. Using the predefined time stops from the previous article and using RSI(4) <20 EVERY time stop produced a positive return greater than +$1000

Now with the adition of that one filter, the pattern produced positive results using 5,10,15,20,25, and 50 day predetermined exits. This is huge because now the entry method has a very substantial edge over random entries. Using just this entry pattern and filter we could move on and design our exit, but I think there may be more room for improvement in our entries.

What about an uptrend?
I figured if the slightly longer term trend was up then the pattern may have a better chance to succeed. I tried using moving averages to determine if the slightly longer term trend was an uptrend or not. However, the results showed no real improvement, infact results suffered. I did find that by using RSI(10) > 20 we got some decent improvement. For now I will include this filter in the entry, but I wont hesitate to remove it if I can prove that it only showed an improvement due to random chance. This should show up in a later article when we expand our testing to more securities. For now we are only developing the strategy on a few securities, so that we can verify its not curve fitted to this particular set of data in the future.

Here is what the current PL chart looks like using a 5 day hard stop on the SPY.  As you can see its pretty choppy. This is due to it having no meaningful exit strategy. SPY PL

Where to go from here?
Now we have a decent entry method, but our exit strategy is just a hard time stop. In the following articles we will explore different exit strategies we can employ. So far it looks as if we will have a profitable strategy at the end of all of this. However, its very possible we wont. Sometimes you succeed, but the majority of the time a strategy is a failure. If you want to see what happens next, Subscribe to my feed or check back in a few days for the article “How to find a trading strategy? Pt. 4

How to find a trading strategy? Pt.2

In the last article How to find a trading strategy? Pt.1 we found a potentially tradeable pattern. Before moving ANY further, we need to know if this pattern has an edge over random entries.

Testing Metrics
All trades will be for 100 shares. Using the commission structure at Interactive Brokers each direction will incur $1 in commission. Twenty cents worth of slippage will also be deducted.  For our pattern we will define an entry when RSI(4) < 20 and current position = flat.  We will also test a slightly modified version of our original pattern and do RSI(4)< 15.  The exit for both our pattern and random entry will be predefined time stops. For each time stop the random entry test will be run 5 times and the results averaged. The random entry will also be throttled to take approximately the same # of trades as our pattern. By running the test several times with different time stops, we should have a pretty good idea if the pattern has a true edge. One thing to keep in mind, is we are NOT looking for the pattern to be profitable using predefined time stops. Instead we are looking for it to perform significantly better than the random entries.

Results For Spy:

Time Stop Our Pattern < 20 Our Pattern < 15 Random Entry
5 Day -$1,006 +$955 -$3,424
10 Day -$1,347 -$4 -$2,505
15 Day -$559 -$325 -$2,229
20 Day +$830 +1,981 -$1,116
25 Day +$1,574 +4,150 -$1,523
50 Day +$255 -$173 +$189

On the SPY it appears this pattern has a slight edge over random entry. The modified version using RSI(4) < 15 had an even greater edge. However, as the time frame goes a bit further out to around 2 months we see that its conceivable that random entries could produce similar results. These results do give us hope that for shorter duration trades we may have an edge to further develop.

Next I tested on USO to make sure we were not just observing a lucky streak with the SPY. The one problem I had here is I only could get about 2 years of historical data. So unlike the SPY test, USO is tested on far less data.

Results For USO:

Time Stop Our Pattern < 20 Our Pattern < 15 Random Entry
5 Day +$2,191 +$1,997 +$922
10 Day +$1,445 +$1,113 +$862
15 Day +$3,561 +$3,830 +$2,830
20 Day +$4,496 +3,864 -$1,116
25 Day +$1,154 +1,743 +$765
50 Day +$4,590 +4,990 +$4,100

So what does this tell us? Well for one the USO has been in such a strong uptrend it doesn’t matter WHEN you buy you will make money. The second thing it tells us is that in every case our pattern entry beat the random entry by a small margin. This further confirms that the pattern has a slight edge over random.

Where do we go from here?

Now that we feel confident that we have at least a slight edge with the current pattern, our next step will be to expand on our entry signal. For example, we will try adding more filters and also look for ways to confirm the signal before entry.

If you want to see what happens next, Subscribe to my feed or check back in a few days for the article How to find a trading strategy? Pt. 3

Also feel free to post comments or suggestions on how to evolve this strategy.

How to find a trading strategy? Pt.1

It comes a time in every trader’s career, when you have to stop trading based on your gut, and start trading based on a sound strategy. In this article series, we will start with a basic observation, and try to develop a profitable strategy.

The first step is to look at several stock charts for a pattern.  For this article, we will develop a strategy based on daily charts. The first chart I pulled up was a daily chart of the SPY(S&P 500). One thing that jumps out immediately, is that the stock price rebounds when RSI(4) goes below 20. However, it appears the last signal given may have been a dud. Does this mean the observation has no merit? Since no strategy is 100% accurate, we can’t answer that yet.

SPY Daily Chart

Before moving ahead to the next stage, you should always see how the observation does under different market conditions. So, I started looking for a completly unrelated security.  Preferably something in a strong uptrend, since the SPY has been in such a severe down trend. This time I chose USO, which has been going steadily higher for months. The observations we made on the SPY chart appear to be holding up. One caveat on the USO chart, is the signals seem to be slightly early, but still good signals.

USO Daily Chart

We now have a promising observation, but we are far from anything tradeable. Next we need to backtest the signals to see how robust they truly are.

If you want to see what happens next, check out How to find a trading strategy? Pt.2

Alcoa Earnings Preview

Judgment day for the market is upon us. This afternoon after the market closes AA will kick off earnings season. The average estimate appears to be .66. The chart for AA looks horrible. The stock has been hammered the past few weeks, but so has the rest of the market. Is all the selling in AA justified, or just another boat sinking with the broader market?

In my Are we all doomed? article I predicted that the market is very close to forming a short term bottom and that I am looking for good beaten down companies to pick up. Whether or not the market is truly near a short term bottom will be affected by how AA responds tonight. Good earnings from Alcoa and the market may shake some of its pre-earnings jitters.

Applying my short term market model to AA I see that it predicts the next valley to occur around $30.86. The average margin of error using this model on AA is plus or minus $1.34. Given that the low today for AA touched $31.02 its very likely the low is in. Even if the true low is not in, I expect it to be a pretty safe trade right here. However, AA is a bit off its lows for the year. If it misses badly on the earnings, or the broader market continues to tank. Its very possible to revisit those lows.

Are we all doomed?

According to every market “guru” CNBC can find the world is either ending, or at the very least, wall street is crumbling.  I personally have no idea where the markets are headed. So, where does that leave us in our search for market riches?

We are currently down a good 21% or so from the S&P 500 highs, and out of the past 15 days, we have only closed positive by any meaningful margin 3 times.  This would lead most people to believe that a bounce is imminent.

However, rather than just “assume” we are due for a bounce because of oversold conditions, I like to consult my market models. According to my short term model the next valley should have been put in at $132.07 on the SPY. We can clearly see this was not the case. To better understand this prediction, you should know that this model is normally off on average plus or minus $4.34 when predicting a valley.  At the time of this witting the SPY is currently trading at $124.55 which means this prediction was off more than normal.

With this information, I am currently looking for good bargins to pick up in preparation for the next short term uptrend. Which, according to this model, should take us to around $133-$137 on the SPY.

Get our RSS Feed
daily in your inbox

Recent Posts

Sponsored

Categories

Meta