4e3c41ea80
* feat(family-15): add 17 risk/performance metrics Implements Family 15 pragmatically as standard `Indicator`s instead of a separate `wickra-metrics` crate. Input is scalar `f64` per bar — period return, equity sample, or per-trade P&L depending on the metric. Scalar `Indicator<f64>` (14): - SharpeRatio(period, risk_free) - SortinoRatio(period, mar) - CalmarRatio(period) - OmegaRatio(period, threshold) - MaxDrawdown(period) — rolling, peak-to-trough - AverageDrawdown(period) - DrawdownDuration — cumulative, bars under water (u32 output) - PainIndex(period) - ValueAtRisk(period, confidence) - ConditionalValueAtRisk(period, confidence) - ProfitFactor(period) - GainLossRatio(period) - RecoveryFactor — cumulative, net return / max drawdown - KellyCriterion(period) Two-series `Indicator<(f64, f64)>` for (asset, benchmark) returns (3): - TreynorRatio(period, risk_free) - InformationRatio(period) - Alpha(period, risk_free) — Jensen / CAPM Touchpoints: - 17 new files under `crates/wickra-core/src/indicators/`. - `mod.rs` + `lib.rs` re-exports. - Python bindings (`bindings/python/src/lib.rs`, `__init__.py`). - Node bindings (`bindings/node/src/lib.rs`, `index.js`). - WASM bindings (`bindings/wasm/src/lib.rs`). - Fuzz: scalar metrics appended to `indicator_update.rs`; new `indicator_update_pair.rs` fuzz target for `(f64, f64)` indicators. - Python tests: SCALAR + new PAIR parameter lists in `test_new_indicators.py`, reference-value cases in `test_known_values.py`. - Node tests: scalar factories + new pair-factory block in `bindings/node/__tests__/indicators.test.js`. - Benches: 5 Family-15 benches added in `crates/wickra/benches/indicators.rs`. - Docs: README family-table row + counter (71 -> 88), CHANGELOG entry under [Unreleased]. Note: Family 12 (statistik-regression, PR #51) introduces `node_pair_indicator!` and `wasm_pair_indicator!` macros for Pearson / Beta / Spearman. Family 15 needs the same pair-input pattern but Family 12 is not yet in main, so the three pair wrappers below are written by hand in this PR. When PR #51 lands, the trivial merge-conflict is resolved by keeping the macros from Family 12 and re-using them for Treynor / IR / Alpha (drop the three handwritten wrappers). cargo check --workspace --all-features: green. * fix(family-15): satisfy clippy doc_markdown / if_not_else / digit_grouping * fix(family-15): unused TreynorRatio import, duplicate pairFactories, _eq_nan inf handling * fix(family-15): node eq() handles matching infinities for ratio indicators * test(family-15): cover cold paths flagged by codecov patch
434 lines
12 KiB
Rust
434 lines
12 KiB
Rust
//! Built-in indicators. Every indicator implements [`crate::Indicator`].
|
|
//!
|
|
//! Modules are organised internally by category (trend, momentum, volatility,
|
|
//! volume) but every public name is also re-exported flat from this module and
|
|
//! from the crate root for convenience.
|
|
|
|
mod acceleration_bands;
|
|
mod accelerator_oscillator;
|
|
mod ad_oscillator;
|
|
mod adaptive_cycle;
|
|
mod adl;
|
|
mod adx;
|
|
mod adxr;
|
|
mod alligator;
|
|
mod alma;
|
|
mod alpha;
|
|
mod anchored_vwap;
|
|
mod apo;
|
|
mod aroon;
|
|
mod aroon_oscillator;
|
|
mod atr;
|
|
mod atr_bands;
|
|
mod atr_trailing_stop;
|
|
mod autocorrelation;
|
|
mod average_drawdown;
|
|
mod awesome_oscillator;
|
|
mod awesome_oscillator_histogram;
|
|
mod balance_of_power;
|
|
mod beta;
|
|
mod bollinger;
|
|
mod bollinger_bandwidth;
|
|
mod calmar_ratio;
|
|
mod camarilla_pivots;
|
|
mod cci;
|
|
mod center_of_gravity;
|
|
mod cfo;
|
|
mod chaikin_oscillator;
|
|
mod chaikin_volatility;
|
|
mod chande_kroll_stop;
|
|
mod chandelier_exit;
|
|
mod choppiness_index;
|
|
mod classic_pivots;
|
|
mod cmf;
|
|
mod cmo;
|
|
mod coefficient_of_variation;
|
|
mod conditional_value_at_risk;
|
|
mod connors_rsi;
|
|
mod coppock;
|
|
mod cybernetic_cycle;
|
|
mod decycler;
|
|
mod decycler_oscillator;
|
|
mod dema;
|
|
mod demand_index;
|
|
mod demark_pivots;
|
|
mod detrended_std_dev;
|
|
mod doji;
|
|
mod donchian;
|
|
mod donchian_stop;
|
|
mod double_bollinger;
|
|
mod dpo;
|
|
mod drawdown_duration;
|
|
mod ease_of_movement;
|
|
mod ehlers_stochastic;
|
|
mod elder_impulse;
|
|
mod ema;
|
|
mod empirical_mode_decomposition;
|
|
mod engulfing;
|
|
mod evwma;
|
|
mod fama;
|
|
mod fibonacci_pivots;
|
|
mod fisher_transform;
|
|
mod force_index;
|
|
mod fractal_chaos_bands;
|
|
mod frama;
|
|
mod gain_loss_ratio;
|
|
mod garman_klass;
|
|
mod hammer;
|
|
mod hanging_man;
|
|
mod harami;
|
|
mod heikin_ashi;
|
|
mod hilbert_dominant_cycle;
|
|
mod hilo_activator;
|
|
mod historical_volatility;
|
|
mod hma;
|
|
mod hurst_channel;
|
|
mod hurst_exponent;
|
|
mod ichimoku;
|
|
mod inertia;
|
|
mod information_ratio;
|
|
mod initial_balance;
|
|
mod instantaneous_trendline;
|
|
mod inverse_fisher_transform;
|
|
mod inverted_hammer;
|
|
mod jma;
|
|
mod kama;
|
|
mod kelly_criterion;
|
|
mod keltner;
|
|
mod kst;
|
|
mod kurtosis;
|
|
mod kvo;
|
|
mod laguerre_rsi;
|
|
mod linreg;
|
|
mod linreg_angle;
|
|
mod linreg_channel;
|
|
mod linreg_slope;
|
|
mod ma_envelope;
|
|
mod macd;
|
|
mod mama;
|
|
mod market_facilitation_index;
|
|
mod marubozu;
|
|
mod mass_index;
|
|
mod max_drawdown;
|
|
mod mcginley_dynamic;
|
|
mod median_absolute_deviation;
|
|
mod median_price;
|
|
mod mfi;
|
|
mod mom;
|
|
mod morning_evening_star;
|
|
mod natr;
|
|
mod nvi;
|
|
mod obv;
|
|
mod omega_ratio;
|
|
mod opening_range;
|
|
mod pain_index;
|
|
mod parkinson;
|
|
mod pearson_correlation;
|
|
mod percent_b;
|
|
mod percentage_trailing_stop;
|
|
mod pgo;
|
|
mod piercing_dark_cloud;
|
|
mod pmo;
|
|
mod ppo;
|
|
mod profit_factor;
|
|
mod psar;
|
|
mod pvi;
|
|
mod r_squared;
|
|
mod recovery_factor;
|
|
mod renko_trailing_stop;
|
|
mod roc;
|
|
mod rogers_satchell;
|
|
mod roofing_filter;
|
|
mod rsi;
|
|
mod rvi;
|
|
mod rvi_volatility;
|
|
mod rwi;
|
|
mod sharpe_ratio;
|
|
mod shooting_star;
|
|
mod sine_wave;
|
|
mod skewness;
|
|
mod sma;
|
|
mod smi;
|
|
mod smma;
|
|
mod sortino_ratio;
|
|
mod spearman_correlation;
|
|
mod spinning_top;
|
|
mod standard_error;
|
|
mod standard_error_bands;
|
|
mod starc_bands;
|
|
mod stc;
|
|
mod std_dev;
|
|
mod step_trailing_stop;
|
|
mod stoch_rsi;
|
|
mod stochastic;
|
|
mod super_smoother;
|
|
mod super_trend;
|
|
mod t3;
|
|
mod td_combo;
|
|
mod td_countdown;
|
|
mod td_demarker;
|
|
mod td_differential;
|
|
mod td_lines;
|
|
mod td_open;
|
|
mod td_pressure;
|
|
mod td_range_projection;
|
|
mod td_rei;
|
|
mod td_risk_level;
|
|
mod td_sequential;
|
|
mod td_setup;
|
|
mod tema;
|
|
mod three_inside;
|
|
mod three_outside;
|
|
mod three_soldiers_or_crows;
|
|
mod tii;
|
|
mod treynor_ratio;
|
|
mod trima;
|
|
mod trix;
|
|
mod true_range;
|
|
mod tsi;
|
|
mod tsv;
|
|
mod ttm_squeeze;
|
|
mod tweezer;
|
|
mod typical_price;
|
|
mod ulcer_index;
|
|
mod ultimate_oscillator;
|
|
mod value_area;
|
|
mod value_at_risk;
|
|
mod variance;
|
|
mod vertical_horizontal_filter;
|
|
mod vidya;
|
|
mod volty_stop;
|
|
mod volume_oscillator;
|
|
mod vortex;
|
|
mod vpt;
|
|
mod vwap;
|
|
mod vwap_stddev_bands;
|
|
mod vwma;
|
|
mod vzo;
|
|
mod wave_trend;
|
|
mod weighted_close;
|
|
mod williams_fractals;
|
|
mod williams_r;
|
|
mod wma;
|
|
mod woodie_pivots;
|
|
mod yang_zhang;
|
|
mod yoyo_exit;
|
|
mod z_score;
|
|
mod zero_lag_macd;
|
|
mod zig_zag;
|
|
mod zlema;
|
|
|
|
pub use acceleration_bands::{AccelerationBands, AccelerationBandsOutput};
|
|
pub use accelerator_oscillator::AcceleratorOscillator;
|
|
pub use ad_oscillator::AdOscillator;
|
|
pub use adaptive_cycle::AdaptiveCycle;
|
|
pub use adl::Adl;
|
|
pub use adx::{Adx, AdxOutput};
|
|
pub use adxr::Adxr;
|
|
pub use alligator::{Alligator, AlligatorOutput};
|
|
pub use alma::Alma;
|
|
pub use alpha::Alpha;
|
|
pub use anchored_vwap::AnchoredVwap;
|
|
pub use apo::Apo;
|
|
pub use aroon::{Aroon, AroonOutput};
|
|
pub use aroon_oscillator::AroonOscillator;
|
|
pub use atr::Atr;
|
|
pub use atr_bands::{AtrBands, AtrBandsOutput};
|
|
pub use atr_trailing_stop::AtrTrailingStop;
|
|
pub use autocorrelation::Autocorrelation;
|
|
pub use average_drawdown::AverageDrawdown;
|
|
pub use awesome_oscillator::AwesomeOscillator;
|
|
pub use awesome_oscillator_histogram::AwesomeOscillatorHistogram;
|
|
pub use balance_of_power::BalanceOfPower;
|
|
pub use beta::Beta;
|
|
pub use bollinger::{BollingerBands, BollingerOutput};
|
|
pub use bollinger_bandwidth::BollingerBandwidth;
|
|
pub use calmar_ratio::CalmarRatio;
|
|
pub use camarilla_pivots::{Camarilla, CamarillaPivotsOutput};
|
|
pub use cci::Cci;
|
|
pub use center_of_gravity::CenterOfGravity;
|
|
pub use cfo::Cfo;
|
|
pub use chaikin_oscillator::ChaikinOscillator;
|
|
pub use chaikin_volatility::ChaikinVolatility;
|
|
pub use chande_kroll_stop::{ChandeKrollStop, ChandeKrollStopOutput};
|
|
pub use chandelier_exit::{ChandelierExit, ChandelierExitOutput};
|
|
pub use choppiness_index::ChoppinessIndex;
|
|
pub use classic_pivots::{ClassicPivots, ClassicPivotsOutput};
|
|
pub use cmf::ChaikinMoneyFlow;
|
|
pub use cmo::Cmo;
|
|
pub use coefficient_of_variation::CoefficientOfVariation;
|
|
pub use conditional_value_at_risk::ConditionalValueAtRisk;
|
|
pub use connors_rsi::ConnorsRsi;
|
|
pub use coppock::Coppock;
|
|
pub use cybernetic_cycle::CyberneticCycle;
|
|
pub use decycler::Decycler;
|
|
pub use decycler_oscillator::DecyclerOscillator;
|
|
pub use dema::Dema;
|
|
pub use demand_index::DemandIndex;
|
|
pub use demark_pivots::{DemarkPivots, DemarkPivotsOutput};
|
|
pub use detrended_std_dev::DetrendedStdDev;
|
|
pub use doji::Doji;
|
|
pub use donchian::{Donchian, DonchianOutput};
|
|
pub use donchian_stop::{DonchianStop, DonchianStopOutput};
|
|
pub use double_bollinger::{DoubleBollinger, DoubleBollingerOutput};
|
|
pub use dpo::Dpo;
|
|
pub use drawdown_duration::DrawdownDuration;
|
|
pub use ease_of_movement::EaseOfMovement;
|
|
pub use ehlers_stochastic::EhlersStochastic;
|
|
pub use elder_impulse::ElderImpulse;
|
|
pub use ema::Ema;
|
|
pub use empirical_mode_decomposition::EmpiricalModeDecomposition;
|
|
pub use engulfing::Engulfing;
|
|
pub use evwma::Evwma;
|
|
pub use fama::Fama;
|
|
pub use fibonacci_pivots::{FibonacciPivots, FibonacciPivotsOutput};
|
|
pub use fisher_transform::FisherTransform;
|
|
pub use force_index::ForceIndex;
|
|
pub use fractal_chaos_bands::{FractalChaosBands, FractalChaosBandsOutput};
|
|
pub use frama::Frama;
|
|
pub use gain_loss_ratio::GainLossRatio;
|
|
pub use garman_klass::GarmanKlassVolatility;
|
|
pub use hammer::Hammer;
|
|
pub use hanging_man::HangingMan;
|
|
pub use harami::Harami;
|
|
pub use heikin_ashi::{HeikinAshi, HeikinAshiOutput};
|
|
pub use hilbert_dominant_cycle::HilbertDominantCycle;
|
|
pub use hilo_activator::HiLoActivator;
|
|
pub use historical_volatility::HistoricalVolatility;
|
|
pub use hma::Hma;
|
|
pub use hurst_channel::{HurstChannel, HurstChannelOutput};
|
|
pub use hurst_exponent::HurstExponent;
|
|
pub use ichimoku::{Ichimoku, IchimokuOutput};
|
|
pub use inertia::Inertia;
|
|
pub use information_ratio::InformationRatio;
|
|
pub use initial_balance::{InitialBalance, InitialBalanceOutput};
|
|
pub use instantaneous_trendline::InstantaneousTrendline;
|
|
pub use inverse_fisher_transform::InverseFisherTransform;
|
|
pub use inverted_hammer::InvertedHammer;
|
|
pub use jma::Jma;
|
|
pub use kama::Kama;
|
|
pub use kelly_criterion::KellyCriterion;
|
|
pub use keltner::{Keltner, KeltnerOutput};
|
|
pub use kst::{Kst, KstOutput};
|
|
pub use kurtosis::Kurtosis;
|
|
pub use kvo::Kvo;
|
|
pub use laguerre_rsi::LaguerreRsi;
|
|
pub use linreg::LinearRegression;
|
|
pub use linreg_angle::LinRegAngle;
|
|
pub use linreg_channel::{LinRegChannel, LinRegChannelOutput};
|
|
pub use linreg_slope::LinRegSlope;
|
|
pub use ma_envelope::{MaEnvelope, MaEnvelopeOutput};
|
|
pub use macd::{MacdIndicator, MacdOutput};
|
|
pub use mama::{Mama, MamaOutput};
|
|
pub use market_facilitation_index::MarketFacilitationIndex;
|
|
pub use marubozu::Marubozu;
|
|
pub use mass_index::MassIndex;
|
|
pub use max_drawdown::MaxDrawdown;
|
|
pub use mcginley_dynamic::McGinleyDynamic;
|
|
pub use median_absolute_deviation::MedianAbsoluteDeviation;
|
|
pub use median_price::MedianPrice;
|
|
pub use mfi::Mfi;
|
|
pub use mom::Mom;
|
|
pub use morning_evening_star::MorningEveningStar;
|
|
pub use natr::Natr;
|
|
pub use nvi::Nvi;
|
|
pub use obv::Obv;
|
|
pub use omega_ratio::OmegaRatio;
|
|
pub use opening_range::{OpeningRange, OpeningRangeOutput};
|
|
pub use pain_index::PainIndex;
|
|
pub use parkinson::ParkinsonVolatility;
|
|
pub use pearson_correlation::PearsonCorrelation;
|
|
pub use percent_b::PercentB;
|
|
pub use percentage_trailing_stop::PercentageTrailingStop;
|
|
pub use pgo::Pgo;
|
|
pub use piercing_dark_cloud::PiercingDarkCloud;
|
|
pub use pmo::Pmo;
|
|
pub use ppo::Ppo;
|
|
pub use profit_factor::ProfitFactor;
|
|
pub use psar::Psar;
|
|
pub use pvi::Pvi;
|
|
pub use r_squared::RSquared;
|
|
pub use recovery_factor::RecoveryFactor;
|
|
pub use renko_trailing_stop::RenkoTrailingStop;
|
|
pub use roc::Roc;
|
|
pub use rogers_satchell::RogersSatchellVolatility;
|
|
pub use roofing_filter::RoofingFilter;
|
|
pub use rsi::Rsi;
|
|
pub use rvi::Rvi;
|
|
pub use rvi_volatility::RviVolatility;
|
|
pub use rwi::{Rwi, RwiOutput};
|
|
pub use sharpe_ratio::SharpeRatio;
|
|
pub use shooting_star::ShootingStar;
|
|
pub use sine_wave::SineWave;
|
|
pub use skewness::Skewness;
|
|
pub use sma::Sma;
|
|
pub use smi::Smi;
|
|
pub use smma::Smma;
|
|
pub use sortino_ratio::SortinoRatio;
|
|
pub use spearman_correlation::SpearmanCorrelation;
|
|
pub use spinning_top::SpinningTop;
|
|
pub use standard_error::StandardError;
|
|
pub use standard_error_bands::{StandardErrorBands, StandardErrorBandsOutput};
|
|
pub use starc_bands::{StarcBands, StarcBandsOutput};
|
|
pub use stc::Stc;
|
|
pub use std_dev::StdDev;
|
|
pub use step_trailing_stop::StepTrailingStop;
|
|
pub use stoch_rsi::StochRsi;
|
|
pub use stochastic::{Stochastic, StochasticOutput};
|
|
pub use super_smoother::SuperSmoother;
|
|
pub use super_trend::{SuperTrend, SuperTrendOutput};
|
|
pub use t3::T3;
|
|
pub use td_combo::TdCombo;
|
|
pub use td_countdown::TdCountdown;
|
|
pub use td_demarker::TdDeMarker;
|
|
pub use td_differential::TdDifferential;
|
|
pub use td_lines::{TdLines, TdLinesOutput};
|
|
pub use td_open::TdOpen;
|
|
pub use td_pressure::TdPressure;
|
|
pub use td_range_projection::{TdRangeProjection, TdRangeProjectionOutput};
|
|
pub use td_rei::TdRei;
|
|
pub use td_risk_level::{TdRiskLevel, TdRiskLevelOutput};
|
|
pub use td_sequential::{TdSequential, TdSequentialOutput};
|
|
pub use td_setup::TdSetup;
|
|
pub use tema::Tema;
|
|
pub use three_inside::ThreeInside;
|
|
pub use three_outside::ThreeOutside;
|
|
pub use three_soldiers_or_crows::ThreeSoldiersOrCrows;
|
|
pub use tii::Tii;
|
|
pub use treynor_ratio::TreynorRatio;
|
|
pub use trima::Trima;
|
|
pub use trix::Trix;
|
|
pub use true_range::TrueRange;
|
|
pub use tsi::Tsi;
|
|
pub use tsv::Tsv;
|
|
pub use ttm_squeeze::{TtmSqueeze, TtmSqueezeOutput};
|
|
pub use tweezer::Tweezer;
|
|
pub use typical_price::TypicalPrice;
|
|
pub use ulcer_index::UlcerIndex;
|
|
pub use ultimate_oscillator::UltimateOscillator;
|
|
pub use value_area::{ValueArea, ValueAreaOutput};
|
|
pub use value_at_risk::ValueAtRisk;
|
|
pub use variance::Variance;
|
|
pub use vertical_horizontal_filter::VerticalHorizontalFilter;
|
|
pub use vidya::Vidya;
|
|
pub use volty_stop::VoltyStop;
|
|
pub use volume_oscillator::VolumeOscillator;
|
|
pub use vortex::{Vortex, VortexOutput};
|
|
pub use vpt::VolumePriceTrend;
|
|
pub use vwap::{RollingVwap, Vwap};
|
|
pub use vwap_stddev_bands::{VwapStdDevBands, VwapStdDevBandsOutput};
|
|
pub use vwma::Vwma;
|
|
pub use vzo::Vzo;
|
|
pub use wave_trend::{WaveTrend, WaveTrendOutput};
|
|
pub use weighted_close::WeightedClose;
|
|
pub use williams_fractals::{WilliamsFractals, WilliamsFractalsOutput};
|
|
pub use williams_r::WilliamsR;
|
|
pub use wma::Wma;
|
|
pub use woodie_pivots::{WoodiePivots, WoodiePivotsOutput};
|
|
pub use yang_zhang::YangZhangVolatility;
|
|
pub use yoyo_exit::YoyoExit;
|
|
pub use z_score::ZScore;
|
|
pub use zero_lag_macd::{ZeroLagMacd, ZeroLagMacdOutput};
|
|
pub use zig_zag::{ZigZag, ZigZagOutput};
|
|
pub use zlema::Zlema;
|