use of suite.math.transform.DiscreteCosineTransform in project suite by stupidsing.
the class Strategos method lowPassPrediction.
public BuySellStrategy lowPassPrediction(int windowSize, int nFutureDays, int nLowPass, float threshold) {
DiscreteCosineTransform dct = new DiscreteCosineTransform();
int nPastDays = windowSize - nFutureDays;
return prices -> holdFixedDays(prices.length, nFutureDays, day -> {
if (nPastDays <= day) {
// moving window
float[] fs0 = new float[windowSize];
float price0 = prices[day];
Floats_.copy(prices, day - nPastDays, fs0, 0, nPastDays);
Arrays.fill(fs0, nPastDays, windowSize, price0);
float[] fs1 = dct.dct(fs0);
float[] fs2 = Floats_.toArray(windowSize, j -> j < nLowPass ? fs1[j] : 0f);
float[] fs3 = dct.idct(fs2);
float predict = fs3[fs3.length - 1];
return getSignal(price0, predict, threshold);
} else
return 0;
});
}
Aggregations