kestrel-chartkitv0.41.0

API overview

The entry points used in these docs. Root-level re-exports are the preferred API; item-level documentation is generated by rustdoc.

Note

The generated documentation for every public item is on docs.rs, including the optional calendar module. For an unreleased state, run cargo doc --open in a clone of the repository.

Overview

Where the main entry points sitYour application passes bars into kestrel-chartkit. The registry builds indicators from their definitions; indicators stream values, extras and alerts; classify_regime and the scoring functions turn readings into a regime and a composite signal; structure and analytics read the bars directly. Everything comes back as plain data, which a renderer such as chartlet or kestrel-loom draws.Where the main entry points sitkestrel-chartkit (pure computation)Your application → Registry: name and parametersRegistry → Definitions: validates againstRegistry → Indicators: buildsYour application → Indicators: bars, one at a timeIndicators → Regime and scoring: outputs and alertsYour application → Structure and analytics: bar historyRegime and scoring → Your application: regime, signal, risk planYour application → Renderer: values to drawname and parametersvalidates againstbuildsbars, one at a timeoutputs and alertsbar historyregime, signal, risk planvalues to drawYour application – bars from your data sourceYour applicationbars from your data sourceRegistry – catalog, build_checked, build_typedRegistrycatalog, build_checked,build_typedDefinitions – parameters, ranges, relationsDefinitionsparameters, ranges, relationsIndicators – Indicator::on_bar, alertsIndicatorsIndicator::on_bar, alertsRegime and scoring – classify_regime, aggregate_subscoresRegime and scoringclassify_regime,aggregate_subscoresStructure and analytics – pivots, zones, read-outs, evaluationStructure and analyticspivots, zones, read-outs,evaluationRenderer – chartlet, kestrel-loomRendererchartlet, kestrel-loom

Indicators

fncatalog
pub fn catalog() -> Vec<IndicatorCatalogEntry>

Every registered indicator with name, description and default parameters.

fnoutput_unit
pub fn output_unit(name: &str) -> IndicatorUnit

What an indicator’s primary output is quoted in: Price, Ratio, Volume or Unitless. Price means a price level and belongs on the price axis; everything else needs its own scale. Unknown names return Unitless.

fnbuild_checked
pub fn build_checked(
  name: &str,
  params: &HashMap<String, f64>,
) -> Result<Box<dyn Indicator>, RegistryError>

Parameters

name
&str
A name from catalog(), e.g. "rsi".
params
&HashMap<String, f64>
Parameter overrides. Missing keys take the defaults.
traitIndicator
pub trait Indicator: Send + Sync {
  fn on_bar(&mut self, bar: &Bar) -> Option<IndicatorOutput>;
  fn on_checked_bar(&mut self, bar: &Bar) -> Result<Option<IndicatorOutput>, BarValidationError>;
  fn alerts(&self) -> Vec<IndicatorAlert>;
  fn warmup_period(&self) -> usize;
  fn reset(&mut self);
}

See Indicators for the output fields.

fnpair_catalog
pub fn pair_catalog() -> Vec<IndicatorCatalogEntry>

The indicators that read two bar series (relative_strength, correlation). None of them is in catalog(); input_series(name) returns Some(2) for these names and Some(1) for the others.

fnbuild_pair_checked
pub fn build_pair_checked(
  name: &str,
  params: &HashMap<String, f64>,
) -> Result<Box<dyn PairIndicator>, RegistryError>

Parameters

name
&str
A name from pair_catalog(), e.g. "relative_strength".
params
&HashMap<String, f64>
Parameter overrides. Missing keys take the defaults.
fnrun_pair_batch
pub fn run_pair_batch<P: PairIndicator + ?Sized>(
  indicator: &mut P,
  bars: &[Bar],
  reference: &[Bar],
) -> Vec<TimestampedOutput>

Pairs the bars of the two series by timestamp and returns one entry per bar of bars. See Two series for the pairing rules.

Market regime

fnclassify_regime
pub fn classify_regime(bars: &[Bar], adx_val: f64, atr_val: f64) -> MarketRegime

Parameters

bars
&[Bar]
History up to the current bar; at least 21 bars.
adx_val
f64
Current ADX value.
atr_val
f64
Current ATR as a fraction of price (ATR / close).

Composite scoring

fnscore_indicator
pub fn score_indicator(name: &str, output: &IndicatorOutput, alerts: &[IndicatorAlert]) -> SubScore
fnaggregate_subscores
pub fn aggregate_subscores(
  subscores: Vec<SubScore>,
  weights: Option<&HashMap<String, f64>>,
  regime: MarketRegime,
  sr_zones: Vec<SupportResistanceZone>,
  latest_bar: Option<&Bar>,
  atr_val: f64,
) -> CompositeSignal

See Composite scoring for thresholds and grades.

Visualisation

kestrel-chartkit draws nothing for presentation; see Visualising results for chartlet and kestrel-loom.

structviz::scene::Scene
pub struct Scene { /* panes, axes and objects */ }

The renderer-neutral scene model for overlays (markers, levels, zones) that kestrel-loom draws.

fnviz::render_chart_svg / viz::render_scene_svg
pub fn render_chart_svg(data: &ChartRenderData, width: u32, height: u32) -> String

Quick-look SVG for tests and debugging, not a presentation layer.

Options at expiry

structOptionExpiryPosition
pub struct OptionExpiryPosition {
  pub option_type: OptionType,   // Call | Put
  pub side: PositionSide,        // Long = bought, Short = sold
  pub strike: f64,
  pub premium: f64,              // per unit of the underlying, the positive amount
  pub contract_size: f64,        // 1.0 = every amount per unit
}

One option position held to expiry. The result at expiry needs no pricing model.

fnoption_expiry_result
pub fn option_expiry_result(
  position: &OptionExpiryPosition,
  underlying: f64,
) -> Result<f64, OptionError>

(intrinsic - premium) * contract_size for the bought option and its negative for the sold one, with intrinsic = max(S - K, 0) for a call and max(K - S, 0) for a put. Positive is a profit of the position’s holder.

fnoption_expiry_profile
pub fn option_expiry_profile(
  position: &OptionExpiryPosition,
) -> Result<OptionExpiryProfile, OptionError>

break_even (K + P for a call, K - P for a put), max_profit and max_loss over every price from 0 up. Both are a PayoffBound: Limited(amount) or Unlimited, so no infinite number reaches an axis or a JSON document. max_loss is a positive amount.

fnoption_expiry_series
pub fn option_expiry_series(
  position: &OptionExpiryPosition,
  from: f64,
  to: f64,
  points: usize,
) -> Result<Vec<OptionExpiryPoint>, OptionError>

The result over points equally spaced prices from from to to, both included, for a payoff diagram. The line through the points shows the bend at the strike exactly when the strike is one of them.

Beyond these docs

The crate also exports trade statistics (stats, evaluation), option and bond valuation (option, finance, valuation), portfolio risk and stress (portfolio, risk, stress), bar transforms such as Heikin-Ashi (transform) and the optional exchange calendar (calendar). The README gives an overview.

Edit this page on GitHub · Docs for v0.41.0