Slope of Hope Blog Posts

Slope initially began as a blog, so this is where most of the website’s content resides. Here we have tens of thousands of posts dating back over a decade. These are listed in reverse chronological order. Click on any category icon below to see posts tagged with that particular subject, or click on a word in the category cloud on the right side of the screen for more specific choices.

C-P3-O (by nummy)

By -

Preamble by Tim that has nothing to do with the post: Several folks have written to me saying that they cannot post comments anymore, or that their avatar has disappeared. Some have even asked if I've banned this (which is peculiar, since the people writing are as nice as can be). First off, my frequency of banning is Virtually Never; perhaps two or three people a year. Second, I think Disqus is having some database issues going on that are affecting some users. Please know that I'm as eager for you to comment as ever, and that I haven't done anything on this end to squish your avatar or its wonder-twin powers.  If you're having trouble, please write them at help@disqus.com

Many of us are excited about the ever-elusive P3 wave down that would confirm this rally as a bear market rally.  Is this it?  If this is the start of P3, things can get nasty pretty fast and bulls are toast.  It may very well be, but the contrarian to my contrarian is molesting me.  What if this isn't it?  What if in the bigger picture, we are at the foot of another bull run?  I investigate what could happen (and has happened) if we really are in a new bull market (which I highly doubt).

Katzo  

First of all, I want to thank katzo for mentioning before that topping processes can be tough to swing trade and several times he pointed to the 2004 example where SPX put in a nice triple top and then corrected in a negative channel.  He has also been making some sweet calls this week, so thanks katzo!

When we look back at a chart from 2003-2004 and compare it to 2009-2010, the similarities are pretty surprising.

+ The first major move up from the March 2003 lows (almost to the freaking day) was topped in early 2004.

+ The wave structures look fairly similar.

+ The ranges are fairly similar.  In 2004, we topped around 1150 (like now).  However, March 2003 lows were 800ish.

+ After that "local top", we had two sequential days with moves more than 2sigma (1sigma = a standard deviation) to the downside.  To give you an idea, a 2sigma event occurs approximately once every 44 (trading) days (~2 months).  The chances of getting 2 sequential 2sigma events are one in 1,936 (trading) days (~7.7 years).  If you'd like my standard-deviation TOS script, Download MyStdDevSTUDY.

-We arrive at a similar trendline in both cases.  In 2004 we broke it and wiggled around it before leaving its vicinity.  Today, we are very close to breaking the analogous trendline from 2003-2004.

0304comparison

So if P3 is bogus, we could see similar action to 2003-2004.  We have seen so much similarity so far, so why shouldn't it continue?

But when we face the situation of fundamentals, aka reality, I laugh at the ridiculousness of the contrarian to my contrarian because the economic situation today is nowhere near what it was in 2003-2004.  A correction is starting and a sideways-ish mildly negative-sloping channel correction is all the bulls can hope for if this isn't P3.

Bolling for Soup (by nummy)

By -

So, for at least the past 4 weeks, SPX has maintained itself in a 35 point range.  What this has done to band systems like the Bollinger Bands (red) and Keltner Channels (yellow) has set us up for a fairly rare occurrence.  Firstly, the Bollinger Bands width (upper band – lower band) has dropped below 30 SPX points.  This hasn't happened for several months.  Secondly, the Bollinger bands have turned fairly flat.  Lastly, the Bollinger Bands (BB) have worked their way inside the Keltner Channels (KC).

2009-12-12-TOS_CHARTS_01

A good question is, how can one quantify this to look for a similar situation that has occurred in the past?  Ideally, we would like to see where this has happened in the past, and look at the result for clues as to what could happen in the present.  We could do this visually, but it would take a lot time staring at charts.  I will briefly go through how to develop a simple thinkscript indicator to indicate when this situation is occurring.

Firstly, it is fairly easy to check the BB band width.  You just subtract the LowerBand value from the UpperBand to get your width.

Secondly, to describe the flatness of a line, we want to use a derivative, or difference.  If we take the current upper band value and subtract the upper band value of the previous candle, we get the slope of that line.  In the chart above, what is in the lower portion of the chart are the derivatives of each band (upper BB', lower BB', upper KC', lower KC').  We want to find a time in the past where the derivatives are close to 0, implying BB/KC flatness.  We don't really care whether the slope is negative or positive because, since they are so close to 0, they imply flatness.  In order to disregard the sign of the derivative, we can use the AbsValue() function and compare it to a threshold to determine flatness.  Here is some pseudo-code for what we would be looking for:

AbsValue(UpperBBSlope) < threshold and AbsValue(LowerBBSlope) < threshold and 
AbsValue(UpperKCSlope) < threshold and AbsValue(LowerKCSlope) < threshold

If we look at our current BB/KC slope values, we want to check that the AbsValue of the current slopes of upper/lower BB/KC lines are less than a threshold, say, 2.5.  Then, we also want to check that we have been flat for some time.  To do this, we can verify that the slopes of BB/KC lines of the last three periods are less than another threshold, say, 1.  Please note that these thresholds are only applicable to the scale of SPX.  In SPX, the BB width is about 30 SPX points while in SPY, the BB width would be about 3 SPY points.  These thresholds must be adjusted in the code if you intend to use this with another ticker symbol.  If you were going from SPX to SPY, you could multiply the threshold and BB width by approximately 1/10 (since SPY is approximately 1/10 of SPX).  All this checking of band slopes is doing is making sure we are near 0 for the past 4 candles.

Finally, we want to check that the BB is inside the KC.  This is also fairly simple, we can check that UpperKC > UpperBB and LowerKC < LowerBB.

Now we have all of our conditions to give us a signal:

1- BB width is less than or equal to 30 points
2- AbsValue(UpperBBSlope) < 2.5 and AbsValue(LowerBBSlope) < 2.5
3- AbsValue(UpperKCSlope) < 2.5 and AbsValue(LowerKCSlope) < 2.5
4- AbsValue(UpperBBSlope[1]) < 1 and AbsValue(LowerBBSlope[1]) < 1
5- AbsValue(UpperKCSlope[1]) < 1 and AbsValue(LowerKCSlope[1]) < 1
6- AbsValue(UpperBBSlope[2]) < 1 and AbsValue(LowerBBSlope[2]) < 1
7- AbsValue(UpperKCSlope[2]) < 1 and AbsValue(LowerKCSlope[2]) < 1
8- AbsValue(UpperBBSlope[3]) < 1 and AbsValue(LowerBBSlope[3]) < 1
9- AbsValue(UpperKCSlope[3]) < 1 and AbsValue(LowerKCSlope[3]) < 1
10- UpperKC > UpperBB and LowerKC < LowerBB

Note that UpperBBSlope means the current slope of the upper BB while UpperBBSlope[1] means 1 period ago (and [2] for 2 periods ago, [3] for 3 periods ago, etc.).  We can combine this into an if statement in thinkscript and check that all conditions are met.  Again, in pseudo-code:

if condition 1 and conditions 2-9 and condition 10 are all true, return 1, otherwise return 0.

So our signal should be 0 all the time unless our conditions are all true in which case it should spike to 1.  To create this script, I used the existing BollingerBandsSMA and KeltnerChannels scripts that come with TOS.  I combined both BB & KC into one script, so I could use data from each.

2009-12-12-TOS_CHARTS_02

So above we have our signal.  Let's look in the past to find similar occurrences.  Look familiar?

2009-12-12-TOS_CHARTS_03

So, keep in mind this happened before in December 2005.   The candle action looks almost identical to where we are today.  Three white candles up and above the mid-lines of BB and KC.  Back in December 2005, SPX re-tested the lows of the range it had been in for about a month (like now) and made slightly new lows.  Will history repeat itself?  Probably not, but it would be nice to see a selloff into OPEX week for once.  So take away what you will from this past occurrence and keep in mind there is always the chance of a fake-out on a BB squeeze.  The bulls seem ready to take charge again and break the range to the upside, but a lonely bear can dream of a downside squeeze, right?

If you'd like, you can download the script here Download NewStudy7STUDY.

Neural Networks – Part One (by nummy)

By -

In light of Tim’s recent post on old school video games, the advancement in computing continues to amaze me and will probably continue to amaze at the same rate for many decades. Or not … because although sufficient enough to approximate, Moore’s “Law” has to hit a threshold eventually, no system is infinitely in perpetual motion because eventually you succumb to the laws of entropy. Anyway, I’d like to do a series of posts on neural networks. I’ll discuss a bit of history in this first post, and how we can apply them to a financial model that can efficiently estimate market movements.

In the late 1800s and early 1900s neural networks became a concept that tried to explain the functional behavior of the human mind. In the 1980s, the implementation of neural networks in computation experienced a boom with the rediscovery of a computable backpropagation algorithm. The idea of spontaneous order came about from Friedrich Hayek in 1950 suggesting that the brain behaves as a result of decentralized networks of simple building blocks we can call neurons.

Neuron


The mind can be essentially thought of as a network that processes multiple input variables in parallel. A neural network modeled in a computer does the same. Imagine a model of the market that can take into account multiple input variables and learn from itself. One of the strengths of NNs is the ability to find patterns and irregularities as well as being able to learn from the inter-dependence and correlation of all the inputs. Equivalent to a biological neuron, we can create an artificial neuron with a mathematical model.

Neuron_artificial 

This is the basic building block of a neural network, the single neuron. As with a biological neuron, your axon terminals are your n inputs. They have weights w_1 through w_n and transfer signals (or stimuli) u_1 through u_n into the neuron. The weights can be thought of as weights of “importance” to each input. The neuron takes into account the sum of the weighted inputs along with an activation function (in this case a step function) which triggers an output z.

Neurons can be organized in various network structures but for our purposes of financial modeling, I will only consider feed-forward networks and recurrent networks. Feed-forward networks just describe the flow of information. Information is fed forward from the input(s) to output(s). Recurrent networks are networks that allow for feedback loops.

Simple_nn

Let’s consider a simple NN model where we would like the output to be SPX daily. We consider the following three inputs to the model:

-Previous day’s EUR/USD exchange rate

-Previous day’s LIBOR rate

-Previous day’s SPX close

The hidden layer of the network allows the network to learn not only how the inputs affect the output, but how each input affects other inputs. This model would be recurrent since the previous SPX data is fed back as an input. Using MATLAB, you can setup models like this. You can run a NN training where it analyzes past data and tests its forecast performance. Suppose we have 1000 data points of each input. That means 1000 daily closes of the EUR/USD, LIBOR, and SPX. We can set aside the first 70% of the data points for the network to “train” itself and compute all the weights (or importances) of each input. The remaining 30% of the data points can be used as a way to backtest predictions against actual outcomes. The network can analyze it's error rate and re-trains itself if the computed weights are not optimal.

Nn_11_3_2009 

Here is a model I have used so far and takes about 2-3 minutes to compute on my iMac (Intel Core 2 @ 2.4GHz, 2GB RAM). The model is a simple one with SPX past data as the input … no other inputs. The dataset used is on the lower-right chart. This is SPX daily close data since the 1970s (maybe 1979? forgot exactly what year the data started). The first 80% of the data was used for the NN training. The remaining 20% of the data was used to forecast (upper-left chart). The error in forecasting is shown on the lower-left chart. The 2-day forecast made by the NN on 11/13/2009 is on the upper-right chart. The model was saying we may get a slight drop the next day but after that, the trend was to change upward soon. I only chose to plot the output of two days because as you go out further in time, your error becomes exponentionally worse. Ideally, after each day, you would re-train the network so it is up to date with the latest data.

You can imagine a much more complex model with multiple outputs (SPX, Dow, Nasdaq, FTSE) and many more inputs (exchange rates, earnings, emerging market indices, volume, etc.). Other researchers have even used commonly used indicators as inputs to the NN model (MACD, RSI, moving averages, etc.). Increasing the inputs and hidden layers greatly increases the forecasting accuracy of the model while also increasing the computation time required. The computation required for this grows exponentially and you can start to see why the “little guy” is screwed from the start. The only way to profit 95%+ of each trading day with this type of computational edge is by an institution with large amounts of capital, a sick artificial NN model running on huge server farms, and direct fiber optic hookups into the NYSE for ultra-low latency. I am quite sure I don’t need to name names on this one.

In a David vs. Goliath attempt, I want to create a NN model with help from fellow Slopers. Maybe we can have some suggestions and discussions on what inputs ultimately affect the output the most. I don’t want to model something that would take days to compute on my iMac so maybe you can list your top 5 things you think affect SPX daily performance the most. Excluding the LDI (we love you Lester), here is my guess as to which inputs could be most influential on the outcome of SPX each day:

-LIBOR rate

-U.S. 20+ Year Treasury Bond Index (TLT)

-TED Spread

-Price of Gold

-Price of Oil

Welcome to Flight 1120

By -

"This is Co-Pilot nummy-nums here and I'd like to welcome you to Flight 1120 with Gold Man-Sacks Airlines where we not only get you there, but we teach you how to pray.  Please put your seat backs and tray tables in the full upright and locked position.  On our multi-day journey we will be cruising at an altitude of about 10,450 Dow points (or 1120ish S&P points) and if the turbulence kicks in, our cruising altitude may be up around 10,680.  In a little while, please don't forget to see the magnificent view on the left side of the plane of the Grand Canyon.  We will be offering the red pill or the blue pill again before landing.  We will be arriving in Honolulu at dawn.  Oh … and they don't know we're coming."

Short-term count of this last wave we've been experiencing. We could keep subdividing and I'd have to reconsider the whole short-term count if we keep blasting higher. But keep in mind, EW counts are usually wrong in the short-term and more accurate in the long-term.

Click on charts for hi-res.

Dandruff Shampoo (by nummy)

By -

I know some of you don't like Elliott Wave analysis, but I'd like to share a case in which EW seems to agree a bit with some technical analysis trendlines.  In lieu of recent bullish activity, I think we are starting our last ride higher (I know it feels like bears have been saying this forever).  If we get one last hurrah, I think it may be one of the greatest shorting opportunities in some time.  Keep in mind, I'm not claiming to be an EW pro or anything … my count is just one of the many out there.

2009-11-06-TOS_CHARTS_SPX

Here's what I'll be watching SPX for in the next two weeks (different paths we could take are denoted by p1, p2, …):

  • (p1) We could go up to the 1075-1080 range and form a right shoulder of the classic H&S pattern (with 1100 being our head and 1080ish our shoulders).  This would truncate 5 of (C).
  • (p2) We could float a bit higher to 1100 to form a double top.  Note that in a linear scale (chart is log), the 2007/2008 trendline stops us at around the 1100 area.  Personally, this would be my favorite scenario.  This would also truncate 5 of (C).
  • (p3) Let us not forget what happened in July, the H&S that broke the neckline only to zoom back above it.  If this happened again, 4 of (C) would be that failed neckline break and end later, rather than having ended this past Monday.  I consider this path the least probable.
  • This fifth wave could very well turn into a behaviorally greedy one characterized by a rapid rise into OPEX, followed by a rapid decline.
  • (p4) The next important level is the 1120 region.  Here lies the 50% retracement for SPX from the October 2007 highs to the March 2009 lows.  This would be another good place to turn back down and create a new head of a H&S pattern (meaning 1100 is the left shoulder).
  • (p4) The last levels to watch would be the 1140-1160 range.  Here, we have some things converging into these price levels:
    • We would be testing the 2007/2008 trendline (in log scale) around the 1140-1150 range.
    • The maximum for 5 of (C) so that 3 of (C) is not the smallest is 1152.23.
    • At 1158.76, (C) of [2] would be equal in length to (A) of [2].

Some of you may look at 3 of (C) and notice that [i] and [iv] overlap.  According to EWP (Elliott Wave Principle by Frost & Prechter), this can happen in the case of an expanding diagonal (blue trendlines).  All in all, we are still looking at the end of primary wave [2] (if that hasn't happened already).  Any upside left has its days numbered so I am watching the following levels on SPX to short on this leg up: 1075-1080, 1100, 1120, and anything in 1140-1160, if we get there.  This market is very vulnerable; one sneeze could start a waterfall.  I think in the intermediate-term, there is more risk in being long than in being short.