Search in sources :

Example 1 with Statistic

use of suite.math.numeric.Statistic in project suite by stupidsing.

the class BackAllocatorUtil method byRiskOfReturn.

public default BackAllocator byRiskOfReturn() {
    Statistic stat = new Statistic();
    int nDays = 32;
    return (akds, indices) -> {
        Map<String, float[]> returnsByKey = akds.dsByKey.mapValue(DataSource::returns).toMap();
        OnDateTime ba0 = allocate(akds, indices);
        return index -> // 
        Read.from2(// 
        ba0.onDateTime(index)).map2((symbol, potential) -> {
            float[] returns = Arrays.copyOfRange(returnsByKey.get(symbol), index - nDays, index);
            return potential / stat.variance(returns);
        }).toList();
    };
}
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) Statistic(suite.math.numeric.Statistic) HashMap(java.util.HashMap) Map(java.util.Map) 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