Thursday, August 19, 2010

21. The (spectral) momentum (or trend) and its acceleration. The 6 basic elements of the momentum (trend) and the 3 measuring methods.

Here is  a suggestion about how to measure in a simplest way the momentum and acceleration in a
spectral-like way in other words selectively sensitive over particular (rainbow) frequencies.

Suppose we want to measure the momentum and acceleration over the frequencies or periods 2*n1, 2*n2, 2*n3,...,2*nk

Then way take the moving averages MA(ni) with periods ni= n1, n2,...,nk respectively

and we combine them as a new weighted average

specMA=a1*MA(n1)+a2*MA(n2)+...+ak*MA(nk)
a1+a2+...+ak=1.
If n1=n2=...nk, then we get measurement on a single frequency.

It is not very practical to use too many frequencies on the same chart, I would suggest 3 at most 4.
e.g. n1=2*N , n2=N, n3=N/2 , n4=N/4, where N is particular rainbow frequency.
Or n1=N1, n2=N1/2, n3=N2 ,n4=N2/2 where N1, N2 are two rainbow frequencies withing the normal range of a single chart.

As weight we may take ai=1/k (all weights equal, no weighted average) or if we want to put more weight to the faster moving averages according to the period then

weights ai=(1/ni)/((1/n1)+(1/n2)+...+(1/nk))

or arbitrary user-interactive weights

So we have defined a spectral smoothed price position

This procedure is under a general approach to utlize weighted average to synthesize
a single meta-indicator from many primary indicators for easiness of monitoring and for reducing complexity.
There are of course other ways to synthesize in to single indicator from many indicators based on logical conditions also.


For the momentum we may take simply the MovingAverage(of specMA ,over period m)-specMA

in other words a classical cross difference of the curve with a moving average smoothing of it. We may prefer m=min(n1,n2,...nk)/2 , for more stable signals.

For the acceleration we may take a OsMA(specMA,l2,l3) of it, in other words a moving average oscillator , but not with a l1 moving average as input, but as input the specMA curve and l2 and l3 smoothing moving averages of it. Better also chose as l2=min(n1,n2,...nk)/2 and

l3=min(n1,n2,...nk)/4 or l2=max(n1,n2,...nk)/2 and  l3=max(n1,n2,...nk)/4


We may want to display the spectral acceleration as a histogram in a separate window with 4 colors above zero and increasing, above zero and decreasing, below zero and decreasing, below zero and increasing. This spectral acceleration involves the desired frequencies and shows hidden divergence for closing positions or starting stalking the market so as to open positions. The acceleration shows leading signals before the reversals

Of course it would be even better to use every where above that a moving average is applied (except of the weighted average from all the frequencies to the spectral position curve) the Hull Moving Average instead of simple moving average.


And of course there are plenty of different indicators that can be used that might measure the momentum and acceleration, if momentum reflects the 1st (or a low order) mathematical (stochastic) derivative, and acceleration reflects the 2nd (or higher order) mathematical (stochastic) derivative. It is better to apply first the smoothing and then the differentiation than vice versa.


If it is preferred a more scientific way to detect and forecast the momentum of the waving price pattern (see post 32) , then we may utilize a Fourier analysis or wavelets analysis.
For example see the indicators 
1) For wavelets analysis the sincMA indicator at  http://codebase.mql4.com/ru/968
2) For Fourier analysis the extrapolator indicator at  http://codebase.mql4.com/4990
Nevertheless, we must realize that in the Fourier analysis it is essentially utilized only one tonal frequency and period, and then all the others are harmonics of it.
If we want to utilize frequencies and periods that are not mutually harmonics, (as the rainbow frequencies ,see post 5) but independent tonal frequencies (e.g. 24 hours periodicity, and also 2.5 days , or 60 hours periodicity simultaneously) then we must superimpose the forecasting of the above extrapolator indicator, with an appropriate specially coded new indicator. I use such an indicator with up to 5 independent tonal frequencies or Fourier sample sizes. In this way we may represent the price movements with almost periodic functions, and utilize selectively few only periodicities (that may not be  harmonics between them) while with a single Fourier analysis we could never be able to do  so. The forecasting in this way, especially around the sessional action (8 hours-12 hours) is much better. The classical scientific tools, are good but not in the exact form they appear in books. It still requires talent and a better than the average understanding of the phenomenon, and the limitations and abilities of the tools.

We must add here that as the momentum (and speed) is not a deterministic but stochastic magnitude,
there are 6 elements of interest to measure and consider in decisions (risk metrics)
1) The signed intensity (the intensity separates a spike from a casual trend)
2) The volatility of it (or amplitude of an appropriate channel; It is relevant to the support-resistance levels )
3) The volatility dynamics of it ( if the volatility of it is increasing or decreasing, in other words if the   channels is expanding or contracting)
4) The phase (the position of the price within the boundaries of the channel, usually also the base for statistical hypothesis test decisions)
5) The duration or maturity (for how long the momentum or trend is going on. e.g. at what number of Elliot subwave we are in, Elliot-order. The decceleration too is an early indicative of the maturity)
6) The decceleration or divergence, and intensity of the acceleration (helpful to get signals prior to reversals of its sign, and to detect spikes)
To the above 6 we may add two more that is for smart traders: 7) The sessional phase relative to the 3 sessions 8) The position relative to the psychological levels xx00, xx50.

If we monitor two different time frames, a focal and a background, then a pair of the above 6 elements should define the state of the market. I have tried it, and it becomes quite complicated. It seems to me now that one time frame, the focal is adequate for all the 6, and the background time-frame only 1 or 2 basic of them. Even at one time-frame only, we may detect the trend on quite close harmonics around the focal frequency, and observe their resonance. Some interesting phenomena occur with the resonance of the sessional periodicities.

The best way to have all these 6 measures relevant to the stochastic momentum, is to utilise a channel, not just a curve, and channels defined by zigzags are preferred. This is the bottom-up method that we discuss below. A moving average as, a single curve, defines only the sign of the trend. (1 of the 6 elements). A channel e.g. the Bollinger Bands, can define 4 of the 6, the sign, the volatility, the volatility dynamics, the phase, but the maturity and divergence not. A channel defined by a zigzag can define all 6 elements of the trend!

The maturity of the trend is usually measured by the divergence or deceleration of its momentum, and by the Elliot wave order. My preference in counting the Elliot orders. 0,1,2,3,4 is by meorological metaphor: 0=Lighning, 1=Thunder, 2=Blow, 3=Wind, 4=Stream.
Statistically, the 1st Elliot wave, the Lightning is the strongest and usually (but not always) it is  a Spike, and the next ones are diminishing in slope and duration. That is why I usually prefer to trade the Lightnings, Thunders, and Blows more than the subsequent waves. Nevertheless some times a trend ends with an final spike (called exhaustion spike that might created also an exhaustion gap) before it reverses direction with a new retrace-and-more spike. The deceleration is utilized to assess the end or almost end of a trend (even though the momentum is still positive) while the acceleration is utilized to select only those trends that is anticipated to be stronger and longer lasting. The deceleration (divergence) and acceleration is detected with various ways, some static based on straight lines (pitchfork median lines, support-resistance break-outs etc), some dynamic based on ratios (e.g. volatility ratios, 2nd derivative ratios etc)



Most people think that it is enough to determine the sign of the trend each time so as to trade successfully. But it is not so. One has to determine successfully all the above 6 elements of the trend so as to trade successfully. There is also an important correlation among these elements. In particular there is correlation between the intensity of the trend and its duration. Both follow a Pareto or Power distribution with a longer tail. This in particular means that you can predict higher duration of the trend if it starts with higher intensity. In other words that longer trends start with spikes! This together with pyramiding along the duration of the trend (as optimal policy after the Pareto law of duration)  is the main key that can allow you a successful trading of high quality. A high quality successful trading is one that the average trade profit is higher or double that the average trade loss. And in its turn this requires setting stop loss less or less than half of the take profit, and trail appropriately.


Each of the 6 elements of the trend is a risk element too, so we may create an additive risk score to evaluate the overall risk at a situation. And by putting a priority order on the 6 elements of the trend, we may have a complete linear risk order on  all trend situations, even if two situations have the same additive risk score.

As there are many rainbow frequencies so as to measure the (stochastic) momentum (or trend or drift) this gives rise to mainly 3 techniques of measuring momentum (or trend)

1) The bottom-up method. In this method we utilize the measurement of momentum based on smaller time scale measurements of the momentum. (Assuming that we start with ticks towards say daily bars, the term bottom-up becomes plausible). A best example is to deduce indirectly the measurement of the momentum (or trend) from the divergence and slope of the channel of a zigzag of  the immediately smaller (rainbow) time scale. It is supposed that each vector of the zigzag is measurement of the shorter time scale momentum while, the zig-zag slope of the focal larger time scale. The theory of Elliot waves is mainly based on that. It is a very powerful method, that I utilize too in my practice.
2) The top-down method. In this method we utilize measurements at larger time scales to deduce the measurement of the momentum on the shorter focal time scale. Usually we have to take higher order derivatives (deltas or differences) of the larger time scale measurement of the momentum. A classical example is the Accelerator indicator of Bill Williams (AC) that is using horizons of 32 days and after higher derivatives it measures small micro-trends of 2-5 days.
3) The middle-out method. In this method we use many different measurements of the momentum with different tools and indicators exactly or almost exactly but quite close to  the required focal time scale (e.g. low order harmonics and subharmonics) and then we deduce from all of them, through an additive score (or through a conjunctive Boolean expression) the momentum of the focal time scale. This is a powerful method too, and if it combines acceleration and oscillators that give earlier signals of the reversal with other trend-following indicators that have lag at reversals we may get a pretty exact measurement for the momentum and is reversals at the focal time scale. As the middle-out technique focuses on the focal frequency and small local deviations of it, its additive score can be considered as an evaluation metric of the states of resonance at the focal frequency.

The above methods are not to be confused with the quite standard and successful practice of requiring that the momentum of the focal or tonal  time scale is not only the appropriate for a trade but also the same holds for the momentum in some larger time scales (background) and some smaller time scales (tuning). This latter technique could be called spectral-band momentum and is a different concept than the bottom-up, top-down ,and middle-out measurement of the momentum which is only of a single  time scale. The focal time scale is distinguished among the larger (background) and smaller (tuning) time scales by the average duration of the trade its average take profit and its  average stop loss.


If we measure the depth of the band-momentum with an additive score (the higher the score the more the time-scales that the momentum is of the same sign, thus another risk metric of the trend)) then we may want to condition and depend the other 6-elements of the momentum as risk metrics according to this score. E.g. we may want to allow maturity of the trend (for opening positions) only at very low Elliot order (early enough, low risk) if the band-score is low (high risk) , while allow maturity at higher order (higher risk) (permit late openings of positions within a trend) if the band-score is high (low risk). This is an example where we do not treat all the 6-elements and the momentum score as independent components but also as depended so as to be more flexible and allow more opportunities and less total intermittency in the trading. The idea is to assess the overall risk from each of the component risks.
That is all.


Monday, August 16, 2010

20. Composing market behavior from the 12 rainbow rhythms.

1) During 2001-2002 I was applying polynomial interpolation and trigonometric interpolation , and exponential interpolation, of paths of market's prices as a way of forecasting next steps. In general the polynomial interpolation forecasting was of positive feedback and good to forecast the trend pattern (see post 32)  (what was the previous move sign, was forecasted as the next move sign too) while the trigonometric interpolation was mainly of negative feedback and good to forecast the waving pattern (see post 32)  (the sign of the next step move was more often opposite to the sign of the previous steps move). These ware my first attempts to synthesise the markets movement through a large number of  base functions (e.g. trigonometric or cyclic functions). The trigonometric interpolation can be viewed also as the deterministic spectral analysis or Fourier analysis. There are many free online e-books of numerical analysis that have all the necessary formulae. All the above three types of functions polynomials, exponentials and trigonometric can be considered as the solutions of linear recursive systems (or even linear differential equations) by utilization of  the least squares method. It is called linear model as the forecasted values are a linear function of the previous values (although a non-linear function of time). I tried also wavelets and wavelets analysis. But the scientific tools do not give directly success, as they appear in the books, without an inspired modification, enhancement of them, based on deep understanding of the social or physical phenomenon under study.

2) Non-deterministic  stochastic spectral analysis is conceptually different as the Fourier transform and spectrum of a path of prices is understood as the sequence of autocorrelations of an underlying (stationary) stochastic process of many paths. Periodogram is the term that is used my econometricians. I worked with these tool from 2002 to 2003. The forecasting with such models is always with linear autoregressive linear  equations. I was using mainly the book by Lambert H. Koopmans The spectral Analysis of Time series
Academic press 1995. Another very useful book is by L.D.Lutes and S. Srakani: Random Vibrations
At that time I had not discovered yet that the market is vividly influence by cycles only at particular frequencies or periods, that I have tabulated in previous posts as the rainbow frequencies.


3) During 2001-2002, I worked also with models of Probabilistic  Linear Oscillations of Quantum Mechanics as stochastic process with very rich and interesting probabilistic structure compared to deterministic linear harmonic oscillations. In these models I was interpreting the probability density through the volumes of transactions of the prices. I found valuable information of numerical solutions of the probabilistic linear harmonic quantum oscilator and animated movies of it in the books: a) by B. Thaller Visual Quantum Mechanics, and b) by S. Brandt/H.D. Dahmen The picture book of Quantum Mechanics



4) After the discovery of the (12 for simplicity) rainbow frequencies, through spectral analysis, and other statistical tools, I conceived a new idea:
 I realized that I was interested in creating a universal model of behavior of the markets that would capture not all of the real behavior but only that which is rooted in eternal natural cosmic and planetary rhythms, and standard social evolutionary habitual rhythms. This was giving me a psychological security when investing or trading. In this way I would not need special cases backtests of models and the anxiety  that the model might not hold anymore. Non-repeatable news  effects and temporary fashions though mass media was not my target to capture, as they mainly create more chaos and shifting sands of forecasting, rather than adding real meaning to the financial developments. Instead I should incorporate (through the law 7 of compensation and law 9 of correspondence) the deeper laws of growth of financial organisations and domestic economies (fundamental analysis) through the Pareto distribution of average returns and volumes transactions in all the rainbow   time-frames and corresponding organisation scales.

My estimate was that this hidden regularity in the prices and volumes  (created  by the cyclic behavior of the physical and social world) would be more than enough to permit an abundant successful trading, with which I could apply the law 1 of elimination of household money (see the post of the 12 laws of the financial markets).
So I would leave some of the still intriguing behavior of the financial markets out! So what! The idea of the nature's cyclic behavior is simple, (almost emotional) and the model would be universal for all markets, securities (stocks), interest rates, commodities, currencies. In addition I would avoid the "over-fitted models". Such over-fitted models, are "animals" that live very efficiently in particular environments but as time changes, or if we change for them the environment they go extinct.

5) And this model I did create. I called it the Rainbow Stochastic Process of the global financial markets. Actually it applies to the growth of enterprises that may not be in stock exchange markets, and to the prices of consumer products too, so to the growth of the wealth of nations.
As I described in the post 5, while the cyclic behavior of some natural or social magnitude at a particular period, goes up, down, up, down etc, the effect in the prices was rather ups and downs in an irregular order, but all of average duration equal to the half-period or integer multiples of half-periods. I call such ups, and downs trend-vectors. The had the characteristic duration of a half-period and there could be runs of them (repetitions e.g. of ups  in sequence). And at each rainbow-color or frequency of the 12 one such stochastic process was defined called rainbow walk. By superimposing all 12 rainbow walks at the different periods we create all the market. So each rainbow-walk is not directly observable, as what is observable is the superposition of all of them at at any time step. (the time steps are those of the fastest rainbow frequencies).
I programmed this in VBA in MS-excel, utilising the in-built random number generator command. It took me some weeks to code it and a couple of years to test, elaborate, and study. This was from 2003 to 2005. At each rainbow frequency the user is defining 1) The trend-vector slope (in this way spikes of various orders can be included with their probability frequency) 2) The probability that the next trend-vector will be in the same direction or opposite (so trending or ranging markets are created) 3) Probability of intermittency, where no trend-vectors appear at all for some time 4) Correlation of higher volumes at the end and start of the trend-vectors. All the support-resistance levels are defined in this way as parallel horizontal levels and characteristic regularity at each rainbow time-frame. The slopes relative to the duration of the trend vectors, or in other words the amplitudes of the underlying yclic phenomena  among all the different rainbow frequencies were regulated by the law of correspondence by the rules of  n^(1/2).
The ability to define explicitly the above known phenomenology in the prices, was also a strong reason, to prefer as basic building blocks at each rainbow frequency the rainbow-walk stochastic process instead of a purely cyclical process.  Although the law 2 of transfer (see the 12 laws of the markets)  somehow creates correlations of the behavior between the rainbow walks of different frequencies, in the coded price generator, I programmed independence and simple superposition.
From the point of view of classical stochastic spectral analysis, I could obtain a similar result by assuming a (stationary) stochastic process with discrete spectrum at the rainbow frequencies, and narrow band continuous around the rainbow frequencies. It is proved in books of random vibrations that the effect of support-resistance boundaries of channels, appears for narrow band (stationary) processes and the distribution of the prices around the support-resistance is the Rayleigh distribution (there are also the rice formulae, and the cartwrite coefficient  that measure the degree of emergence of a support-resitance)

6) Once I had coded the rainbow price generator, my whole psychology of trading and attitude towards the markets changed. I was not feeling alienated anymore from the markets, as I had captured what I want from them, right in my computer and I could reproduce it indefinitely. So 50 years data could be relatively easily generated. Also I had to win in my own game, not the game defined my other people. Furthermore I could solve it and find trading systems and know also how optimal or sub-optimal they are, how complete for all market phases or how partial and thin slices of only of some of the phases of the markets are. In other words I could satisfy my scientific intellect and subconscious, and be able to know why it is possible to be a systematic winner, of how much , with what expected MaxDrawDown etc.Furthermore I could analyse any system or robot that I could find for free or buy in the web, and assess how good or bad it was, assuming that the markets behave as in the rainbow process. Most of the trading systems were obvious solutions if we assumed that  the markets behaved like the rainbow process. Rarely some of them contained very smart elements that led me to perfect or add a new feature to the rainbow process.
  I had to be sure of course that the rainbow price generator was realistic. I could configure it so that it becomes a pure random walk were there is no winning trading system ever, and I could configure it so that purely cyclic behavior occurs at each rainbow frequency (this would be a quite easy market to trade) or I could configure it in a realistic way, that it is as difficult to trade it as is the real markets. So I took winning automated systems that were know to be winning for 20 years or more, and I  applied them to the artificial prices of the rainbow price generator. The trading results were almost identical. Conversely when I devised a  winning trading system over the artificial prices, then I was testing it over real historical prices, and the results were almost identical.

7) It was 2004 and I was even thinking to put this price generator online for free for other traders to try systems too. Tradestation was quite expensive and not free. But then the Metatrader4 appeared in 2004, and more and more forex brokers allowed free demo accounts, so this became not so critical anymore.
8) So this is the 1st part of the story of what I did with the discovery of the characteristic frequencies of the markets. It is the part that describes the creation of the  universal model for the prices. The 2nd part is supposed to do with finding a relatively simple trading solution within such a universal model. The simplest of all is based on the fact that the volatility of the prices  and volumes of transcations do have direct (stochastic) cycles. So the easiest method is the volatility-short/volatility-long techniques. Although this terminology comes from the trading of options it is possible to create somehow artificial options with ordinary positions (even at forex). Examples of volatility-long techniques are the break-out methods, and examples of volatility-short techniques are the B. Williams angulation-counter-trend method or other counter-trend methods that focus on retracements of spikes.