Search in sources :

Example 1 with Configuration

use of suite.trade.data.Configuration in project suite by stupidsing.

the class BackAllocatorUtil method filterByIndexReturn.

public default BackAllocator filterByIndexReturn(Configuration cfg, String indexSymbol) {
    DataSource indexDataSource = cfg.dataSource(indexSymbol);
    return (akds, indices) -> {
        OnDateTime onDateTime = allocate(akds, indices);
        return index -> {
            Time date = Time.ofEpochSec(akds.ts[index - 1]).date();
            long t0 = date.addDays(-7).epochSec();
            long tx = date.epochSec();
            DataSource ids = indexDataSource.range(t0, tx);
            double indexPrice0 = ids.get(-1).t1;
            double indexPricex = ids.get(-2).t1;
            double indexReturn = Quant.return_(indexPrice0, indexPricex);
            return // 
            -.03f < indexReturn ? // 
            onDateTime.onDateTime(index) : List.of();
        };
    };
}
Also used : Arrays(java.util.Arrays) Read(suite.streamlet.Read) Trade_(suite.trade.Trade_) AlignKeyDataSource(suite.trade.data.DataSource.AlignKeyDataSource) Mutable(suite.adt.Mutable) DblDbl_Dbl(suite.primitive.DblDbl_Dbl) HashMap(java.util.HashMap) Deque(java.util.Deque) IntPredicate(java.util.function.IntPredicate) Fun(suite.util.FunUtil.Fun) ArrayList(java.util.ArrayList) DblFltPair(suite.primitive.adt.pair.DblFltPair) String_(suite.util.String_) Map(java.util.Map) Set_(suite.util.Set_) Streamlet2(suite.streamlet.Streamlet2) Object_(suite.util.Object_) Friends.min(suite.util.Friends.min) Statistic(suite.math.numeric.Statistic) Predicate(java.util.function.Predicate) ObjObj_Dbl(suite.primitive.DblPrimitives.ObjObj_Dbl) Datum(suite.trade.data.DataSource.Datum) Obj_Dbl(suite.primitive.DblPrimitives.Obj_Dbl) Quant(ts.Quant) Usex(suite.trade.Usex) Objects(java.util.Objects) WalkForwardAllocator(suite.trade.walkforwardalloc.WalkForwardAllocator) Pair(suite.adt.pair.Pair) Friends.max(suite.util.Friends.max) List(java.util.List) Streamlet(suite.streamlet.Streamlet) Time(suite.trade.Time) Configuration(suite.trade.data.Configuration) Entry(java.util.Map.Entry) DataSource(suite.trade.data.DataSource) As(suite.streamlet.As) Asset(suite.trade.Asset) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) Fail(suite.util.Fail) Time(suite.trade.Time) AlignKeyDataSource(suite.trade.data.DataSource.AlignKeyDataSource) DataSource(suite.trade.data.DataSource)

Aggregations

ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Deque (java.util.Deque)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 IntPredicate (java.util.function.IntPredicate)1 Predicate (java.util.function.Predicate)1 Mutable (suite.adt.Mutable)1 Pair (suite.adt.pair.Pair)1 Statistic (suite.math.numeric.Statistic)1 DblDbl_Dbl (suite.primitive.DblDbl_Dbl)1 ObjObj_Dbl (suite.primitive.DblPrimitives.ObjObj_Dbl)1 Obj_Dbl (suite.primitive.DblPrimitives.Obj_Dbl)1 DblFltPair (suite.primitive.adt.pair.DblFltPair)1 As (suite.streamlet.As)1