TA, like catching a greased pig

I did some trend and cycle analysis of the CORN ETF by fitting 10 curves to the most recent 123 calendar days of close prices with prices (20210125 through 20210527) and then extrapolating the curves for 21 calendar days.

The models for the curves are:
Code:
y = 16.7131156921387  -  0.0153137510642409 * x  +  0.000483304698718712 * x * x
    +  0.959539353847504 * cos(twopi / 63.4018692382697 * x  +  3.40450406074524)
    +  0.770700573921204 * cos(twopi / 43.3602527495009 * x  +  4.73570346832275)
    +  0.467519104480743 * cos(twopi / 34.7284220393245 * x  +  6.08380746841431) ;
y = 16.713436126709  -  0.0150419715791941 * x  +  0.000478885543998331 * x * x
    +  0.95742279291153 * cos(twopi / 63.8633323419881 * x  +  3.4558277130127)
    +  0.7980717420578 * cos(twopi / 43.3673122743544 * x  +  4.78270292282104)
    +  0.483296900987625 * cos(twopi / 35.3236032629264 * x  +  0.0110753700137138) ;
y = 16.7580909729004  -  0.0169391445815563 * x  +  0.000495195155963302 * x * x
    +  0.995058178901672 * cos(twopi / 62.4901849257942 * x  +  3.34408283233643)
    +  0.800124228000641 * cos(twopi / 44.1284251402229 * x  +  4.85770988464355)
    +  0.432926446199417 * cos(twopi / 35.0238653361553 * x  +  6.18382596969604) ;
y = 16.5952205657959  -  0.0109868599101901 * x  +  0.000449098908575252 * x * x
    +  0.949107766151428 * cos(twopi / 65.1970106025516 * x  +  3.57469415664673)
    +  0.794284164905548 * cos(twopi / 43.0441710517878 * x  +  4.75899887084961)
    +  0.511595726013184 * cos(twopi / 35.3163192832428 * x  +  0.0236181281507015) ;
y = 16.6779689788818  -  0.0139918606728315 * x  +  0.000472479616291821 * x * x
    +  0.948615729808807 * cos(twopi / 64.1614927302518 * x  +  3.47451305389404)
    +  0.790576696395874 * cos(twopi / 43.0908605109407 * x  +  4.72300720214844)
    +  0.501231789588928 * cos(twopi / 35.163146391637 * x  +  6.24657678604126) ;
y = 16.7613830566406  -  0.0172608532011509 * x  +  0.000499849615152925 * x * x
    +  0.962769985198975 * cos(twopi / 62.6504139908195 * x  +  3.3491542339325)
    +  0.88291609287262 * cos(twopi / 43.0581795739345 * x  +  4.68369483947754)
    +  0.540133655071259 * cos(twopi / 35.7706484172679 * x  +  0.0910500288009644) ;
y = 16.7431106567383  -  0.0164131913334131 * x  +  0.000492125283926725 * x * x
    +  0.946361899375916 * cos(twopi / 41.9450197437358 * x  +  4.50250482559204)
    +  0.929884850978851 * cos(twopi / 63.4108127579004 * x  +  3.38510155677795)
    +  0.663641095161438 * cos(twopi / 35.8246719924236 * x  +  0.0866263881325722) ;
y = 16.7465496063232  -  0.0169562790542841 * x  +  0.000497211585752666 * x * x
    +  0.951225876808167 * cos(twopi / 63.147808236269 * x  +  3.36992502212524)
    +  0.809797048568726 * cos(twopi / 42.8652174448971 * x  +  4.63862800598145)
    +  0.510966598987579 * cos(twopi / 35.0402748945954 * x  +  6.15926599502563) ;
y = 16.6235942840576  -  0.0114988768473268 * x  +  0.000451428000815213 * x * x
    +  0.934058785438538 * cos(twopi / 65.0798104216482 * x  +  3.55813646316528)
    +  0.822907149791718 * cos(twopi / 42.7345265547166 * x  +  4.71264028549194)
    +  0.544252336025238 * cos(twopi / 35.6158612814569 * x  +  0.118446305394173) ;
y = 16.7602806091309  -  0.0173964351415634 * x  +  0.000501201080624014 * x * x
    +  0.97394859790802 * cos(twopi / 62.4490370652999 * x  +  3.32628607749939)
    +  0.801126003265381 * cos(twopi / 43.5088793352626 * x  +  4.73933458328247)
    +  0.470553696155548 * cos(twopi / 34.9519416795132 * x  +  6.13758230209351) ;
y is the predicted price, and x is the number of calendar days since 20210125. The only reason the models vary is because of different pseudorandom number sequences when they were genetically optimized.

The close prices (+ signs) and overlaid curves are:
View attachment 259712
So the models all think an uptrend has started.

I think you can use a higher degree polynomial to get a nicer fit.
 
Would you mind if I used this as an example of overfitting in my next book?

GAT

It's hard to overfit (model noise) on typical asset prices with a parabola and three cosine waves.

If I used a few more cosines ...
upload_2021-5-28_14-52-34.png

Now there is a fit that would have made Jean-Baptiste Joseph Fourier proud!:)
 
Now there is a fit that would have made Jean-Baptiste Joseph Fourier proud!

And what's the use in trading of your calculations? Because to me that's the only thing that counts.
Are you not always running behind the facts?
Like this:
Clipboard01.jpg


But you impressed me with that math. :)
@globalarbtrader , you can use this for your book too, just mention my name. :D
 
Last edited:
And what's the use in trading of your calculations?

That post is a tounge-in-cheek comment to "Would you mind if I used this as an example of overfitting in my next book?" The graph is a combination of a least-squares parabola and inverse Fourier Transform to get a very overfitted curve. My original CORN post presents fitted curves that have a parabola plus three cosine waves. In my opinion, those models do not overfit the CORN prices because they visually don't follow the prices very closely. Perhaps globalarbtrader or someone else can explain how these simple curves overfit?

I tried to explain the philosophy of this here and here. The generated models try to capture a recent trend (parabola) and oscillations around the trend (cosine waves). Since the functions depend only on time, they can be extrapolated to find possible inflection points for times of trade entry and exit.
 
That post is a tounge-in-cheek comment to "Would you mind if I used this as an example of overfitting in my next book?" The graph is a combination of a least-squares parabola and inverse Fourier Transform to get a very overfitted curve. My original CORN post presents fitted curves that have a parabola plus three cosine waves. In my opinion, those models do not overfit the CORN prices because they visually don't follow the prices very closely. Perhaps globalarbtrader or someone else can explain how these simple curves overfit?

I tried to explain the philosophy of this here and here. The generated models try to capture a recent trend (parabola) and oscillations around the trend (cosine waves). Since the functions depend only on time, they can be extrapolated to find possible inflection points for times of trade entry and exit.

What are the advantages vs a low pass filter like the moving average
 
What are the advantages vs a low pass filter like the moving average

A function like
Code:
y = 16.7131156921387  -  0.0153137510642409 * x  +  0.000483304698718712 * x * x
    +  0.959539353847504 * cos(twopi / 63.4018692382697 * x  +  3.40450406074524)
    +  0.770700573921204 * cos(twopi / 43.3602527495009 * x  +  4.73570346832275)
    +  0.467519104480743 * cos(twopi / 34.7284220393245 * x  +  6.08380746841431) ;
has y as the predicted price, and x is the number of bars (days) from the beginning of the input data.

Since you know what time is in the future (e.g., two weeks from now is always 14 days), this makes it possible to predict future prices and the time(s) of the next price swing(s). An image from this post illustrates this:
upload_2021-4-3_17-43-32-png.256154

The two rightmost inflection points in the detrended curve are in the future relative to when the input data ended (after the mean line in the graph ends).

You can't do that with a filter like a moving average because it uses prices as inputs, and you don't know future prices until they happen.

FYI, the 9th degree polynomial fit above was intended as a joke because higher-order polynomials are known for creating extreme values.
 
Back
Top