Search in sources :

Example 16 with Ints_

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", ""));
}
Also used : HttpUtil(suite.http.HttpUtil) ObjFltMap(suite.primitive.adt.map.ObjFltMap) List(java.util.List) URL(java.net.URL) Trade_(suite.trade.Trade_) Chars_(suite.primitive.Chars_) As(suite.streamlet.As) To(suite.util.To) Ints_(suite.primitive.Ints_) URL(java.net.URL)

Example 17 with Ints_

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));
}
Also used : HttpUtil(suite.http.HttpUtil) ObjFltMap(suite.primitive.adt.map.ObjFltMap) List(java.util.List) URL(java.net.URL) Trade_(suite.trade.Trade_) Chars_(suite.primitive.Chars_) As(suite.streamlet.As) To(suite.util.To) Ints_(suite.primitive.Ints_) URL(java.net.URL)

Example 18 with Ints_

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);
        }
    }
}
Also used : Arrays(java.util.Arrays) DblSource(suite.primitive.DblPrimitives.DblSource) Friends.min(suite.util.Friends.min) Statistic(suite.math.numeric.Statistic) Random(java.util.Random) To(suite.util.To) LinearRegression(suite.math.numeric.Statistic.LinearRegression) Friends.max(suite.util.Friends.max) Floats_(suite.primitive.Floats_) Vector(suite.math.linalg.Vector) Floats(suite.primitive.Floats) FltObjPair(suite.primitive.adt.pair.FltObjPair) FltStreamlet(suite.primitive.streamlet.FltStreamlet) Ints_(suite.primitive.Ints_) Int_Dbl(suite.primitive.Int_Dbl) Int_Flt(suite.primitive.Int_Flt) DblObjPair(suite.primitive.adt.pair.DblObjPair) LinearRegression(suite.math.numeric.Statistic.LinearRegression)

Example 19 with Ints_

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];
}
Also used : Arrays(java.util.Arrays) Read(suite.streamlet.Read) Friends.min(suite.util.Friends.min) Statistic(suite.math.numeric.Statistic) Trade_(suite.trade.Trade_) CholeskyDecomposition(suite.math.linalg.CholeskyDecomposition) To(suite.util.To) LinearRegression(suite.math.numeric.Statistic.LinearRegression) ArrayList(java.util.ArrayList) Friends.max(suite.util.Friends.max) List(java.util.List) MeanVariance(suite.math.numeric.Statistic.MeanVariance) Vector(suite.math.linalg.Vector) Floats(suite.primitive.Floats) FltObjPair(suite.primitive.adt.pair.FltObjPair) Ints_(suite.primitive.Ints_) Int_Dbl(suite.primitive.Int_Dbl) LinearRegression(suite.math.numeric.Statistic.LinearRegression)

Example 20 with Ints_

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();
        });
    }
}
Also used : Object_(suite.util.Object_) B_TreeBuilder(suite.btree.impl.B_TreeBuilder) Files(java.nio.file.Files) Constants(suite.Constants) Bytes(suite.primitive.Bytes) Profiler(suite.sample.Profiler) IOException(java.io.IOException) Random(java.util.Random) Test(org.junit.Test) To(suite.util.To) Serialize(suite.util.Serialize) JournalledPageFile(suite.file.JournalledPageFile) Pair(suite.adt.pair.Pair) Assert.assertNull(org.junit.Assert.assertNull) Ints_(suite.primitive.Ints_) Comparator(java.util.Comparator) Path(java.nio.file.Path) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) JournalledFileFactory(suite.file.impl.JournalledFileFactory) Path(java.nio.file.Path) Bytes(suite.primitive.Bytes) Profiler(suite.sample.Profiler) B_TreeBuilder(suite.btree.impl.B_TreeBuilder) JournalledPageFile(suite.file.JournalledPageFile) Test(org.junit.Test)

Aggregations

Ints_ (suite.primitive.Ints_)24 To (suite.util.To)14 Arrays (java.util.Arrays)12 Statistic (suite.math.numeric.Statistic)12 Friends.max (suite.util.Friends.max)12 List (java.util.List)10 LinearRegression (suite.math.numeric.Statistic.LinearRegression)10 FltObjPair (suite.primitive.adt.pair.FltObjPair)10 Pair (suite.adt.pair.Pair)9 Floats_ (suite.primitive.Floats_)9 Read (suite.streamlet.Read)9 Friends.min (suite.util.Friends.min)9 Random (java.util.Random)8 Int_Flt (suite.primitive.Int_Flt)8 As (suite.streamlet.As)8 Test (org.junit.Test)7 Time (suite.trade.Time)6 Trade_ (suite.trade.Trade_)6 Configuration (suite.trade.data.Configuration)6 ConfigurationImpl (suite.trade.data.ConfigurationImpl)6