I wrote it in C++ and opencl (so most of the calculations are done on a GPU) with controlling code in perl and shell (bash). The graphs are from gnuplot.
A model (e.g., for GLD) bwould be something like
Code:
y = 178.67431640625 - 0.552311420440674 * x + 0.0044319755397737 * x * x
+ 1.70705246925354 * cos(twopi / 38.167761420465 * x + 2.84865665435791)
+ 1.67844784259796 * cos(twopi / 49.4317214487235 * x + 2.56916689872742)
+ 1.21163415908813 * cos(twopi / 26.0198103914197 * x + 4.47486019134521) ;
where y is the predicted price, x is the number of calendar days from the beginning of the input period, and the body of the function has a parabola and three cosine waves with amplitude, period, and phase).
It's nowhere near perfect (e.g., the models don't capture the spike of 24.99 to 26.76 to 24.54 of SLV on trading days 20210129, 20210201, and 20210202 too well). But the code works fairly consistently given the same data (different pseudorandom number sequences) or similar data. For example, here are the same type of graphs (10 overlaid models) for the same 123 calendar days for S&P 500 index ETFs VOO and SPLG (prices adjusted for splits and dividends).
VOO
View attachment 259483
SPLG
View attachment 259484
sample model for VOO
Code:
y = 343.538146972656 + 0.316626936197281 * x + 0.000452404085081071 * x * x
+ 5.90755987167358 * cos(twopi / 73.4853813924861 * x + 4.88049077987671)
+ 5.03771877288818 * cos(twopi / 27.725765107584 * x + 0.971799075603485)
+ 3.74927115440369 * cos(twopi / 30.3418598657709 * x + 5.95282411575317) ;
sample model for SPLG
Code:
y = 43.9298973083496 + 0.0405849181115627 * x + 5.74740915908478e-05 * x * x
+ 0.756501495838165 * cos(twopi / 73.2716120758861 * x + 4.86414957046509)
+ 0.680599689483643 * cos(twopi / 27.841080791083 * x + 1.03640067577362)
+ 0.516805410385132 * cos(twopi / 30.2471932452291 * x + 5.86949491500854) ;
The graphs for the two S&P 500 index ETFs have similar shapes for the fits and predictions, and the sample models have similar periods and phases in their cosines.