Search in sources :

Example 1 with FltObjPair

use of suite.primitive.adt.pair.FltObjPair in project suite by stupidsing.

the class TimeSeries method hurstFwf.

// http://www.financialwisdomforum.org/gummy-stuff/hurst.htm
public double hurstFwf(float[] ys, int tor) {
    float[] logys = To.vector(ys, Math::log);
    float[] returns0 = dropDiff_(1, logys);
    int length = returns0.length;
    List<FltObjPair<float[]>> pairs = new ArrayList<>();
    for (int n = 0; n < length * 3 / 4; n++) {
        float[] returns = Arrays.copyOfRange(returns0, n, length);
        MeanVariance mv = stat.meanVariance(returns);
        double mean = mv.mean;
        float[] devs = To.vector(returns, r -> r - mean);
        double min = Double.MAX_VALUE;
        double max = Double.MIN_VALUE;
        double sum = 0d;
        for (float dev : devs) {
            sum += dev;
            min = min(sum, min);
            max = max(sum, max);
        }
        double x = Math.log(returns.length);
        double y = (max - min) / mv.standardDeviation();
        pairs.add(FltObjPair.of((float) y, new float[] { (float) x, 1f }));
    }
    return stat.linearRegression(Read.from(pairs)).coefficients[0];
}
Also used : MeanVariance(suite.math.numeric.Statistic.MeanVariance) ArrayList(java.util.ArrayList) FltObjPair(suite.primitive.adt.pair.FltObjPair)

Aggregations

ArrayList (java.util.ArrayList)1 MeanVariance (suite.math.numeric.Statistic.MeanVariance)1 FltObjPair (suite.primitive.adt.pair.FltObjPair)1