use of suite.primitive.Longs_ 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);
}
use of suite.primitive.Longs_ in project suite by stupidsing.
the class BackAllocatorTest method testStop.
@Test
public void testStop() {
Time start = Time.of(2017, 1, 1);
String symbol = "S";
float[] prices = { 1f, .99f, .98f, .5f, .5f, .5f, 0f, 0f, 0f };
BackAllocator ba0 = (akds, ts) -> index -> List.of(Pair.of(symbol, 1d));
BackAllocator ba1 = ba0.stopLoss(.98d);
int length = prices.length;
long[] ts = Longs_.toArray(length, i -> start.addDays(i).epochSec());
DataSource ds = DataSource.of(ts, prices);
AlignKeyDataSource<String> akds = DataSource.alignAll(Read.from2(List.of(Pair.of(symbol, ds))));
int[] indices = Ints_.toArray(length, i -> i);
OnDateTime odt = ba1.allocate(akds, indices);
List<Double> potentials = //
Ints_.range(//
indices.length).map(//
index -> 0 < index ? Read.from(odt.onDateTime(index)) : Read.<Pair<String, Double>>empty()).map(//
pairs -> pairs.toDouble(Obj_Dbl.sum(pair -> pair.t1))).toList();
assertEquals(List.of(0d, 1d, 1d, 1d, 0d, 0d, 0d, 0d, 0d), potentials);
}
Aggregations