Skip to main content

Module stocks

Module stocks 

Source
Expand description

Ordered price-path analytics (equities or any positive price series).

§Layers

LayerAPIPurpose
Scalarssimple_return, volatility, beta, …One-off metrics
Solutionprice_path_solutionSummary stats + formulas for a full path
SeriesPricePathSolution::seriesPeriod detail (return, wealth, drawdown)
TablesPricePathSeries::print_tableTerminal / copy-paste output
TAta — SMA/EMA/WMA/HMA/Stoch/MACD/BB/KC/Donchian/VWAP/RVOL/RSI/ATR/LinReg + *StateBatch 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§

atr
Average True Range (ATR)
bollinger
Bollinger Bands
donchian
Donchian channels
keltner
Keltner Channels
linear_regression
Rolling least-squares linear regression
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.
rsi
Relative Strength Index (RSI)
rvol
Relative volume (RVOL)
ta
Technical analysis indicators on price / volume series.
vwap
VWAP (volume-weighted average price)

Structs§

AtrParams
ATR lookback pack (Wilder).
AtrSeries
AtrSolution
AtrState
Incremental Wilder ATR.
BollingerBarOutput
One-bar Bollinger output.
BollingerParams
Bollinger parameter pack.
BollingerSeries
Middle / upper / lower / %B series.
BollingerSolution
Teaching solution + table.
BollingerState
Incremental Bollinger Bands (sample stdev on the window).
DonchianBarOutput
DonchianParams
Donchian lookback.
DonchianSeries
DonchianSolution
DonchianState
Incremental Donchian.
EmaState
Incremental EMA (α = 2/(period+1), seed = SMA of first period closes).
HmaState
Hull moving average state.
KeltnerBarOutput
KeltnerParams
Keltner parameter pack (Wilder ATR).
KeltnerSeries
KeltnerSolution
KeltnerState
Incremental Keltner (EMA mid + Wilder ATR).
LinRegBar
One fitted window.
LinRegParams
Rolling regression window length.
LinRegSolution
LinRegState
Incremental rolling regression on a caller-chosen series.
MacdParams
MACD parameter pack: fast < slow, all periods ≥ 1.
MacdSeries
Aligned MACD / signal / histogram series.
MacdSolution
Teaching wrapper with formula strings and a printable table.
MacdState
Incremental MACD (fast/slow/signal EMAs).
PricePathOptions
Options for price_path_solution.
PricePathPeriod
One step between consecutive prices.
PricePathSeries
Period series for a price path. Derefs to [PricePathPeriod].
PricePathSolution
Full analysis of an ordered price path.
RsiParams
RSI lookback pack (Wilder).
RsiSeries
RsiSolution
RsiState
Incremental Wilder RSI.
RvolParams
RVOL lookback pack.
RvolSeries
RvolSolution
RvolState
Incremental relative volume.
SmaState
Incremental SMA. After warm-up, each SmaState::push is O(1).
StochBarOutput
One-bar stochastic output (warm-up allowed as None).
StochState
Incremental stochastic (fast/full via StochasticParams).
StochasticParams
Unvalidated (but Copy) stochastic parameter pack.
StochasticSeries
Aligned %K / %D output.
StochasticSolution
Teaching wrapper around StochasticSeries.
ValidatedAtr
Validated ATR config.
ValidatedBollinger
Validated Bollinger config.
ValidatedDonchian
ValidatedKeltner
Validated Keltner config.
ValidatedLinReg
Validated pack.
ValidatedMacd
Validated MACD config for reuse across many close series.
ValidatedRsi
Validated RSI config.
ValidatedRvol
Validated RVOL config.
ValidatedStochastic
Params that passed period validation — safe to use in a tight loop.
ValidatedVwap
Validated VWAP config.
VwapParams
VWAP parameter pack.
VwapSeries
VwapSolution
VwapState
Incremental VWAP (cumulative or rolling). Call VwapState::reset at session open if desired.
WmaState
Incremental WMA: newest sample weight = period, oldest weight = 1.

Enums§

ReturnKind
Kind of return used for mean / vol / Sharpe on the path.
StdevKind
Which denominator to use for window standard deviation (Bollinger, etc.).
VwapMode
Cumulative session vs rolling window.
VwapPriceSource
Price input for VWAP numerator.

Functions§

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.
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 first period closes.
ema_last
Last defined EMA value, if any (via EmaState).
hma
Hull moving average of period (must be ≥ 2).
hma_last
keltner
keltner_solution
Examples
linear_regression
Batch rolling OLS. series is 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.
price_path_solution
Build a PricePathSolution summarizing 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.
rsi
rsi_solution
Examples
rvol
rvol_solution
Examples
sharpe_ratio
Sharpe ratio: (mean - risk_free) / volatility over 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 period closes. Leading period - 1 values are None.
sma_last
Last defined SMA value, if any.
sortino_ratio
Sortino ratio: (mean - target) / downside_deviation, using returns below target only.
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
wma
Weighted moving average (newest weight = period).
wma_last