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.

Slope of Hope Humor Two (by Biffermas)

By -

My friends, you are a hilarious group of intelligent loonies, and I've really enjoyed getting to know you.  I feel at home here with the Slope comminity.

Note: I had an excellent soundtrack for this post, but Youtube flagged the video as a copyright violation. Lacking further time, I threw up (literally) some Bach.  Given the nature of this video, I suspect Johann Sebastian is turning in his grave!

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.

1937 vs 2007 Bear Market Correlation (by TheInflationist)

By -

This is our first post on SOH – hope this finds its way to fellow Slopers (Thanks Tim).

1937 vs 2007 fibonacci correlation by www.theinflationist.com
1937 vs 2007 fibonacci correlation by www.theinflationist.com

Although
the backbone of our analysis is NOT based on fibonacci numbers or
anything conventional, our analysis and comparison of 1937 vs 2007
produced uncanny results.

In 1937, DJI peaked at 194.4, bottomed at 98.95 and subsequent bear
market rally peaked at 158. So it dropped 95.45 points from peak to
bottom. Of this, the bear market rally regained 59.05 points
(158-98.95). The ratio of retracement 59.05/95.45 = 0.6186. For those
of you who are not aware of the principles of Fibonacci and its
application in trading, Fibonacci numbers are numbers where each one is
the sum of the previous two numbers. Read below for more details on
Fibonacci numbers. We arrived at this ratio inadvertently, without even
realising the significance of 0.618 until it was pointed out to us
.
Coincidental? Perhaps.

Regardless, we applied the same Fibonacci ratio to the current rally
in an attempt to see where this rally will peak. Based on the same
Fibonacci ratio, a peak of 11255 will produce the same retracement as
1937. This has to be a closing price, which means the high of the day
will probably hit 11300 for those trading with a sniper rifle (we prefer the shot gun approach!).

We are concern enough to scale back some of our additional shorts
opened Friday, to provide sufficient firepower to short 100% at 11300.
11300 appears high enough to wipe out the remaining bears in our camp
and provide the undoubted confidence in bulls. This would fit with a
"blow off" top we have been talking about. We will take the little
profits we have from our S&P shorts opened Friday. Also will look
into the weekly (or monthly if available) Binary Index trade for 11300
as insurance.

We have a busy weekend ahead so we will rush this analysis to print. We will add more to this as time permits so do check back.

Why compare 1937 with 2007 ?

For new readers, our attention focused on 1937 after we compared all
previous significant bear markets since 1929 and the Nikkei's 1989
(because of the similiarities in monetary policies quoted by many eg
"Mish" Mike Shedlock) – and found that 1937's chart looked identical to
the current. Check the full post here.

www.theinflationist.com
www.theinflationist.com

We then zoomed in on 1937 after noting the striking resemblance and compared with the current decline in more detail here.
We were not sure though, whether the current rally equivalent was at
point A or B (see below). We felt that if we were at point A, then that
would mean that we have topped at 10500, and to expect a pullback
before further rally to hit 11000 at point B. When news of Dubai
default came up, we thought "Perfect timing!" – and that it was going to be used as the "excuse" for
the expected pullback. That was not to be as markets resumed the rally
after the weekend to make higher highs.

1937 Crash Vs 2007 Bear Market

We then searched the web to see if anyone else saw this. We found
one – Louise Yamada. She tries to explain the similarities of 1937 and 2007 both
from a fundamental and technical perspective. Here is what she says about 1937 vs 2007
(2/5 videos)

Where to From Here ?

1937vs2007fibonacci2

Good luck to all.

———————

Fibonacci Numbers, Fibonacci's Golden Ratio

0

1

1

2

3

5

8

13

21

34

55

89

etc

The division of any two adjacent numbers gives the amazing Golden number e.g.
34 / 55 = 0.618

It is called the Fibonacci series after Leonardo of Pisa or (Filius
Bonacci), alias Leonardo Fibonacci, born in 1175, whose great book The
Liber Abaci (1202) , on arithmetic, was a standard work for 200 years
and is still considered the best book written on arithmetic. It was the
principal means of demonstrating and introducing the enormous
advantages of the Hindu Arabic system of numeration over the Roman
System. Leonardo's reputation amongst scholars was deservedly great. It
was so outstanding that King Frederick II, visiting Pisa in 1225, held
a public competition in mathematics to test Leonardo's skill and he was
the only one able to answer the questions (Huntley 158). Fibonacci
ratios occur naturally around us: width vs height of picture frames, no
of petals in a flower, etc (see the mystery of Fibonacci Ratio and Numbers)

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.