Class Rules
Rules over indicator arrays. All rules are
NaN-safe: a rule is never satisfied while its inputs are in warm-up.
The design decision worth knowing: a Rule is a predicate over
a BAR INDEX into precomputed indicator arrays, not over live values.
That keeps strategy definitions declarative ("RSI crossed under 30 AND
price above the 200-day") and — more importantly — makes look-ahead
bias structurally harder: the arrays are computed once by causal
indicator code, and a rule can only combine values at i and
i-1, never peek at i+1. Cross rules require the
previous bar to be on the other side (with <=/>=), so
a series that OPENS above the level does not count as a cross — the
classic off-by-one that fires a "breakout" signal on bar 0 of every
backtest. NaN warm-up bars satisfy nothing, and combining rules with
Rule.and(com.quantfinlib.dsl.Rule)/Rule.or(com.quantfinlib.dsl.Rule)/Rule.not() preserves that.
Assembled into strategies by StrategyBuilder.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Ruleabove(double[] a, double[] b) static RuleaboveValue(double[] a, double level) static Rulebelow(double[] a, double[] b) static RulebelowValue(double[] a, double level) static RulecrossAbove(double[] a, double[] b) a crossed above b on this bar.static RulecrossAboveValue(double[] a, double level) a crossed above a constant level on this bar.static RulecrossBelow(double[] a, double[] b) a crossed below b on this bar.static RulecrossBelowValue(double[] a, double level) a crossed below a constant level on this bar.static Rulefalling(double[] a, int bars) a has fallen on each of the lastbarsbars.static Rulerising(double[] a, int bars) a has risen on each of the lastbarsbars.
-
Method Details
-
crossAbove
a crossed above b on this bar. -
crossBelow
a crossed below b on this bar. -
crossAboveValue
a crossed above a constant level on this bar. -
crossBelowValue
a crossed below a constant level on this bar. -
above
-
below
-
aboveValue
-
belowValue
-
rising
a has risen on each of the lastbarsbars. -
falling
a has fallen on each of the lastbarsbars.
-