I analyze macroeconomic issues from a fundamental perspective, and I analyze market behavior from a technical perspective. Original macroeconomic analysis can be found here and both macro analysis and commentary can be found on my Caps blog. If you like or appreciate my analysis, please add yourself to my Following List
Showing posts with label Random. Show all posts
Showing posts with label Random. Show all posts

Friday, October 28, 2011

1000th post

This post is my 1000th post.

If you don't have anything of quality to say, make up for it in volume. That's my motto.

Or at least it would be, if I start having a motto.

Thursday, October 27, 2011

Randomly Useful: Fibonacci Ratio Table (Updated)

This is just a mostly trivial update to the original post: Randomly Useful: Fibonacci Ratio Table. Added another calculation variant to derive a few more ratios and to show the coolness of the Fibonacci relationships via the fact that they can be arrived at multiples ways.

And no, just adding 1 or 2 to a ratio is *not* a valid technique to derive ratios (and yes, I am speaking to all the knuckleheads who still use 1.382 as a Fibonacci ratio)

------------------------------------

Nothing Earth-shattering, but here is a nice little table of Fibonacci Ratios. I actually generated this table a long time ago (6 months?, 9 months? edit 10/27/11: Okay, lets just say a few years ago :) ). Anyways, I would sometimes come across lists of Fib ratios. But as a guy who wants to understand where things come from in the first place, that was very unsatisfying.

The are many ways to come up with Fibonacci ratios besides looking at adjacent Fib numbers. There is the exact equation, which gives you the main one (0.618 and 1.618). But the most clever way is as a system of linear equations (and since I love linear algebra, this is very cool). I was planning on writing a really detailed post of why I love phi and going on a geek trip using linear equations, like I did regarding e as with this post: Why e is the coolest number. But I decided to restrain myself this time :)

Anyways, here is the table. Have fun! :)

Tuesday, July 19, 2011

Why Using the MACD for Long Term Trend Analysis is Worthless

Again, apologies ahead of time for titling the post so stridently, but I wanted it to capture people's attention, in the same way as I wrote Why Arithmetic Stock Charts Are Worthless. And you will see in this post the exact same reasons exist for this argument as does the logarithmic vs. arithmetic price scale argument.

First, you have to read this post for all of the necessary background (Why Arithmetic Stock Charts Are Worthless). If you don't read that post then don't bother reading this post. I will do a quick summary as to why this difference is important, but I will not rehash everything.

I fully admit that I have been guilty of the sin of using the MACD for long term trend analysis. But I want to show you why I have abandoned it (and replaced it with a more appropriate indicator) for long term analysis.

First consider what the Moving Average Convergence-Divergence (MACD) is and how it is calculated (from Stockcharts)

Standard MACD is the 12-day Exponential Moving Average (EMA) less the 26-day EMA. Closing prices are used for these moving averages. A 9-day EMA of MACD is plotted with the indicator to act as a signal line and identify turns. The MACD-Histogram represents the difference between MACD and its 9-day EMA, the signal line. The histogram is positive when MACD is above its 9-day EMA and negative when MACD is below its 9-day EMA.

As such, the output from the MACD Indicator (both the MACD and the Histogram) is in terms of points.

Consider the following statement:

"The Dow moved 14 points!"

Is that a useful statement? No, it has absolutely no meaning because it has no context.

If the 14 point move happened when the Dow was at 100 (in 1928), then it was a 14% move (pretty significant). If the 14 point move happened when the Dow as at 14000 (in 2007), then it was a 0.1% move (pretty insignificant).

The absolute magnitude of moves (point moves) in the stock market are meaningless values. They are only meaningful when they are related to some reference value (converted into percentage moves).

Which as I said before: ALL GAINS AND LOSSES IN THE STOCK MARKET ARE EXPONENTIAL!! NOT ARITHMETIC!!.

So does that mean we should scrap the MACD altogether?

NO!

The MACD is an extremely useful trend following and momentum indicator, and is very useful in finding momentum divergences for short term moves (where the difference in price over the range of comparison is small).

The problem happens is when one uses the MACD to find divergences in moves where the difference in price over the range of comparison is LARGE. Then the same exponential issue shows up. Fortunately there is another indicator that serves the exact same function as the MACD, can still find momentum and divergences, has the same EMA input, but is instead expressed in percentage terms.

It is the Percentage Price Oscillator (PPO), (from Stockcharts)

While MACD measures the absolute difference between two moving averages, PPO makes this a relative value by dividing difference by the slower moving average (26-day EMA). PPO is simply the MACD value divided by the longer moving average. The result is multiplied by 100 to move the decimal place two spots.

To illustrate why this is a big deal, and why using the MACD instead of the PPO to find divergence in long term trends (where there is a large price change between the two comparison periods) is incorrect, see this example chart:



As another example of looking at indicator behavior in percentage terms, see this long term study post of mine: First Derivative of the S&P 500, Long Term Study

Conclusion

All moves in the stock market are exponential/logarithmic, not arithmetic. Which means that not only do we need to look at price scales in logarithmic terms (so that we can do percentage comparisons not point comparisons), but also make sure our indicators also reflect moves expressed in percentage terms. This is not as critical when the difference in price between the two comparison points is small, but is absolutely critical when the difference in price between the two comparison points is large.

Monday, February 14, 2011

Who? Who does not want to wear the ribbon?!!

Nothing particularly predictive or useful here. Just having fun playing with MA ribbons. This is really just a bit of (ch)art. :)

Wednesday, June 9, 2010

Randomly Useful: Fibonacci Ratio Table

NOTE: Update here -- Randomly Useful: Fibonacci Ratio Table (Updated)

Nothing Earth-shattering, but here is a nice little table of Fibonacci Ratios. I actually generated this table a long time ago (6 months?, 9 months?). Anyways, I would sometimes come across lists of Fib ratios. But as a guy who wants to understand where things come from in the first place, that was very unsatisfying.

The are many ways to come up with Fibonacci ratios besides looking at adjacent Fib numbers. There is the exact equation, which gives you the main one (0.618 and 1.618). But the most clever way is as a system of linear equations (and since I love linear algebra, this is very cool). I was planning on writing a really detailed post of why I love phi and going on a geek trip using linear equations, like I did regarding e as with this post: Why e is the coolest number. But I decided to restrain myself this time :)

Anyways, here is the table. Have fun! :)

Friday, December 25, 2009

Merry Christmas and Happy Holidays!

Merry Christmas and Happy Holidays to all!!

Monday, December 14, 2009

Time For a Craft Break

With Conan O'Brien and Martha Stewart. This is a very old one, but I am still amused by it.

Why am I showing you this?

Why not. That's what I say. Is Minor Wave B done, are we in Minor C? Is it an Ending Diagonal? I don't know. And here's a hint: neither does anybody else.

So lets take a little amusement break and hopefully we will get some resolution (either a breakout or a breakdown) on our current trading range that we have been in for the past 4 weeks.

Enjoy :)

Monday, November 23, 2009

First and Second Derivatives of the SPX

Here is another off the wall post that will produce a few more interesting
observations. Please see my last post Recipe for Disaster to see where this train of thought came from and I will be linking some conclusions together between this post and that one.

First, what the hell is a derivative?

Maybe you are familiar with this concept on calculus and maybe not. Here is the real background if you are interested (http://en.wikipedia.org/wiki/Derivative), but here is the 1 paragraph version that gives you an understanding for this post.

A function is a description of how a dependent variable (lets call it y) moves with respect to an independent variable (lets call it x). A straight line is a very simple example: y = slope*x + intercept. Or a parabola: y = x^2. A derivative tells you the instantaneous rate of change of that function as x changes. It is also the slope of the function, but rate of change is the key concept. A straight line is always changing at a constant value, hence its derivative is a constant number. The parabola has a negative slope for x < 0, has a slope of zero at x = 0, and has a positive slope for x > 0. The second derivative tells you the rate of change of the first derivative.

Okay, that was a bit abstract. So lets use a physical example. Position (or displacement) as a dependent variable tells you where you are with respect to time, the independent variable. The first derivative will tell you the rate of change of position with respect to time. This is the velocity, or speed. Everybody is familiar with this concept. The second derivative will tell you the rate of change of velocity with respect to time. This is the acceleration. Another familiar concept.

Now lets apply this concept to the stock market. I will specifically be using the S&P 500 here. The price is analogous to the position, and we will look at the first and second derivatives of price, to help us to understand the behavior of how the price is changing with time.

First, here is the chart:



The price of the SPX is at the top of the chart in pink (I adjusted the left axis so the price would reside above the velocity and acceleration curves so that the chart would be more readable).

I did not calculate the velocity directly from the price action. It is too chaotic and would give just a big mess. So I calculated the 10 day Moving Average of the price (based on closing prices) and determined the velocity of that curve. For an additional bit of "smoothing" I am also plotting the 10 day MA of velocity just so the trend is a bit clearer, but I am working with the velocity as described above. The acceleration is calculated directly from the velocity, but I am also plotting a 10 day MA for the acceleration so you can see the trends (since it is also very spiky)

As a side note, the ROC (rate of change) indicator on Stockcharts gives you very similar "velocity" information. I am showing the data plotted myself since I am going through a more in depth study.

Important observations: The middle of last year was the market crash. This is by far the most important price action element on the 2 year chart. The move down was a violent freefall and you can see the associated velocity spike.

When I think about this move and try to assign it a physical corollary, I think of a football kick. A football is initially at rest and then the kicker kicks the ball to put it on its parabolic trajectory toward the goal posts. But what is of interest here is the dynamics and forces right at the time of the kick.

This system can be modeled as a first order Ordinary Differential Equation with a prescribed velocity as the initial condition. And for those who have done first order and second order ODE modeling of physical processes, the disturbance perturbs the system which has natural damping to return it to an equilibrium position. The response is always an exponential function (e^-j*omega*t) or (e^-omega*t) depending on if you are underdamped or overdamped.

The point is that an exponential decay envelop tells you how the response will change over time. And so when when I look at the velocity, I am able to fit an exponential decay envelope very nicely over the peaks.

This works very well describing the velocity behavior from mid last year to mid this year.

The last couple of months up to Now is where things get very interesting.

So for a physical system, the vibrations damp out to zero as time increases. And for very big disturbances, I would expect the market to behave like a physical system (it has mass, inertia, capacitance, etc. Tastylunch and I have had long conversations about this http://caps.fool.com/Blogs/ViewPost.aspx?bpid=127072, comments #39-43). The are places where these analogies do not work, but you can get a surprising amount of insight into monetary policy effects and assets price responses if you look at them as signal functions.

So the current large wave up (Primary 2) is a mechanism by the market to dampen out the oscillations caused by Primary 1 (the wave down last year). And from the decay envelopes above, you can see it was doing exactly that. But now the oscillations have begun to increase again. They are no longer being held in by the decay envelope.

And this goes directly to the observations that I made in my last post Recipe for Disaster. The market internals (and breadth is by far the most important internal measure) are becoming more violent up and down even as the price action narrows and starts going sideways / slightly up as it has the past couple of months.

This lets you know that there is a lot of turmoil beneath the surface and another large "step function" in price change is about to occur. Will it be a crash up or a crash down? I obviously have my opinion on the matter. For those who are interested in my opinion, please read this post: My Positions and Projections

But the real point of this post and the last post is to show that things are not as calm as they might appear on the surface.

Recipe for Disaster

I have worked a bit with Control Systems. I am by no means an expert. But the market right now looks to me exactly like an unstable control loop. For a little background on what I am describing, please read this post Why e is the coolest number and especially read the part at the end regarding LaPlace Transforms and integral convergence with respect to control systems.

But let me distill down a few concepts in controls. The first is a feedback loop. Whenever you have an input into the system (such as the the control stick to move the ailerons on your airplane), you want the actuator and the system to respond in a stable way. By this I mean when you move the stick to bank left or to pitch down, the actuators controlling the ailerons should move in a way that causes that movement and nothing else. They are two big exceptions that occur that cause big problems that aircraft designers need to avoid. The first is aileron reversal. This happens when the flutter speed is exceeded and the control surface (aileron) no longer can maintain aircraft orientation. Below the flutter speed the controls work normally, near the flutter speed the ailerons do not respond to inputs. Past the flutter speed the ailerons go into reversal, which means that a left bank on the control stick turns the airplane right. This is a catastrophic scenario to be avoided in the operating regime.

The next is oversteering. This is when your control surfaces give you too much movement and don't return to an equilibrium state on their own. If you pull up on the controls and the aircraft pitches up much more than you intend and you overcompensate by immediately pitching down, and again the controls are too strong and the aircraft pitches down too much. This is an example of runaway positive feedback. I saw one a video of a pilot landing an experimental aircraft that had exactly this problem. The ground effect as the aircraft was coming in for a landing was overwhelming the controls a producing a positive feedback. The aircraft oscillated wildly up and down just a few feet off the ground before crashing and skidding on the runway. Fortunately the pilot was safe.

The point is that control systems must be defined very carefully and that runaway positive feedback is detrimental to a control system.

And we are seeing perhaps some runaway feedback in the market right now. The bulls are getting uber-bullish and the bears are getting uber-bearish. On each large wave down bearish breadth is increasing, and on each bullish wave up bullish breadth is increasing. This has been happening over the past few months and prices are mostly sideways / slightly up. See the chart below. Look at the breadth right below the price (green and orange curves with the green and oragne trendlines)

How does this resolve itself. One word .... badly.

Monday, November 9, 2009

Why Arithmetic Stock Charts Are Worthless

Apologies ahead of time for titling the post so stridently, but I wanted it to capture people's attention. I have seen a lot of different charts on a lot of different blogs and some use Arithmetic (or Linear) Scale Price Axis charts to a) make counts and (more dangerously) b) draw trendlines on them. I disagree with this pretty vehemently and I wanted to share why.

You may have thought about this before, or you may have not. But I will invite you to do so in this post. "But a chart is a chart, right? An axis is an axis right? As long as it has all the data, you're good.... right?". This is not the case.

I am an engineer. I primarily perform thermal and structural analysis in the Aerospace industry. And it is critical to my job when analyzing and trying to comprehend data that it be viewed in the proper context. For example when looking at vibration test data, I look at Frequency Response vs. Frequency or Power Spectral Density vs. Frequency on a Log-Log plot. Same with Fatigue data (S-N curves). An Electrical Engineer looking at the band pass characteristics of a circuit would look at the signal response on a log-log plot.

Looking at any of this information on the wrong scales will improperly exaggerate signals at the top end of the axis and *hide valuable information* at the lower end of the function axis.

--- IMPORTANT NOTE / CLARIFICATION ---

** There is an exception to this general statement that arithmetic charts are worthless. It is the crux of Gann's analysis, and arithmetic charts are critical to this analysis. Because there is a *very* specific way you must set up your templates to make them work. And when you do, very specific angle relationships show up that otherwise won't.

But in general an arithmetic chart with no special format will not give you proper relationships on a trendline analysis, and per my reasoning and logic exercise below, I argue that it is invalid.


---------

So first some terminology:

1) Log-Log Scale: Both your horizontal and vertical axis are logarithmic
2) Log-Linear (or Semilog) Scale: One axis is logarithmic and the other is linear / arithmetic. For the purpose of this discussion regarding stocks, the vertical axis (price) is logarithmic and the horizontal axis is linear
3) Linear-Linear: Both axes are linear. This is they way most people generally think about graphs (temperature vs. time, for example)

We will focus on Scales 2) and 3) for this discussion (obviously, log-log stock charts are not very meaningful, since the date is a linear set)

-- Log-Linear vs. Linear-Linear Charts to plot exponential functions

Now I use this word logarithmic a lot. You may be familiar with it or not. But in this context, substitute the word "exponential". They have the same connotation here. An exponential growth in population. Cell-division is an exponential process. Everybody is familiar with this concept. Stock price movement is also exponential, but more on that in a moment.

So lets say I had some initial value of, I don't know, rabbits. And lets say that every year, the population of rabbits would grow by 60% of the previous year's value. What does this look like on the two scales?



What is the important observation here?

On the Linear Scale chart, you have an exponential data set that looks like a parabolic run up. But on the Log Scale chart the data set is a straight line!!. This is why looking at an exponential data set on a log chart gives you so much insight into the behavior. Straight lines on a semilog plot are lines of "constant exponential growth" and the growth percentage is directly related to the slope of the line.

-- Stock Price Movement is Logarithmic

Stock price movement is logarithmic / exponential. Sorry, this needs to be emphasized. ALL GAINS AND LOSSES IN THE STOCK MARKET ARE EXPONENTIAL!! NOT ARITHMETIC!!. To see why, consider this example:

Is a 200 point move equivalent to any other 200 point move? NO. If 200 point move A occurs when an index is at 4000 (5%), it is much less meaningful than if a 200 point move B occurs when an index is at 500 (40%).

This is why linear scale stock charts are almost meaningless.

Because we don’t measure stock performance on an absolute basis, we measure it on a RELATIVE basis. A 50% gain is a 50% gain. Whether you bought a stock at 10 and it moved to 15 or you bought the stock at 1000 and it moved to 1500. This makes all gains and all moves in the stock market exponential / logarithmic.

Stock data on a linear chart improperly exaggerates the importance of moves at the top of the chart and improperly diminishes the importance of moves at the bottom of the chart!!.

For the clearest example of this, lets look at the Homebuilders Index (XHB). As we all know, Home Builders have taken a thrashing the last few years. In fact XHB went from 45 at its peak down to 8, that is a drop of 82%. So, a move of 4 points when XHB was at 8 is a 50% move, whereas a move of 4 points when XHB was at 45 is a 9% move. That is a big difference!!. So how different does XHB look on a linear scale vs. a log scale? You bet, very different!:



On the Semilog (above), everything looks fine and normal.

On the Linear (below)... not so much. Read the notes on the chart.



-- The Problem with Trendlines on Arithmetic Charts

Okay, so here is where I show some problems with trendlines. Now before we get into this, the first thing you are going to think is "I see trendlines and channels get respected on arithmetic charts all the time!". And my response will be "Yes, you do" .... with a big caveat.

On small scales (relatively little difference in the max and min values on the y-axis), maybe less than a 10% difference between min and max, it is little matter if you use linear or log. You will see effectively the same chart and it will respect the same trendlines because of the only minor difference in scale.

The problem exists in charts with a large difference between the min and max value (such as the XHB example above). This is because price moved very quickly or it is even more compounded when there is both a large price difference AND a large time difference.

What am I getting at? The "Great Bear Trendline" that you see all over the place. Here is is for the SPX on a Semilog



And here it is for the Linear Scale. And I posit that it is wrong. Read the notes on the chart.



-- Conclusion

As always, this is just my take. There is no commandment handed down from on high stating “Thou shalt use log scale stock charts”. But just an exercise in logic, as I went through above, shows that this is a pretty obvious conclusion. But as an analyst and reader, you need to make up your own mind about this.

Thank you for listening to binve's Chart Analysis Public Service Announcement :)

Note 1:

I went through a similar exercise, not as focused as this one, about 6 months ago in this post

Saturday, September 19, 2009

Why e is the coolest number

Adapted from my original post here: Why e is the coolest number - June 18, 2008
----------------------------

Okay, this is obviously not going to be a blog about stocks or Elliott Wave counts. It will be about investing only in a very general and relatively abstract sense. But growth (and more importantly exponential growth) is why all of us are investing in the first place. And it is interesting to think about the fact that all exponential growth has its basis is one very cool number: e.

Why am I writing this? Who knows, binv271828 is a strange character [Note: My original Caps username is binv271828 and my new username in binve]. I really wanted to share why I like the number e so much that I did put it in my name and why it is related to investing.

Let me warn you now that there will be a lot of ideas, mostly math based and some very uninteresting except to those that really like math. Please feel free to skip, and I won’t be offended :). So, it should be abundantly clear to anybody who has read my blog posts that I am a fairly large nerd. I like math… a lot. Numbers are cool. But the relationships between numbers and how they describe physical phenomena are even more interesting.

e is a number that describes a whole class of relationships like this. But if you read a math textbook or looked up e on wikipedia you would have no idea how universally cool it is. So here is the dry definition: e, also called Euler’s number, is a transcendental number that is approximated by 2.71828182845904523536. …. Okay, who cares. So here is some more dry definition: the mathematical constant e is the unique real number such that the function e^x has the same value as the slope of the tangent line, for all values of x. … again, who cares!

Okay, lets see why e is so cool.

Everybody is familiar with compound interest. You begin with a starting amount of money, and then you earn interest. The next period you earn interest on the principal + interest from the first period, and this continues until you are rich!

So lets say you have an account where interest is calculated once a year. So the growth comes in yearly chunks. If you start with $1 and you get an interest rate of 100%, then at the end of the year you will have $2 (the interest earned on 1$ with a rate of 100% is 1$, and $1 + $1 = $2). Well, what if interest was calculated once every half year. Then that means after 6 months you will earn $0.50 (100% interest for half a year, or 50% earned on the $1) for a total of $1.50, then at the end of the next 6 months, you will earn interest on $1.50. This interest is 50% (for half a year) to give you $0.75. Add back to the $1.50, which gives you $2.25. Right on, so calculating in more intervals gives you more money. So now you have 2 payments instead of one step at the end of the year. Next imagine the interest was calculated once a month, or once a day or once an hour or once a minute or once a second or once a nanosecond…. What this does is to increase the number of steps, which makes your growth curve “smoother”. Eventually with an infinite number of steps in which your interest is calculated, your interest growth will represent a continuous curve.
That is an interesting relationship. And this relationship can be expressed as: (1 + 100%/n)^n where n is the number of steps taken. So lets list this relationship for an increasing number of steps:













































StepsGrowth
12.0
22.25
32.37
52.48832
1002.59374246
10002.704813829
100002.716923932
1000002.718145927
1000002.718268237
10000002.718280469
100000002.718281694
1000000002.718281786
10000000002.718282031


And as you can see, the relationship begins to converge, and lo and behold, it’s e! So this is where e comes in, it is this idea of continuous growth.

What this actually is, is a limit. Okay, I am going to throw some calculus at you. e = limit as n goes to infinity of (1 + 1/n)^n. This is an exceptionally important relationship very useful in describing all kinds of phenomena, and has some very unique properties in relation to derivatives and integrals (more in a minute).

What is even more interesting is that if you start looking at any exponential relationship (interest calculated at interest rates other than 100%, population growth, cell division, bacteria replication, etc.) you can express it as function of e. Absolutely any exponential relationship at all. What this means is that every single continuous growth relationship in existence can be though of as a scaled version of e…. ! How cool is that!

So all of us are looking for continuous exponential growth in our portfolio returns :), e is always on our minds subconsciously.

Okay so that’s cool, so what’s up with all derivative and integral stuff? Because of the shape of this exponential curve and remembering the original dry wikipedia definition “the mathematical constant e is the unique real number such that the function e^x has the same value as the slope of the tangent line, for all values of x” an interesting property is discovered: The derivative d/dx (e^x) = e^x. This is very useful in casting functions for linearization.

Another concept as to why e useful is in the concept of imaginary numbers. It can be shown that e is actually a trig relationship (sines and cosines) in the imaginary domain. Now that is really abstract, but you can think of imaginary numbers as describing an oscillating signal or motion. Any motion that can be described as a magnitude and an angle or phase (such as a pendulum moving back and forth, a wing vibrating through the air, a cesium atom moving back and forth in an atomic clock) can be though of in terms of imaginary numbers, which then can be compactly represented in one number: e …!

e also has usefulness in integrals. Since e can represent imaginary numbers, it can represent any oscillatory signal. Any oscillating signal can decay (think of a bar door when you open it, rocking back and forth on its hinge until it eventually comes back to rest), stay stable or it can grow (if you are not familiar with the bridge “galloping gertie” check this out http://en.wikipedia.org/wiki/Tacoma_Narrows_Bridge and be sure to watch the video under the collapse section). So growing oscillating signals are bad for mechanical systems, like galloping gertie, and are also bad for electrical systems. Exponentially growing signals cannot be easily described since their integrals do not converge. So you cannot even analyze the effects of a system with a non-converging integral.

That is until you throw in some e! Since e is actually an oscillatory number, you can add a sufficiently large amount of negative e in order to force an integral to converge. This is the principle behind the LaPlace transform. Figuring out the size of negative e added can tell you something about the stability of a system, and is a very useful technique in controls.

e is just so cool!

Okay, okay enough geeking out. If you want to use e for some useful formulas for investing calculations, here are a few:

growth = e ^ (total rate * time)
annualized growth rate = e ( ln (total return multiple) / number years ) - 1
where ln is the natural logarithm (another cool relationship that is related to e).

If you also have a love of e, please feel free to share! If you have skipped everything in the middle and come down to the end, well I don’t blame you :)

-

For more reading on e, check out:
http://betterexplained.com/articles/an-intuitive-guide-to-exponential-functions-e/
http://en.wikipedia.org/wiki/E_(mathematical_constant)