Cycle measurement: the easy way
Results 1 to 10 of 310

Thread: Cycle measurement: the easy way

  1. #1
    Occasionally once you search what you find something else...
    I had been (and still am) looking for a good estimator of this trend. Without being a DSP ace, those played around with a few moving averages quickly realized that in the event that you want the outcome smooth you receive lag. You are able to remove the lag but you receive overshooting; that is as bad. To reduce the overshooting you return the smoothness. A vicious cycle with no escape. I'm no exception and my trend estimator suffers from annoying residual oscillations. Those oscillations are mainly because of the wide oscillations the price can make during explosive tendencies and throughout the wide ranges. In order to reduce the oscillations I wished to assess the cyclic components of the time series. If I can quantify it I could remove it. If I can remove it I could eliminate the oscillations.

    Let's see in picture exactly what I mean. Here is the kind of oscillations I'd love to remove:


    When the oscillations of this price are little enough the estimator absorbs them. However, if the amplitude of the oscillations gets larger they become a problem. To form this type of motion the market requires a while and therefore these oscillations can not have a too brief period. I target the oscillations of approx. 10 to 30 bars each cycle.

    If you're also looking for a way to estimate these cycles, you certainly have heard about the Goertzel algorithm. It's very exact but it requires three full cycles to discover the frequency it is tunned on. You're able to detect just one predefined frequency. You surely also understand John Ehlers' function, namely the double differentiator and the homodyne filter. The double differentiator gives an effect quickly but it overshoots in the frequency domain: the detection is quickly but... wrong! The homodyne filter lags 21 bars and if a bicycle is detected it has usually already gone. I tried Hilbert wavelet pair change (https://www.forexsoutheast.asia/gene...ity-check.html) but as a result of end of sample impact of this wavelet change I might just have lag and not-so-acurate dimensions.

    Here is a really easy solution
    I use a bandpass filter to the range of frequencies I'm interested in. This way I remove both the large frequency (sound ) and the trend, so that I will not need to detrend the samples to assess the cycles. I take the premise that there's just one single big cycle at one time in this range. This is not always correct.

    The output of this filter is approximately looking like a sine wave. I just need to take its Hilbert transform to assess the frequency, the amplitude and the phase (timing inside the cycle). The Hilbert transform of sin(x) is -cos(x). It occurs that the derivative of sin(x) is cos(x) that is the HT around the signal. The general form of the sine wave is A.sin(#969;t #966;-RRB-, where A is the amplitude, #969; is your frequency and #966; is your phase. The problem is that the derivative of A.sin(#969;t #966;-RRB- is A#969;.cos(#969;t #966;-RRB-. But we need A.cos(#969;t #966;-RRB-. The multipliive factor #969; isn't desired. We do not know the frequency since it is what we're trying the quote so we can not remove it. The integral of sin(x) is -cos(x) that is the HT. Computing the key of A.sin(#969;t #966;-RRB- we receive -(A/#969;).cos(#969;t #966;-RRB-. Now we have a factor 1/#969; to eliminate.

    I simply mutiply the derivative and the integral. I get -A²cos²(#969;t #966;-RRB-. Taking the square root of the total value (to prevent signal problem) I get |A.cos(#969;t #966;-RRB-| that's the HT up to the signal. But the sign is the same as the one of this derivative and nothing is missing.

    S = A.sin(#969;t #966;-RRB-
    D = dS / dt = A#969;. cos(#969;t #966;-RRB-
    I = #8747;S dt = -(A/#969;-RRB-. cos(#969;t #966;-RRB-
    D.I = -A²cos²(#969;t #966;-RRB-
    HT = sgn(D). #8730;|D.I|

    From the in-phase and quadrature I receive the amplitude A=#8730;(S² HT²) along with the phase using atan(HT/S) up to quadrant identifiion. Taking two sequential measurements allows to locate the frequency that's the derivative of this phase.

    Two small problems
    - The measured amplitude is bigger than the real one because the signal is taken following the bandpass filter. But knowning the frequency response of this filter we could fix the amplitude now we understand the frequency. A_price = A_measured/ / |H(#969;-RRB-|, where H(#969;-RRB- is the transfer function of this filter.
    - The signal isn't always made of one cycle along with the tip no longer works. The solution is to assess if the quote fits the few past samples or not.

    About the lag
    To get the results we need the key and the derivative of this signal output by the banbdpass filter and also the derivative of the resulting phase to get the frequency. The integration has no lag. The derivation has half an sample lag. We need another sample to assess the frequency. So we have one bar and a half lag on top of the filter. I use a brief IIR filter to get it as low as possible ! 1 bar. Clearly I get phase stimulation as the price to pay but I've near real-time estimation.

    And the result
    In red the output of this filter, in green the amplitude (not frequency corrected ) and in blue the instantaneous phase.


    I hope this little finding may help somebody.

  2. #2
    Quote Originally Posted by ;
    When you state lag, do you mean phase shift?
    By lag I mean what every trader at the forum understands: the delay samples (pubs ) between the input and the output. For instance 10 bars are lagged by a SMA20. I believe the worse group delay from the band pass because the phase response isn't linear.

    Quote Originally Posted by ;
    On your initial post you mentioned that your goal was to out the cycle and be left with this trend. So once you state a lag of 4 bars is a lot of, it sounds as if you're speaking about a systematic phase shift. If the method is to generate a sinewave equivalent into the cycle and subtract it from the data, that can readily be done without any phase shift. However, you would have to wait for enough of this wave to seem to be sure it was a cycle. Furthermore, your interval estimate would have to be extremely accurate, or the inaccuracy of this interval will probably...
    Substracting the most important cycle in the data is indeed the concept of this approach. I don't have a very acurate estimation of this interval. This is the major problem. As you can see in the post #4 the phase is absolutely not linear and the delay curve increases sharply from the frequency band of interest. Due to this very big incline a small mistake in the estimation of the frequency leads to a huge mistake in the determination of this lag. Because of this I cannot compensate the lag by advancing/backsteping the sinewave from the lag. This is why I try to get a very low lag so the mistake is kept small.

    Quote Originally Posted by ;
    I use a lag-free LPF into detrend data as a preparatory measure to cycle discovery. But data points at the right edge of this chart are always only approximations. In my job, the error that this poses is insignificant. The cycles expressed in this way are free of phase shift. However, you are not going to see instant results, it takes a few turns of this cycle to find reasonable estimates of period, amplitude and period.
    Goertzel filter gives similar results but I need the frequency stage amplitude almost realtime because the cycles are so short lived. Goertzel filter needs 3 periods of the cycle in theory but only 2 can already give a good result. Unfortunately some cycles simply don't last more than half their period. If I substract a cycle that's already gone I actually introduce a bogus one.

    Quote Originally Posted by ;
    Another thing is that the SNR of market data is reduced at the best of times. If your system can't stand up to 4 bars of lag, it sounds like it would also be overly sensitive to noise in the data.
    No as I said the very low lag is only required for the acuracy. The output is due to be fed into a kalman filter. The issue I have is that the cycles which are at the limit of this tendency wavelength create the KF oscillates (post #1) because it cannot decide if it is a trend or a range. Short and very long cycles are not any problem. If I had been interested in cycles of intervals of 10 bars and less the method would do the job flawlessly. However, I target cycles of 10 to 25 bars.

    If 8 bars of lag is acceptable for you wavelets are a good and fast alternative.

  3. #3
    Ah! The picture comes into focus. I don't have anything to indicate, ATM. It's unfortunate that market information isn't better behaved.

    A cycle to one trader isn't a cycle to another. In my world, a cycle isn't a cycle until it clearly goes ahead in time. I use three rotations to acquire initial measurements, then I wait and watch. If price data proceeds to follow the trajectory plotted ahead in time for that wave, then that is a cycle. If it doesn't then it never was a cycle, but merely a noise burst at a particular frequency. What I am looking for are cycles which have long lifetimes, they last for 8, 12, 20 or more rotations. Most bicycles in price data are just short-lived bursts, and that I do not know of any automated way to display them, it stays a manually intensive process.

    My current research management is in frequency elastic BPFs. I would like to have a spectrum of the price information, extract the dominant cycle and tune a BPF to that. Raw price information is far too noisy to get a Hilbert Transform to acquire a steady frequency estimate directly. Assessing the subject brought me to this thread. You have an interesting approach to cycle measurement, a bank of BPFs of the sort might do just fine. BPFs may not monitor a cycle nicely if its period strayed much, another approach that I am considering is Empirical Mode Decomposition. Do an EMD, then select out the IMF of interest (highest amplitude, generally) and HT that for the instantaneous frequency. It should be stable enough for my own needs, though I don't have some expertise with EMD to be aware of how much advantage consequences will get in the way. This sounds like the most promising approach for the time being.

    I haven't looked into wavelets in any way.

  4. #4
    What range do you concentrate on?

  5. #5
    Quote Originally Posted by ;
    What phases range do you concentrate on?
    I'll look at a broad range. After a tendency in one TF is a cycle at a different, and what is sound at one TF will often display structure at a lower TF. But the periods I work with most are in the range of a few hours to a few days. You have to watch the action on three or four TFs though. Anyone who has traded bicycles for an appreciable time understands that trends often play havoc with cycle trading. Too many times I have been blind-sided by something I did not see coming, however, a postmortem review showed the indications were plain on higher TFs if I had been watching for this.

    Were you expecting a response in number of bars? I count my bicycles in components aside from bars, e.g. hours, so I could quickly flip TFs and watch the identical cycle at several levels of detail without needing to reevaluate parameters. So number of bars fluctuates, but 50 or 100 are typical.

  6. #6
    During years, I have attempted to measure cycles like you, but finally with 2 moving averages and also a fantastic osciltor you can get very good results with no high level of maths and DSP.

  7. #7
    As I explained and unlike what the screenshot suggests the objective isn't to pick entrances. It is to reduce the residual oscillations of a trend dimension.

    What's the good oscillator you use? According to which criteria do you believe it good?

  8. #8
    I use MACD Just like a oscillator.... Its great because gives the best to me.

    Maybe I cant help you because you are searching for great estimator of the trend and that I favor the best entries.

    Whats the fad???

    Can you've researched the distance beetween two dominant cycles??

    For me it is not possible to extract the ideal cycle, only an approximation. .

  9. #9
    Your answer is quite surprising since mathematically MACD is the estimator of the trend...

  10. #10
    It depends just like you use...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.