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/Stoch/MACD/BB/KC/VWAP/RVOL + *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§
- bollinger
- Bollinger Bands
- keltner
- Keltner Channels
- macd
- MACD (Moving Average Convergence Divergence)
- 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.
- rvol
- Relative volume (RVOL)
- ta
- Technical analysis indicators on price / volume series.
- vwap
- VWAP (volume-weighted average price)
Structs§
- 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 (sample stdev on the window).
- EmaState
- Incremental EMA (α = 2/(period+1), seed = SMA of first
periodcloses). - Keltner
BarOutput - Keltner
Params - Keltner parameter pack (Wilder ATR).
- Keltner
Series - Keltner
Solution - Keltner
State - Incremental Keltner (EMA mid + Wilder ATR).
- 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).
- 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.
- Rvol
Params - RVOL lookback pack.
- Rvol
Series - Rvol
Solution - Rvol
State - Incremental relative volume.
- 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. - Validated
Bollinger - Validated Bollinger config.
- Validated
Keltner - Validated Keltner config.
- Validated
Macd - Validated MACD config for reuse across many close series.
- Validated
Rvol - Validated RVOL config.
- Validated
Stochastic - Params that passed period validation — safe to use in a tight loop.
- Validated
Vwap - Validated VWAP config.
- Vwap
Params - VWAP parameter pack.
- Vwap
Series - Vwap
Solution - Vwap
State - Incremental VWAP (cumulative or rolling). Call
VwapState::resetat session open if desired.
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§
- 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. - 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). - keltner
- keltner_
solution - Examples
- 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.
- 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.
- rolling_
max_ drawdown - Running maximum drawdown magnitude observed up to each price index.
- rvol
- rvol_
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.
- total_
return - Total simple return from first to last price:
(end - start) / start. - 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