use of ts.TimeSeries.ReturnsStat in project suite by stupidsing.
the class WalkForwardAllocTester method conclusion.
public String conclusion() {
float[] valuations_ = valuations.toFloats().toArray();
int length = valuations_.length;
double deltaMs = (start - System.currentTimeMillis()) / length;
ReturnsStat rs = ts.returnsStat(valuations_, deltaMs);
StringBuilder sb = new StringBuilder();
for (Pair<String, Double> e : Read.from2(holdBySymbol).sortBy((symbol, value) -> -value).take(5)) sb.append(e.t0 + ":" + String.format("%.0f", e.t1 * 100d / length) + "%,");
return //
"nTicks:" + length + " val:" + //
(0 < length ? valuations_[length - 1] : "N/A") + " tickRtn:" + //
To.string(rs.return_) + " sharpe:" + //
To.string(rs.sharpeRatio()) + " skew:" + //
To.string(stat.skewness(valuations_)) + " " + //
account.transactionSummary(cfg::transactionFee).out0() + " holds::" + sb + "...";
}
use of ts.TimeSeries.ReturnsStat in project suite by stupidsing.
the class MovingAvgMeanReversionBackAllocator method backAllocator.
public BackAllocator backAllocator() {
return (akds, indices) -> {
Map<String, DataSource> dsBySymbol = akds.dsByKey.toMap();
double dailyRiskFreeInterestRate = Trade_.riskFreeInterestRate(1);
DataSourceView<String, MeanReversionStat> dsv = //
DataSourceView.of(tor, 256, akds, (symbol, ds, period) -> new MeanReversionStat(ds, period));
return index -> {
Map<String, MeanReversionStat> mrsBySymbol = //
akds.dsByKey.map2(//
(symbol, ds) -> dsv.get(symbol, index)).filterValue(//
mrsReversionStat -> mrsReversionStat != null).toMap();
// ensure 0 < half-life: determine investment period
return //
Read.from2(mrsBySymbol).filterValue(mrs -> //
mrs.adf < 0d && //
mrs.hurst < .5d && //
mrs.movingAvgMeanReversionRatio() < 0d).map2((symbol, mrs) -> {
DataSource ds = dsBySymbol.get(symbol);
double price = ds.prices[index - 1];
double lma = mrs.latestMovingAverage();
double diff = mrs.movingAvgMeanReversion.predict(new float[] { (float) lma, 1f });
double dailyReturn = diff / price - dailyRiskFreeInterestRate;
ReturnsStat returnsStat = ts.returnsStatDaily(ds.prices);
double sharpe = returnsStat.sharpeRatio();
double kelly = dailyReturn * price * price / mrs.movingAvgMeanReversion.sse;
return new PotentialStat(dailyReturn, sharpe, kelly);
}).filterValue(//
ps -> 0d < ps.kelly).cons(Asset.cashSymbol, //
new PotentialStat(Trade_.riskFreeInterestRate, 1d, 0d)).mapValue(//
ps -> ps.kelly).sortBy(//
(symbol, potential) -> -potential).take(//
top).toList();
};
};
}
Aggregations