Class StrategyBuilder
java.lang.Object
com.quantfinlib.dsl.StrategyBuilder
Strategy Builder DSL: compose entry/exit rules, stop loss and take profit
into a backtestable strategy with a fluent API.
double[] close = series.closes();
double[] fast = Indicators.ema(close, 12);
double[] slow = Indicators.ema(close, 26);
BacktestResult result = StrategyBuilder.named("EMA momentum")
.enterWhen(Rules.crossAbove(fast, slow))
.exitWhen(Rules.crossBelow(fast, slow))
.withStopLoss(0.03)
.withTakeProfit(0.08)
.build()
.backtest(series, 100_000);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA rule-based strategy produced by the builder. -
Method Summary
Modifier and TypeMethodDescriptionbuild()static StrategyBuilderwithStopLoss(double pct) Per-trade stop loss as a fraction of the entry price (0.03 = 3%).withTakeProfit(double pct) Per-trade take profit as a fraction of the entry price (0.08 = 8%).
-
Method Details
-
named
-
enterWhen
-
exitWhen
-
withStopLoss
Per-trade stop loss as a fraction of the entry price (0.03 = 3%). -
withTakeProfit
Per-trade take profit as a fraction of the entry price (0.08 = 8%). -
build
-