5867f71450
* feat(core): add 3 trade-flow microstructure indicators SignedVolume (per-trade size signed by aggressor), CumulativeVolumeDelta (running signed-volume total), and TradeImbalance (rolling buy/sell volume imbalance over a trade window). All consume the Trade type, with full unit coverage. Extends the Microstructure family. * feat(bindings): expose trade-flow microstructure indicators Python, Node and WASM bindings for SignedVolume, CumulativeVolumeDelta and TradeImbalance. Each takes a trade via update(price, size, is_buy); Python and Node expose a batch over three parallel arrays, WASM exposes per-trade update. Regenerates node index.d.ts/.js. * test(bindings,fuzz,bench): cover trade-flow microstructure indicators Python and Node: reference values, streaming-vs-batch, lifecycle/repr and input validation (zero window, negative size, non-positive price, mismatched batch lengths). New indicator_update_trade fuzz target. Synthetic trade-tape benches (signed_volume cheapest, trade_imbalance windowed/expensive). * docs: add trade-flow indicators + bump counter to 227 README Microstructure family row gains signed volume / CVD / trade imbalance and the counter goes 224 -> 227; CHANGELOG records the trade-flow indicators.
519 lines
9.3 KiB
Python
519 lines
9.3 KiB
Python
"""Wickra: streaming-first technical indicators.
|
|
|
|
Every indicator is available both in streaming mode (call ``update(value)`` per
|
|
new data point) and batch mode (call ``batch(numpy_array)`` over a full series).
|
|
Warmup positions in batch output are returned as ``NaN`` so the shape always
|
|
matches the input.
|
|
|
|
Example::
|
|
|
|
import numpy as np
|
|
import wickra as ta
|
|
|
|
prices = np.linspace(100, 200, 1000)
|
|
rsi = ta.RSI(14)
|
|
values = rsi.batch(prices) # numpy array, NaN during warmup
|
|
|
|
# Or streaming:
|
|
rsi = ta.RSI(14)
|
|
for p in prices:
|
|
v = rsi.update(p) # None during warmup, then float
|
|
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from ._wickra import (
|
|
__version__,
|
|
# Trend
|
|
SMA,
|
|
EMA,
|
|
WMA,
|
|
DEMA,
|
|
TEMA,
|
|
HMA,
|
|
KAMA,
|
|
SMMA,
|
|
TRIMA,
|
|
ZLEMA,
|
|
T3,
|
|
VWMA,
|
|
ALMA,
|
|
McGinleyDynamic,
|
|
FRAMA,
|
|
VIDYA,
|
|
JMA,
|
|
Alligator,
|
|
EVWMA,
|
|
# Momentum
|
|
RSI,
|
|
MACD,
|
|
Stochastic,
|
|
CCI,
|
|
ROC,
|
|
WilliamsR,
|
|
ADX,
|
|
ADXR,
|
|
MFI,
|
|
TRIX,
|
|
AwesomeOscillator,
|
|
Aroon,
|
|
MOM,
|
|
CMO,
|
|
TSI,
|
|
PMO,
|
|
TII,
|
|
KST,
|
|
StochRSI,
|
|
UltimateOscillator,
|
|
RVI,
|
|
PGO,
|
|
KST,
|
|
SMI,
|
|
LaguerreRSI,
|
|
ConnorsRSI,
|
|
Inertia,
|
|
APO,
|
|
AwesomeOscillatorHistogram,
|
|
CFO,
|
|
ZeroLagMACD,
|
|
ElderImpulse,
|
|
STC,
|
|
PPO,
|
|
DPO,
|
|
Coppock,
|
|
AroonOscillator,
|
|
Vortex,
|
|
RWI,
|
|
WaveTrend,
|
|
MassIndex,
|
|
AcceleratorOscillator,
|
|
BalanceOfPower,
|
|
ChoppinessIndex,
|
|
VerticalHorizontalFilter,
|
|
# Volatility
|
|
BollingerBands,
|
|
ATR,
|
|
Keltner,
|
|
Donchian,
|
|
PSAR,
|
|
NATR,
|
|
StdDev,
|
|
UlcerIndex,
|
|
HistoricalVolatility,
|
|
BollingerBandwidth,
|
|
PercentB,
|
|
SuperTrend,
|
|
ChandelierExit,
|
|
ChandeKrollStop,
|
|
AtrTrailingStop,
|
|
HiLoActivator,
|
|
VoltyStop,
|
|
YoyoExit,
|
|
DonchianStop,
|
|
PercentageTrailingStop,
|
|
StepTrailingStop,
|
|
RenkoTrailingStop,
|
|
TrueRange,
|
|
ChaikinVolatility,
|
|
RVIVolatility,
|
|
ParkinsonVolatility,
|
|
GarmanKlassVolatility,
|
|
RogersSatchellVolatility,
|
|
YangZhangVolatility,
|
|
# Volume
|
|
OBV,
|
|
VWAP,
|
|
RollingVWAP,
|
|
ADL,
|
|
VolumePriceTrend,
|
|
ChaikinMoneyFlow,
|
|
ChaikinOscillator,
|
|
ForceIndex,
|
|
KVO,
|
|
VolumeOscillator,
|
|
NVI,
|
|
PVI,
|
|
WilliamsAD,
|
|
AnchoredVWAP,
|
|
DemandIndex,
|
|
TSV,
|
|
VZO,
|
|
MarketFacilitationIndex,
|
|
EaseOfMovement,
|
|
# Statistics
|
|
TypicalPrice,
|
|
MedianPrice,
|
|
WeightedClose,
|
|
LinearRegression,
|
|
LinRegSlope,
|
|
ZScore,
|
|
LinRegAngle,
|
|
Variance,
|
|
CoefficientOfVariation,
|
|
Skewness,
|
|
Kurtosis,
|
|
StandardError,
|
|
DetrendedStdDev,
|
|
RSquared,
|
|
Autocorrelation,
|
|
MedianAbsoluteDeviation,
|
|
HurstExponent,
|
|
PearsonCorrelation,
|
|
Beta,
|
|
PairwiseBeta,
|
|
PairSpreadZScore,
|
|
LeadLagCrossCorrelation,
|
|
Cointegration,
|
|
RelativeStrengthAB,
|
|
SpearmanCorrelation,
|
|
# Ehlers / Cycle
|
|
SuperSmoother,
|
|
FisherTransform,
|
|
InverseFisherTransform,
|
|
Decycler,
|
|
DecyclerOscillator,
|
|
RoofingFilter,
|
|
CenterOfGravity,
|
|
CyberneticCycle,
|
|
InstantaneousTrendline,
|
|
EhlersStochastic,
|
|
EmpiricalModeDecomposition,
|
|
HilbertDominantCycle,
|
|
AdaptiveCycle,
|
|
SineWave,
|
|
MAMA,
|
|
FAMA,
|
|
# Bands & Channels
|
|
MaEnvelope,
|
|
AccelerationBands,
|
|
StarcBands,
|
|
AtrBands,
|
|
HurstChannel,
|
|
LinRegChannel,
|
|
StandardErrorBands,
|
|
DoubleBollinger,
|
|
TtmSqueeze,
|
|
FractalChaosBands,
|
|
VwapStdDevBands,
|
|
# Pivots & S/R
|
|
ClassicPivots,
|
|
FibonacciPivots,
|
|
Camarilla,
|
|
WoodiePivots,
|
|
DemarkPivots,
|
|
WilliamsFractals,
|
|
ZigZag,
|
|
# DeMark
|
|
TDSetup,
|
|
TDSequential,
|
|
TDDeMarker,
|
|
TDREI,
|
|
TDPressure,
|
|
TDCombo,
|
|
TDCountdown,
|
|
TDLines,
|
|
TDRangeProjection,
|
|
TDDifferential,
|
|
TDOpen,
|
|
TDRiskLevel,
|
|
# Ichimoku & alternative charts
|
|
Ichimoku,
|
|
HeikinAshi,
|
|
# Market Profile
|
|
ValueArea,
|
|
InitialBalance,
|
|
OpeningRange,
|
|
# Candlestick patterns
|
|
Doji,
|
|
Hammer,
|
|
InvertedHammer,
|
|
HangingMan,
|
|
ShootingStar,
|
|
Engulfing,
|
|
Harami,
|
|
MorningEveningStar,
|
|
ThreeSoldiersOrCrows,
|
|
PiercingDarkCloud,
|
|
Marubozu,
|
|
Tweezer,
|
|
SpinningTop,
|
|
ThreeInside,
|
|
ThreeOutside,
|
|
# Microstructure: order book
|
|
OrderBookImbalanceTop1,
|
|
OrderBookImbalanceTopN,
|
|
OrderBookImbalanceFull,
|
|
Microprice,
|
|
QuotedSpread,
|
|
# Microstructure: trade flow
|
|
SignedVolume,
|
|
CumulativeVolumeDelta,
|
|
TradeImbalance,
|
|
# Risk / Performance
|
|
SharpeRatio,
|
|
SortinoRatio,
|
|
CalmarRatio,
|
|
OmegaRatio,
|
|
MaxDrawdown,
|
|
AverageDrawdown,
|
|
DrawdownDuration,
|
|
PainIndex,
|
|
ValueAtRisk,
|
|
ConditionalValueAtRisk,
|
|
ProfitFactor,
|
|
GainLossRatio,
|
|
RecoveryFactor,
|
|
KellyCriterion,
|
|
TreynorRatio,
|
|
InformationRatio,
|
|
Alpha,
|
|
)
|
|
|
|
__all__ = [
|
|
"__version__",
|
|
# Trend
|
|
"SMA",
|
|
"EMA",
|
|
"WMA",
|
|
"DEMA",
|
|
"TEMA",
|
|
"HMA",
|
|
"KAMA",
|
|
"SMMA",
|
|
"TRIMA",
|
|
"ZLEMA",
|
|
"T3",
|
|
"VWMA",
|
|
"ALMA",
|
|
"McGinleyDynamic",
|
|
"FRAMA",
|
|
"VIDYA",
|
|
"JMA",
|
|
"Alligator",
|
|
"EVWMA",
|
|
# Momentum
|
|
"RSI",
|
|
"MACD",
|
|
"Stochastic",
|
|
"CCI",
|
|
"ROC",
|
|
"WilliamsR",
|
|
"ADX",
|
|
"ADXR",
|
|
"MFI",
|
|
"TRIX",
|
|
"AwesomeOscillator",
|
|
"Aroon",
|
|
"MOM",
|
|
"CMO",
|
|
"TSI",
|
|
"PMO",
|
|
"TII",
|
|
"KST",
|
|
"StochRSI",
|
|
"UltimateOscillator",
|
|
"RVI",
|
|
"PGO",
|
|
"KST",
|
|
"SMI",
|
|
"LaguerreRSI",
|
|
"ConnorsRSI",
|
|
"Inertia",
|
|
"APO",
|
|
"AwesomeOscillatorHistogram",
|
|
"CFO",
|
|
"ZeroLagMACD",
|
|
"ElderImpulse",
|
|
"STC",
|
|
"PPO",
|
|
"DPO",
|
|
"Coppock",
|
|
"AroonOscillator",
|
|
"Vortex",
|
|
"RWI",
|
|
"WaveTrend",
|
|
"MassIndex",
|
|
"AcceleratorOscillator",
|
|
"BalanceOfPower",
|
|
"ChoppinessIndex",
|
|
"VerticalHorizontalFilter",
|
|
# Volatility
|
|
"BollingerBands",
|
|
"ATR",
|
|
"Keltner",
|
|
"Donchian",
|
|
"PSAR",
|
|
"NATR",
|
|
"StdDev",
|
|
"UlcerIndex",
|
|
"HistoricalVolatility",
|
|
"BollingerBandwidth",
|
|
"PercentB",
|
|
"SuperTrend",
|
|
"ChandelierExit",
|
|
"ChandeKrollStop",
|
|
"AtrTrailingStop",
|
|
"HiLoActivator",
|
|
"VoltyStop",
|
|
"YoyoExit",
|
|
"DonchianStop",
|
|
"PercentageTrailingStop",
|
|
"StepTrailingStop",
|
|
"RenkoTrailingStop",
|
|
"TrueRange",
|
|
"ChaikinVolatility",
|
|
"RVIVolatility",
|
|
"ParkinsonVolatility",
|
|
"GarmanKlassVolatility",
|
|
"RogersSatchellVolatility",
|
|
"YangZhangVolatility",
|
|
# Volume
|
|
"OBV",
|
|
"VWAP",
|
|
"RollingVWAP",
|
|
"ADL",
|
|
"VolumePriceTrend",
|
|
"ChaikinMoneyFlow",
|
|
"ChaikinOscillator",
|
|
"ForceIndex",
|
|
"KVO",
|
|
"VolumeOscillator",
|
|
"NVI",
|
|
"PVI",
|
|
"WilliamsAD",
|
|
"AnchoredVWAP",
|
|
"DemandIndex",
|
|
"TSV",
|
|
"VZO",
|
|
"MarketFacilitationIndex",
|
|
"EaseOfMovement",
|
|
# Statistics
|
|
"TypicalPrice",
|
|
"MedianPrice",
|
|
"WeightedClose",
|
|
"LinearRegression",
|
|
"LinRegSlope",
|
|
"ZScore",
|
|
"LinRegAngle",
|
|
"Variance",
|
|
"CoefficientOfVariation",
|
|
"Skewness",
|
|
"Kurtosis",
|
|
"StandardError",
|
|
"DetrendedStdDev",
|
|
"RSquared",
|
|
"Autocorrelation",
|
|
"MedianAbsoluteDeviation",
|
|
"HurstExponent",
|
|
"PearsonCorrelation",
|
|
"Beta",
|
|
"PairwiseBeta",
|
|
"PairSpreadZScore",
|
|
"LeadLagCrossCorrelation",
|
|
"Cointegration",
|
|
"RelativeStrengthAB",
|
|
"SpearmanCorrelation",
|
|
# Ehlers / Cycle
|
|
"SuperSmoother",
|
|
"FisherTransform",
|
|
"InverseFisherTransform",
|
|
"Decycler",
|
|
"DecyclerOscillator",
|
|
"RoofingFilter",
|
|
"CenterOfGravity",
|
|
"CyberneticCycle",
|
|
"InstantaneousTrendline",
|
|
"EhlersStochastic",
|
|
"EmpiricalModeDecomposition",
|
|
"HilbertDominantCycle",
|
|
"AdaptiveCycle",
|
|
"SineWave",
|
|
"MAMA",
|
|
"FAMA",
|
|
# Bands & Channels
|
|
"MaEnvelope",
|
|
"AccelerationBands",
|
|
"StarcBands",
|
|
"AtrBands",
|
|
"HurstChannel",
|
|
"LinRegChannel",
|
|
"StandardErrorBands",
|
|
"DoubleBollinger",
|
|
"TtmSqueeze",
|
|
"FractalChaosBands",
|
|
"VwapStdDevBands",
|
|
# Pivots & S/R
|
|
"ClassicPivots",
|
|
"FibonacciPivots",
|
|
"Camarilla",
|
|
"WoodiePivots",
|
|
"DemarkPivots",
|
|
"WilliamsFractals",
|
|
"ZigZag",
|
|
# DeMark
|
|
"TDSetup",
|
|
"TDSequential",
|
|
"TDDeMarker",
|
|
"TDREI",
|
|
"TDPressure",
|
|
"TDCombo",
|
|
"TDCountdown",
|
|
"TDLines",
|
|
"TDRangeProjection",
|
|
"TDDifferential",
|
|
"TDOpen",
|
|
"TDRiskLevel",
|
|
# Ichimoku & alternative charts
|
|
"Ichimoku",
|
|
"HeikinAshi",
|
|
# Market Profile
|
|
"ValueArea",
|
|
"InitialBalance",
|
|
"OpeningRange",
|
|
# Candlestick patterns
|
|
"Doji",
|
|
"Hammer",
|
|
"InvertedHammer",
|
|
"HangingMan",
|
|
"ShootingStar",
|
|
"Engulfing",
|
|
"Harami",
|
|
"MorningEveningStar",
|
|
"ThreeSoldiersOrCrows",
|
|
"PiercingDarkCloud",
|
|
"Marubozu",
|
|
"Tweezer",
|
|
"SpinningTop",
|
|
"ThreeInside",
|
|
"ThreeOutside",
|
|
# Microstructure: order book
|
|
"OrderBookImbalanceTop1",
|
|
"OrderBookImbalanceTopN",
|
|
"OrderBookImbalanceFull",
|
|
"Microprice",
|
|
"QuotedSpread",
|
|
# Microstructure: trade flow
|
|
"SignedVolume",
|
|
"CumulativeVolumeDelta",
|
|
"TradeImbalance",
|
|
# Risk / Performance
|
|
"SharpeRatio",
|
|
"SortinoRatio",
|
|
"CalmarRatio",
|
|
"OmegaRatio",
|
|
"MaxDrawdown",
|
|
"AverageDrawdown",
|
|
"DrawdownDuration",
|
|
"PainIndex",
|
|
"ValueAtRisk",
|
|
"ConditionalValueAtRisk",
|
|
"ProfitFactor",
|
|
"GainLossRatio",
|
|
"RecoveryFactor",
|
|
"KellyCriterion",
|
|
"TreynorRatio",
|
|
"InformationRatio",
|
|
"Alpha",
|
|
]
|