use of suite.streamlet.Streamlet in project suite by stupidsing.
the class P3Optimize method optimize_.
private Funp optimize_(Funp n) {
return //
n.<//
Funp>switch_().applyIf(FunpCoerce.class, f -> f.apply((coerce, expr) -> {
return !(expr instanceof FunpDontCare) ? n : optimize(expr);
})).applyIf(FunpData.class, f -> f.apply(pairs -> {
return FunpData.of(Read.from2(pairs).concatMap((expr, range) -> {
Funp expr1 = optimize(expr);
int start = range.t0;
Streamlet<Pair<Funp, IntIntPair>> pairsx = new //
Switch<Streamlet<Pair<Funp, IntIntPair>>>(//
expr1).applyIf(FunpData.class, g -> g.apply(pairs1 -> {
return //
Read.from2(//
pairs1).map((exprc, range1) -> Pair.of(optimize(exprc), IntIntPair.of(start + range1.t0, start + range1.t1)));
})).result();
return pairsx != null ? pairsx : Read.each(Pair.of(expr1, range));
}).toList());
})).applyIf(FunpDeref.class, f -> f.apply(pointer -> {
return optimize(pointer).<Funp>switch_().applyIf(FunpReference.class, g -> g.expr).result();
})).applyIf(FunpIf.class, f -> f.apply((if_, then, else_) -> {
return //
optimize(if_).<Funp>switch_().applyIf(FunpBoolean.class, g -> g.apply(b -> {
return b ? then : else_;
})).result();
})).applyIf(FunpMemory.class, f -> f.apply((pointer, start, end) -> {
return //
optimize(pointer).<Funp>switch_().applyIf(FunpData.class, g -> g.apply(pairs -> {
for (Pair<Funp, IntIntPair> pair : pairs) {
IntIntPair range = pair.t1;
if (start == range.t0 && end == range.t1)
return pair.t0;
}
return null;
})).applyIf(FunpReference.class, g -> {
return FunpTree.of(TermOp.PLUS__, g.expr, FunpNumber.ofNumber(start));
}).result();
})).applyIf(FunpReference.class, f -> f.apply(expr -> {
return optimize(expr).<Funp>switch_().applyIf(FunpMemory.class, g -> g.pointer).result();
})).applyIf(FunpTree.class, f -> f.apply((operator, lhs, rhs) -> {
IntInt_Bool iib = TreeUtil.boolOperations.get(operator);
IntInt_Int iii = TreeUtil.intOperations.get(operator);
if (iib != null)
return evaluate(iib, lhs, rhs);
else if (iii != null)
return evaluate(iii, lhs, rhs);
else
return null;
})).applyIf(FunpTree2.class, f -> f.apply((operator, lhs, rhs) -> {
return evaluate(TreeUtil.tupleOperations.get(operator), lhs, rhs);
})).applyIf(FunpWhile.class, f -> f.apply((while_, do_, expr) -> {
return //
optimize(while_).<Funp>switch_().applyIf(FunpBoolean.class, g -> g.apply(b -> {
return b ? null : expr;
})).result();
})).result();
}
use of suite.streamlet.Streamlet in project suite by stupidsing.
the class DailyMain method alloc.
private Result alloc(String tag, float fund, BackAllocator backAllocator, Streamlet<Asset> assets) {
TimeRange period = TimeRange.daysBefore(64);
Simulate sim = BackAllocTester.of(cfg, period, assets, backAllocator, log).simulate(fund);
Account account0 = Account.ofPortfolio(cfg.queryHistory().filter(r -> String_.equals(r.strategy, tag)));
Account account1 = sim.account;
Map<String, Integer> assets0 = account0.assets();
Map<String, Integer> assets1 = account1.assets();
Set<String> symbols = Set_.union(assets0.keySet(), assets1.keySet());
Map<String, Float> priceBySymbol = cfg.quote(symbols);
List<Trade> trades = Trade_.diff(Trade.NA, assets0, assets1, priceBySymbol::get).toList();
sb.append("\nstrategy = " + tag + ", " + sim.conclusion());
return new Result(tag, trades);
}
use of suite.streamlet.Streamlet in project suite by stupidsing.
the class Lister method leaves.
private Streamlet<IList<Node>> leaves(Node node, IList<Node> prefix) {
NodeRead nr = NodeRead.of(node);
Streamlet<IList<Node>> st;
if (nr.type == ReadType.TUPLE)
st = //
Read.from(//
nr.children).index().map(//
(i, p) -> leaves(p.t1, IList.cons(Int.of(i), prefix))).collect(As::concat);
else if (nr.type != ReadType.TERM)
st = Read.from(nr.children).concatMap(p -> leaves(p.t1, IList.cons(p.t0, prefix)));
else
st = Read.from(List.of(IList.cons(nr.terminal, prefix)));
if (nr.op != null)
st = st.cons(IList.cons(Atom.of(nr.op.toString()), prefix));
return st;
}
use of suite.streamlet.Streamlet in project suite by stupidsing.
the class Hkex method queryCompanies_.
private List<Asset> queryCompanies_(int pageNo) {
JsonNode json = query(//
"" + //
"https://www.hkex.com.hk/eng/csm/ws/Result.asmx/GetData" + //
"?location=companySearch" + //
"&SearchMethod=2" + //
"&LangCode=en" + //
"&StockCode=" + //
"&StockName=" + //
"&Ranking=ByMC" + //
"&StockType=MB" + //
"&mkt=hk" + "&PageNo=" + //
(pageNo + 1) + //
"&ATypeSHEx=" + //
"&AType=" + //
"&FDD=" + //
"&FMM=" + //
"&FYYYY=" + //
"&TDD=" + //
"&TMM=" + "&TYYYY=");
CompanySearch companySearch = mapper.convertValue(json, CompanySearch.class);
Streamlet<List<String>> data0;
if (Boolean.TRUE)
data0 = //
Read.each(//
companySearch).flatMap(//
cs -> cs.data).concatMap(Data::tableEntries);
else
data0 = //
Read.each(//
json).flatMap(//
json_ -> json_.path("data")).flatMap(//
json_ -> json_.path("content")).flatMap(//
json_ -> json_.path("table")).flatMap(//
json_ -> json_.path("tr")).filter(//
json_ -> !json_.path("thead").asBoolean()).flatMap(//
json_ -> json_.path("td")).map(json_ -> Read.from(json_).map(JsonNode::asText).toList());
Streamlet<List<String>> data1 = data0.collect(As::streamlet);
Map<String, Integer> lotSizeBySymbol = queryLotSizeBySymbol_(data1.map(this::toSymbol));
return data1.map(datum -> toAsset(datum, lotSizeBySymbol)).toList();
}
use of suite.streamlet.Streamlet in project suite by stupidsing.
the class Yahoo method dataSourceYql.
public DataSource dataSourceYql(String symbol, TimeRange period) {
String yql = //
"select *" + //
" from yahoo.finance.historicaldata" + " where symbol = \"" + symbol + //
"\"" + " and startDate = \"" + period.from.ymd() + //
"\"" + " and endDate = \"" + period.to.ymd() + "\"";
String urlString = //
"http://query.yahooapis.com/v1/public/yql" + "?q=" + //
encode(yql) + //
"&format=json" + //
"&diagnostics=true" + //
"&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys" + "&callback=";
return Rethrow.ex(() -> {
try (InputStream is = Singleton.me.storeCache.http(urlString).collect(To::inputStream)) {
JsonNode json = mapper.readTree(is);
Streamlet<JsonNode> quotes = //
Read.each(json).flatMap(//
json_ -> json_.path("query")).flatMap(//
json_ -> json_.path("results")).flatMap(//
json_ -> json_.path("quote")).collect(As::streamlet);
Streamlet<String[]> arrays = //
quotes.map(json_ -> new String[] { //
json_.path("Date").textValue(), //
json_.path("Open").textValue(), //
json_.path("Close").textValue(), //
json_.path("Low").textValue(), //
json_.path("High").textValue() }).collect(As::streamlet);
long[] ts = arrays.collect(Obj_Lng.lift(array -> closeTs(array[0]))).toArray();
float[] opens = arrays.collect(Obj_Flt.lift(array -> Float.parseFloat(array[1]))).toArray();
float[] closes = arrays.collect(Obj_Flt.lift(array -> Float.parseFloat(array[2]))).toArray();
float[] lows = arrays.collect(Obj_Flt.lift(array -> Float.parseFloat(array[3]))).toArray();
float[] highs = arrays.collect(Obj_Flt.lift(array -> Float.parseFloat(array[4]))).toArray();
float[] volumes = new float[ts.length];
return DataSource.ofOhlcv(ts, opens, closes, lows, highs, volumes);
}
});
}
Aggregations