Search in sources :

Example 1 with DiscreteCosineTransform

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;
    });
}
Also used : GetBuySell(suite.trade.singlealloc.BuySellStrategy.GetBuySell) Arrays(java.util.Arrays) Floats_(suite.primitive.Floats_) Vector(suite.math.linalg.Vector) MovingAverage(suite.trade.analysis.MovingAverage) Ints_(suite.primitive.Ints_) Quant(ts.Quant) DiscreteCosineTransform(suite.math.transform.DiscreteCosineTransform) DiscreteCosineTransform(suite.math.transform.DiscreteCosineTransform)

Aggregations

Arrays (java.util.Arrays)1 Vector (suite.math.linalg.Vector)1 DiscreteCosineTransform (suite.math.transform.DiscreteCosineTransform)1 Floats_ (suite.primitive.Floats_)1 Ints_ (suite.primitive.Ints_)1 MovingAverage (suite.trade.analysis.MovingAverage)1 GetBuySell (suite.trade.singlealloc.BuySellStrategy.GetBuySell)1 Quant (ts.Quant)1