use of suite.primitive.Ints_ in project suite by stupidsing.
the class Aastocks method quote_.
private float quote_(String symbol) {
String urlString = "http://www.aastocks.com/en/mobile/Quote.aspx?symbol=0" + symbol.substring(0, 4);
URL url = To.url(urlString);
List<String> lines = HttpUtil.get(url).out.collect(As::lines).toList();
int i0 = Ints_.range(lines.size()).filter(i -> lines.get(i).contains("text_last")).first();
return toFloat(lines.get(i0 + 1).replace("0px", "").replace(".png", ""));
}
use of suite.primitive.Ints_ in project suite by stupidsing.
the class Aastocks method hsi.
public float hsi() {
String urlString = "http://www.aastocks.com/en/mobile/Quote.aspx?symbol=00005";
URL url = To.url(urlString);
List<String> lines = HttpUtil.get(url).out.collect(As::lines).toList();
int i0 = Ints_.range(lines.size()).filter(i -> lines.get(i).contains("HSI")).first();
return toFloat(lines.get(i0 + 1));
}
use of suite.primitive.Ints_ in project suite by stupidsing.
the class Arima method armaIa.
// extended from
// "High Frequency Trading - A Practical Guide to Algorithmic Strategies and
// Trading Systems", Irene Aldridge, page 100
// xs[t]
// = ars[0] * xs[t - 1] + ... + ars[p - 1] * xs[t - p]
// + ep[t]
// + mas[0] * ep[t - 1] + ... + mas[q - 1] * ep[t - q]
private Arima_ armaIa(float[] xs, int p, int q) {
int length = xs.length;
int lengthp = length + p, lengthpm1 = lengthp - 1;
int lengthq = length + q, lengthqm1 = lengthq - 1;
int iter = 0;
float[] xsp = new float[lengthp];
float[][] epqByIter = new float[q][];
Arrays.fill(xsp, 0, p, xs[0]);
System.arraycopy(xs, 0, xsp, p, length);
while (true) {
int iter_ = iter;
LinearRegression lr = stat.linearRegression(//
Ints_.range(//
length).map(t -> {
int tp = t + p;
int tq = t + q, tqm1 = tq - 1;
float[] lrxs = //
Floats_.concat(Floats_.reverse(xsp, t, tp), //
Ints_.range(iter_).collect(Int_Flt.lift(i -> epqByIter[i][tqm1 - i]))).toArray();
return FltObjPair.of(xsp[tp], lrxs);
}));
float[] coeffs = lr.coefficients();
if (iter < q)
System.arraycopy(lr.residuals, 0, epqByIter[iter++] = new float[lengthq], q, length);
else {
float[] ars = Floats.of(coeffs, 0, p).toArray();
float[] mas = Floats.of(coeffs, p).toArray();
double x1 = //
0d + //
Ints_.range(p).toDouble(Int_Dbl.sum(i -> ars[i] * xsp[lengthpm1 - i])) + Ints_.range(q).toDouble(Int_Dbl.sum(i -> mas[i] * epqByIter[i][lengthqm1 - i]));
return new Arima_(ars, mas, (float) x1);
}
}
}
use of suite.primitive.Ints_ in project suite by stupidsing.
the class TimeSeries method adf.
// Augmented Dickey-Fuller test
public double adf(float[] ys, int tor) {
float[] ydiffs = differences_(1, ys);
int length = ys.length;
LinearRegression lr = stat.linearRegression(//
Ints_.range(tor, //
length).map(i -> FltObjPair.of(ydiffs[i], // i - drift term, necessary?
Floats.concat(Floats.of(ys[i - 1], 1f, i), Floats.of(ydiffs, i - tor, i)).toArray())));
return lr.tStatistic()[0];
}
use of suite.primitive.Ints_ in project suite by stupidsing.
the class B_TreeTest method testInsertPerformance.
@Test
public void testInsertPerformance() throws IOException {
int nKeys = 16384;
keys = Ints_.toArray(nKeys, i -> i);
int pageSize = 4096;
Path path = Constants.tmp("b_tree-file");
for (int i = 0; i < nKeys; i++) {
int j = random.nextInt(nKeys);
Integer temp = keys[i];
keys[i] = keys[j];
keys[j] = temp;
}
Files.deleteIfExists(path);
B_TreeBuilder<Integer, Bytes> builder = new B_TreeBuilder<>(serialize.int_, serialize.bytes(64));
try (JournalledPageFile jpf = JournalledFileFactory.journalled(path, pageSize);
B_Tree<Integer, Bytes> b_tree = builder.build(jpf, comparator, 9999)) {
new Profiler().profile(() -> {
b_tree.create();
for (int i = 0; i < nKeys; i++) {
int key = keys[i];
b_tree.put(key, To.bytes(Integer.toString(key)));
}
jpf.commit();
jpf.sync();
});
}
}
Aggregations