Expand description
Ordered price-path analytics (equities or any positive price series).
§Layers
| Layer | API | Purpose |
|---|---|---|
| Scalars | simple_return, volatility, beta, … | One-off metrics |
| Solution | price_path_solution | Summary stats + formulas for a full path |
| Series | PricePathSolution::series | Period detail (return, wealth, drawdown) |
| Tables | PricePathSeries::print_table | Terminal / copy-paste output |
| TA | ta — SMA/EMA/WMA/HMA/Stoch/MACD/BB/KC/Donchian/VWAP/RVOL/RSI/ATR/LinReg + *State | Batch series + incremental push |
§Error handling (v0.1+)
Public scalars and price_path_solution return crate::FinanceResult.
Empty series, non-positive prices, length mismatches, and zero volatility cases are
structured crate::FinanceError values — not panics.
Prefer composing with ? when prices come from users or external data.
Modules§
- adx
- Average Directional Index (ADX) / +DI / −DI / DX
- atr
- Average True Range (ATR)
- bollinger
- Bollinger Bands
- cci
- Commodity Channel Index (CCI)
- donchian
- Donchian channels
- keltner
- Keltner Channels
- linear_
regression - Rolling least-squares linear regression
- macd
- MACD (Moving Average Convergence Divergence)
- mfi
- Money Flow Index (MFI)
- obv
- On-Balance Volume (OBV)
- path
- Price-path analysis: solution struct, period series, and pretty tables.
- returns
- Simple and logarithmic returns from prices.
- risk
- Risk metrics: volatility, Sharpe, Sortino, max drawdown, beta, rolling drawdown, Calmar, Ulcer index, correlation, information ratio, and trade-PnL helpers.
- rsi
- Relative Strength Index (RSI)
- rvol
- Relative volume (RVOL)
- sar
- Parabolic SAR (Stop and Reverse)
- supertrend
- Supertrend
- ta
- Technical analysis indicators on price / volume series.
- vwap
- VWAP (volume-weighted average price)
- willr
- Williams %R
Structs§
- AdxBar
Output - One-bar ADX pack (any field may still be warming up).
- AdxParams
- ADX / DI Wilder period.
- AdxSeries
- AdxSolution
- AdxState
- Incremental ADX / DI / DX.
- AtrParams
- ATR lookback pack (Wilder).
- AtrSeries
- AtrSolution
- AtrState
- Incremental Wilder ATR.
- Bollinger
BarOutput - One-bar Bollinger output.
- Bollinger
Params - Bollinger parameter pack.
- Bollinger
Series - Middle / upper / lower / %B series.
- Bollinger
Solution - Teaching solution + table.
- Bollinger
State - Incremental Bollinger Bands.
- CciParams
- CCI lookback (on typical price).
- CciSeries
- CciSolution
- CciState
- Incremental CCI. After warm-up each push is O(period) (mean absolute deviation).
- Dema
State - Double exponential moving average:
2·EMA − EMA(EMA). - Donchian
BarOutput - Donchian
Params - Donchian lookback.
- Donchian
Series - Donchian
Solution - Donchian
State - Incremental Donchian.
- EmaState
- Incremental EMA (α = 2/(period+1), seed = SMA of first
periodcloses). - HmaState
- Hull moving average state.
- Kama
Params - Kaufman Adaptive Moving Average parameters.
- Kama
State - Incremental KAMA.
- Keltner
BarOutput - Keltner
Params - Keltner parameter pack (Wilder ATR).
- Keltner
Series - Keltner
Solution - Keltner
State - Incremental Keltner (EMA mid + Wilder ATR).
- LinReg
Bar - One fitted window.
- LinReg
Params - Rolling regression window length.
- LinReg
Solution - LinReg
State - Incremental rolling regression on a caller-chosen series.
- Macd
Params - MACD parameter pack:
fast < slow, all periods ≥ 1. - Macd
Series - Aligned MACD / signal / histogram series.
- Macd
Solution - Teaching wrapper with formula strings and a printable table.
- Macd
State - Incremental MACD (fast/slow/signal EMAs).
- MfiParams
- MfiSeries
- MfiSolution
- MfiState
- Incremental MFI.
- MomBar
Output - One-bar momentum pack.
- MomParams
- Lookback for MOM / ROC / ROCP.
- MomSeries
- MomSolution
- MomState
- Incremental MOM/ROC/ROCP (shared ring of last
periodcloses + current). - Natr
Series - Normalized ATR series.
- Natr
State - Incremental NATR (wraps
AtrState). - ObvParams
- OBV has no lookback; pack is a unit for API consistency.
- ObvSeries
- ObvSolution
- ObvState
- Incremental OBV. Each
pushis O(1). - Price
Path Options - Options for
price_path_solution. - Price
Path Period - One step between consecutive prices.
- Price
Path Series - Period series for a price path. Derefs to
[PricePathPeriod]. - Price
Path Solution - Full analysis of an ordered price path.
- RmaState
- Incremental Wilder RMA (also called SMMA). α = 1/
period. - RocSeries
- Rocp
Series - RsiParams
- RSI lookback pack (Wilder).
- RsiSeries
- RsiSolution
- RsiState
- Incremental Wilder RSI.
- Rvol
Params - RVOL lookback pack.
- Rvol
Series - Rvol
Solution - Rvol
State - Incremental relative volume.
- SarBar
Output - SarParams
- Parabolic SAR acceleration parameters.
- SarSeries
- SarSolution
- SarState
- Incremental Parabolic SAR.
- SmaState
- Incremental SMA. After warm-up, each
SmaState::pushis O(1). - Stoch
BarOutput - One-bar stochastic output (warm-up allowed as
None). - Stoch
State - Incremental stochastic (fast/full via
StochasticParams). - Stochastic
Params - Unvalidated (but
Copy) stochastic parameter pack. - Stochastic
Series - Aligned %K / %D output.
- Stochastic
Solution - Teaching wrapper around
StochasticSeries. - Supertrend
Bar - Supertrend
Params - Supertrend pack: Wilder ATR period + band multiplier.
- Supertrend
Series - Supertrend
Solution - Supertrend
State - Incremental Supertrend.
- Tema
State - Triple exponential moving average:
3·e1 − 3·e2 + e3. - Validated
Adx - Validated
Atr - Validated ATR config.
- Validated
Bollinger - Validated Bollinger config.
- Validated
Cci - Validated
Donchian - Validated
Kama - Validated
Keltner - Validated Keltner config.
- Validated
LinReg - Validated pack.
- Validated
Macd - Validated MACD config for reuse across many close series.
- Validated
Mfi - Validated
Mom - Validated
Obv - Validated pack (always succeeds).
- Validated
Rsi - Validated RSI config.
- Validated
Rvol - Validated RVOL config.
- Validated
Sar - Validated
Stochastic - Params that passed period validation — safe to use in a tight loop.
- Validated
Supertrend - Validated
Vwap - Validated VWAP config.
- Validated
Willr - Validated pack.
- Vwap
Params - VWAP parameter pack.
- Vwap
Series - Vwap
Solution - Vwap
State - Incremental VWAP (cumulative or rolling). Call
VwapState::resetat session open if desired. - Willr
Params - Williams %R lookback.
- Willr
Series - Willr
Solution - Willr
State - Incremental Williams %R.
- WmaState
- Incremental WMA: newest sample weight =
period, oldest weight = 1.
Enums§
- Return
Kind - Kind of return used for mean / vol / Sharpe on the path.
- Stdev
Kind - Which denominator to use for window standard deviation (Bollinger, etc.).
- Vwap
Mode - Cumulative session vs rolling window.
- Vwap
Price Source - Price input for VWAP numerator.
Functions§
- adx
- adx_
solution - Examples
- atr
- atr_
solution - Examples
- beta
- OLS beta of asset returns vs market returns (same length series).
- bollinger
- bollinger_
solution - Teaching solution with formulas + table.
- cagr
- Compound annual growth rate:
(end / start)^(1/years) - 1. - cagr_
from_ prices - CAGR from a positive price path over
yearsyears:(end/start)^(1/years) − 1. - cagr_
from_ prices_ periods - CAGR using
(prices.len()−1) / periods_per_yearas the year fraction. - calmar_
ratio - Calmar ratio:
CAGR / |max drawdown|on a positive price series. - calmar_
ratio_ periods - Calmar with year fraction from sample length and
periods_per_year. - cci
- cci_
solution - Examples
- correlation
- Pearson correlation of two equal-length series.
- dema
- DEMA of
periodcloses. - dema_
last - donchian
- donchian_
solution - drawdown_
series - Running drawdown series (one value per price, starting at 0).
- ema
- EMA with span
period(α = 2 / (period + 1)). Seed = SMA of the firstperiodcloses. - ema_
last - Last defined EMA value, if any (via
EmaState). - expectancy
- Expectancy: mean trade P&L (including zeros).
- hma
- Hull moving average of
period(must be ≥ 2). - hma_
last - information_
ratio - Information ratio:
mean(active) / stdev(active)whereactive[i] = asset[i] − benchmark[i]. - kama
- Kaufman adaptive moving average.
- kama_
last - keltner
- keltner_
solution - Examples
- linear_
regression - Batch rolling OLS.
seriesis your choice of bar field (close, high, …). - linear_
regression_ solution - log_
return - Logarithmic return:
ln(p1 / p0). Requires strictly positive prices. - log_
returns - Log returns for consecutive prices: length
prices.len() - 1. - macd
- Free function: validate params then compute.
- macd_
solution - Solution with formulas + table for teaching / audit.
- max_
drawdown - Maximum peak-to-trough drawdown over a positive price series (most negative fraction).
- mean_
return - Arithmetic mean of a return series.
- mfi
- mfi_
solution - Examples
- mom
- mom_
solution - Examples
- natr
- Normalized ATR:
100 * ATR / closewhen both defined and close ≠ 0. - obv
- obv_
solution - Examples
- price_
path_ solution - Build a
PricePathSolutionsummarizing returns, risk, and period detail for a price path. - price_
volatility - Volatility of simple returns computed from consecutive prices.
- profit_
factor - Profit factor:
sum(positive pnl) / |sum(negative pnl)|. - rma
- Wilder RMA / SMMA of
periodcloses. - rma_
last - roc
- rocp
- rolling_
max_ drawdown - Running maximum drawdown magnitude observed up to each price index.
- rsi
- rsi_
solution - Examples
- rvol
- rvol_
solution - Examples
- sar
- sar_
solution - Examples
- sharpe_
ratio - Sharpe ratio:
(mean - risk_free) / volatilityover the return series. - simple_
return - Simple return between two prices:
(p1 - p0) / p0. - simple_
returns - Simple returns for consecutive prices: length
prices.len() - 1. - sma
- SMA of
periodcloses. Leadingperiod - 1values areNone. - sma_
last - Last defined SMA value, if any.
- sortino_
ratio - Sortino ratio:
(mean - target) / downside_deviation, using returns belowtargetonly. - stochastics
- Stochastic series with raw (possibly unvalidated) params — validates then computes.
- stochastics_
solution - Teaching solution: formulas + printable %K/%D table.
- supertrend
- supertrend_
solution - Examples
- tema
- TEMA of
periodcloses. - tema_
last - total_
return - Total simple return from first to last price:
(end - start) / start. - true_
range_ series - Per-bar true range series (same length as inputs). Bar 0 uses
H−Lonly. - ulcer_
index - Ulcer index:
sqrt(mean of squared percentage drawdowns)(Martin). - volatility
- Sample standard deviation of a return series (population divisor
n - 1). - volatility_
annualized - Annualized volatility:
volatility(returns) * sqrt(periods_per_year). - vwap
- vwap_
solution - Examples
- willr
- willr_
solution - Examples
- win_
rate - Win rate over a trade P&L series:
count(pnl > 0) / n(zeros count as non-wins). - wma
- Weighted moving average (newest weight =
period). - wma_
last