Search in sources :

Example 1 with LngStreamlet

use of suite.primitive.streamlet.LngStreamlet in project suite by stupidsing.

the class PairTest method test.

private void test(TimeRange period, String symbol0, String symbol1) {
    DataSource ds0 = cfg.dataSource(symbol0, period);
    DataSource ds1 = cfg.dataSource(symbol1, period);
    LngStreamlet ts0 = Longs_.of(ds0.ts);
    LngStreamlet ts1 = Longs_.of(ds1.ts);
    long[] tradeTimes = Longs_.concat(ts0, ts1).distinct().sort().toArray();
    float[] prices0 = ds0.alignBeforePrices(tradeTimes).prices;
    float[] prices1 = ds1.alignBeforePrices(tradeTimes).prices;
    int length = prices0.length;
    LinearRegression lr = statistic.linearRegression(// 
    Ints_.range(// 
    length).map(i -> FltObjPair.of(prices1[i], new float[] { prices0[i], 1f })));
    System.out.println(symbol0 + " -> " + symbol1 + lr);
    assertTrue(.4d < lr.r2);
}
Also used : ConfigurationImpl(suite.trade.data.ConfigurationImpl) Statistic(suite.math.numeric.Statistic) Configuration(suite.trade.data.Configuration) FltObjPair(suite.primitive.adt.pair.FltObjPair) LngStreamlet(suite.primitive.streamlet.LngStreamlet) DataSource(suite.trade.data.DataSource) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Ints_(suite.primitive.Ints_) LinearRegression(suite.math.numeric.Statistic.LinearRegression) Longs_(suite.primitive.Longs_) LngStreamlet(suite.primitive.streamlet.LngStreamlet) LinearRegression(suite.math.numeric.Statistic.LinearRegression) DataSource(suite.trade.data.DataSource)

Aggregations

Assert.assertTrue (org.junit.Assert.assertTrue)1 Test (org.junit.Test)1 Statistic (suite.math.numeric.Statistic)1 LinearRegression (suite.math.numeric.Statistic.LinearRegression)1 Ints_ (suite.primitive.Ints_)1 Longs_ (suite.primitive.Longs_)1 FltObjPair (suite.primitive.adt.pair.FltObjPair)1 LngStreamlet (suite.primitive.streamlet.LngStreamlet)1 Configuration (suite.trade.data.Configuration)1 ConfigurationImpl (suite.trade.data.ConfigurationImpl)1 DataSource (suite.trade.data.DataSource)1