Search in sources :

Example 11 with LinearRegression

use of suite.math.numeric.Statistic.LinearRegression in project suite by stupidsing.

the class StatisticalArbitrageTest method testCointegration.

// Auto-regressive test
@Test
public void testCointegration() {
    // 0004.HK, 0020.HK
    // 0011.HK, 0005.HK
    int tor = 8;
    String symbol0 = "0004.HK";
    String symbol1 = "0945.HK";
    AlignKeyDataSource<String> akds = cfg.dataSources(period, Read.each(symbol0, symbol1));
    Map<String, float[]> pricesBySymbol = akds.dsByKey.mapValue(DataSource::returns).toMap();
    int length = akds.ts.length;
    float[] prices0 = pricesBySymbol.get(symbol0);
    float[] prices1 = pricesBySymbol.get(symbol1);
    LinearRegression lr = stat.linearRegression(// 
    Ints_.range(tor, // 
    length).map(i -> FltObjPair.of(prices1[i], Floats_.toArray(tor, j -> prices0[i + j - tor]))));
    System.out.println(lr);
}
Also used : KmeansCluster(suite.algo.KmeansCluster) Arrays(java.util.Arrays) Read(suite.streamlet.Read) LogUtil(suite.os.LogUtil) IntFltPair(suite.primitive.adt.pair.IntFltPair) AlignKeyDataSource(suite.trade.data.DataSource.AlignKeyDataSource) HashMap(java.util.HashMap) Random(java.util.Random) Sina(suite.trade.data.Sina) Fun(suite.util.FunUtil.Fun) ConfigurationImpl(suite.trade.data.ConfigurationImpl) String_(suite.util.String_) Map(java.util.Map) FltObjPair(suite.primitive.adt.pair.FltObjPair) TimeSeries(ts.TimeSeries) Ints_(suite.primitive.Ints_) DiscreteCosineTransform(suite.math.transform.DiscreteCosineTransform) Streamlet2(suite.streamlet.Streamlet2) Statistic(suite.math.numeric.Statistic) Test(org.junit.Test) To(suite.util.To) Obj_Dbl(suite.primitive.DblPrimitives.Obj_Dbl) Quant(ts.Quant) LinearRegression(suite.math.numeric.Statistic.LinearRegression) IntObjMap(suite.primitive.adt.map.IntObjMap) BollingerBands(ts.BollingerBands) Pair(suite.adt.pair.Pair) Streamlet(suite.streamlet.Streamlet) Time(suite.trade.Time) Floats_(suite.primitive.Floats_) Configuration(suite.trade.data.Configuration) DataSource(suite.trade.data.DataSource) As(suite.streamlet.As) Asset(suite.trade.Asset) TimeRange(suite.trade.TimeRange) Int_Flt(suite.primitive.Int_Flt) LinearRegression(suite.math.numeric.Statistic.LinearRegression) Test(org.junit.Test)

Aggregations

LinearRegression (suite.math.numeric.Statistic.LinearRegression)11 Statistic (suite.math.numeric.Statistic)10 Ints_ (suite.primitive.Ints_)10 FltObjPair (suite.primitive.adt.pair.FltObjPair)10 To (suite.util.To)9 Arrays (java.util.Arrays)8 Random (java.util.Random)7 Floats_ (suite.primitive.Floats_)7 Vector (suite.math.linalg.Vector)6 Int_Dbl (suite.primitive.Int_Dbl)6 Int_Flt (suite.primitive.Int_Flt)6 Read (suite.streamlet.Read)6 Friends.max (suite.util.Friends.max)6 Floats (suite.primitive.Floats)5 Friends.min (suite.util.Friends.min)5 Test (org.junit.Test)4 Configuration (suite.trade.data.Configuration)4 DataSource (suite.trade.data.DataSource)4 Map (java.util.Map)3 DblSource (suite.primitive.DblPrimitives.DblSource)3