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);
}
Aggregations