392 lines
7.6 KiB
Python
392 lines
7.6 KiB
Python
"""
|
|
ferro_ta.raw — Zero-overhead access to the compiled Rust extension.
|
|
|
|
Importing from this module gives you direct access to the PyO3-compiled
|
|
indicator functions **without** the pandas/polars wrapping, Python validation,
|
|
or ``_to_f64`` conversion overhead applied by the standard public API.
|
|
|
|
When to use
|
|
-----------
|
|
Use ``ferro_ta.raw`` when:
|
|
|
|
- You have benchmarked and confirmed that wrapper overhead is your bottleneck.
|
|
- Your inputs are already 1-D C-contiguous ``float64`` NumPy arrays.
|
|
- You do not need ``pandas.Series`` or ``polars.Series`` output.
|
|
- You understand the trade-off: no nice error messages, no index preservation.
|
|
|
|
Stability
|
|
---------
|
|
The raw API is **not guaranteed to be stable** across minor versions.
|
|
Function signatures follow the compiled Rust extension directly and may
|
|
change when the Rust layer changes. For a stable API use the public
|
|
``ferro_ta.*`` functions.
|
|
|
|
Usage
|
|
-----
|
|
>>> import numpy as np
|
|
>>> from ferro_ta.core.raw import sma, ema, rsi
|
|
>>>
|
|
>>> close = np.random.rand(1000).astype(np.float64)
|
|
>>> result = sma(close, 20) # returns numpy.ndarray directly
|
|
>>> result2 = rsi(close, 14)
|
|
>>> result3 = ema(close, 20)
|
|
|
|
Batch (Rust loop, 2-D input):
|
|
>>> data = np.random.rand(252, 100).astype(np.float64)
|
|
>>> sma_out = batch_sma(data, 20) # shape (252, 100) — Rust inner loop
|
|
|
|
Available names
|
|
---------------
|
|
All functions registered by the ``_ferro_ta`` extension module are accessible
|
|
from this namespace. In addition to the canonical imports below, you can
|
|
use the ``_ferro_ta`` module directly::
|
|
|
|
from ferro_ta._ferro_ta import sma # identical to ferro_ta.raw.sma
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Re-export everything from the compiled extension.
|
|
# The ``noqa: F401`` silences "imported but unused" warnings — these are
|
|
# intentional re-exports.
|
|
# ---------------------------------------------------------------------------
|
|
from ferro_ta._ferro_ta import ( # noqa: F401
|
|
# Streaming classes (PyO3 classes)
|
|
StreamingATR,
|
|
StreamingBBands,
|
|
StreamingEMA,
|
|
StreamingMACD,
|
|
StreamingRSI,
|
|
StreamingSMA,
|
|
StreamingStoch,
|
|
StreamingSupertrend,
|
|
StreamingVWAP,
|
|
ad,
|
|
adosc,
|
|
adx,
|
|
adxr,
|
|
apo,
|
|
aroon,
|
|
aroonosc,
|
|
atr,
|
|
avgprice,
|
|
batch_ema,
|
|
batch_rsi,
|
|
batch_sma,
|
|
bbands,
|
|
beta,
|
|
bop,
|
|
cci,
|
|
cdl2crows,
|
|
cdl3blackcrows,
|
|
cdl3inside,
|
|
cdl3linestrike,
|
|
cdl3outside,
|
|
cdl3starsinsouth,
|
|
cdl3whitesoldiers,
|
|
cdlabandonedbaby,
|
|
cdladvanceblock,
|
|
cdlbelthold,
|
|
cdlbreakaway,
|
|
cdlclosingmarubozu,
|
|
cdlconcealbabyswall,
|
|
cdlcounterattack,
|
|
cdldarkcloudcover,
|
|
cdldoji,
|
|
cdldojistar,
|
|
cdldragonflydoji,
|
|
cdlengulfing,
|
|
cdleveningdojistar,
|
|
cdleveningstar,
|
|
cdlgapsidesidewhite,
|
|
cdlgravestonedoji,
|
|
cdlhammer,
|
|
cdlhangingman,
|
|
cdlharami,
|
|
cdlharamicross,
|
|
cdlhighwave,
|
|
cdlhikkake,
|
|
cdlhikkakemod,
|
|
cdlhomingpigeon,
|
|
cdlidentical3crows,
|
|
cdlinneck,
|
|
cdlinvertedhammer,
|
|
cdlkicking,
|
|
cdlkickingbylength,
|
|
cdlladderbottom,
|
|
cdllongleggeddoji,
|
|
cdllongline,
|
|
cdlmarubozu,
|
|
cdlmatchinglow,
|
|
cdlmathold,
|
|
cdlmorningdojistar,
|
|
cdlmorningstar,
|
|
cdlonneck,
|
|
cdlpiercing,
|
|
cdlrickshawman,
|
|
cdlrisefall3methods,
|
|
cdlseparatinglines,
|
|
cdlshootingstar,
|
|
cdlshortline,
|
|
cdlspinningtop,
|
|
cdlstalledpattern,
|
|
cdlsticksandwich,
|
|
cdltakuri,
|
|
cdltasukigap,
|
|
cdlthrusting,
|
|
cdltristar,
|
|
cdlunique3river,
|
|
cdlupsidegap2crows,
|
|
cdlxsidegap3methods,
|
|
# Extended indicators
|
|
chandelier_exit,
|
|
choppiness_index,
|
|
cmo,
|
|
correl,
|
|
dema,
|
|
donchian,
|
|
dx,
|
|
ema,
|
|
ht_dcperiod,
|
|
ht_dcphase,
|
|
ht_phasor,
|
|
ht_sine,
|
|
ht_trendline,
|
|
ht_trendmode,
|
|
hull_ma,
|
|
ichimoku,
|
|
kama,
|
|
keltner_channels,
|
|
linearreg,
|
|
linearreg_angle,
|
|
linearreg_intercept,
|
|
linearreg_slope,
|
|
ma,
|
|
macd,
|
|
macdext,
|
|
macdfix,
|
|
mama,
|
|
mavp,
|
|
medprice,
|
|
mfi,
|
|
midpoint,
|
|
midprice,
|
|
minus_di,
|
|
minus_dm,
|
|
mom,
|
|
natr,
|
|
obv,
|
|
pivot_points,
|
|
plus_di,
|
|
plus_dm,
|
|
ppo,
|
|
roc,
|
|
rocp,
|
|
rocr,
|
|
rocr100,
|
|
# Rolling math operators
|
|
rolling_max,
|
|
rolling_maxindex,
|
|
rolling_min,
|
|
rolling_minindex,
|
|
rolling_sum,
|
|
rsi,
|
|
sar,
|
|
sarext,
|
|
sma,
|
|
stddev,
|
|
stoch,
|
|
stochf,
|
|
stochrsi,
|
|
supertrend,
|
|
t3,
|
|
tema,
|
|
trange,
|
|
trima,
|
|
trix,
|
|
tsf,
|
|
typprice,
|
|
ultosc,
|
|
var,
|
|
vwap,
|
|
vwma,
|
|
wclprice,
|
|
willr,
|
|
wma,
|
|
)
|
|
|
|
__all__ = [
|
|
# Overlap
|
|
"sma",
|
|
"ema",
|
|
"wma",
|
|
"dema",
|
|
"tema",
|
|
"trima",
|
|
"kama",
|
|
"t3",
|
|
"bbands",
|
|
"macd",
|
|
"macdfix",
|
|
"macdext",
|
|
"sar",
|
|
"sarext",
|
|
"ma",
|
|
"mavp",
|
|
"mama",
|
|
"midpoint",
|
|
"midprice",
|
|
# Momentum
|
|
"rsi",
|
|
"mom",
|
|
"roc",
|
|
"rocp",
|
|
"rocr",
|
|
"rocr100",
|
|
"mfi",
|
|
"willr",
|
|
"adx",
|
|
"adxr",
|
|
"apo",
|
|
"ppo",
|
|
"cci",
|
|
"cmo",
|
|
"aroon",
|
|
"aroonosc",
|
|
"bop",
|
|
"stoch",
|
|
"stochf",
|
|
"stochrsi",
|
|
"ultosc",
|
|
"dx",
|
|
"plus_di",
|
|
"minus_di",
|
|
"plus_dm",
|
|
"minus_dm",
|
|
"trix",
|
|
# Volume
|
|
"ad",
|
|
"adosc",
|
|
"obv",
|
|
# Volatility
|
|
"atr",
|
|
"natr",
|
|
"trange",
|
|
# Statistics
|
|
"stddev",
|
|
"var",
|
|
"beta",
|
|
"correl",
|
|
"linearreg",
|
|
"linearreg_slope",
|
|
"linearreg_intercept",
|
|
"linearreg_angle",
|
|
"tsf",
|
|
# Price transforms
|
|
"avgprice",
|
|
"medprice",
|
|
"typprice",
|
|
"wclprice",
|
|
# Cycle
|
|
"ht_trendline",
|
|
"ht_dcperiod",
|
|
"ht_dcphase",
|
|
"ht_phasor",
|
|
"ht_sine",
|
|
"ht_trendmode",
|
|
# Pattern recognition (all 61 CDL functions)
|
|
"cdl2crows",
|
|
"cdl3blackcrows",
|
|
"cdl3inside",
|
|
"cdl3linestrike",
|
|
"cdl3outside",
|
|
"cdl3starsinsouth",
|
|
"cdl3whitesoldiers",
|
|
"cdlabandonedbaby",
|
|
"cdladvanceblock",
|
|
"cdlbelthold",
|
|
"cdlbreakaway",
|
|
"cdlclosingmarubozu",
|
|
"cdlconcealbabyswall",
|
|
"cdlcounterattack",
|
|
"cdldarkcloudcover",
|
|
"cdldoji",
|
|
"cdldojistar",
|
|
"cdldragonflydoji",
|
|
"cdlengulfing",
|
|
"cdleveningdojistar",
|
|
"cdleveningstar",
|
|
"cdlgapsidesidewhite",
|
|
"cdlgravestonedoji",
|
|
"cdlhammer",
|
|
"cdlhangingman",
|
|
"cdlharami",
|
|
"cdlharamicross",
|
|
"cdlhighwave",
|
|
"cdlhikkake",
|
|
"cdlhikkakemod",
|
|
"cdlhomingpigeon",
|
|
"cdlidentical3crows",
|
|
"cdlinneck",
|
|
"cdlinvertedhammer",
|
|
"cdlkicking",
|
|
"cdlkickingbylength",
|
|
"cdlladderbottom",
|
|
"cdllongleggeddoji",
|
|
"cdllongline",
|
|
"cdlmarubozu",
|
|
"cdlmatchinglow",
|
|
"cdlmathold",
|
|
"cdlmorningdojistar",
|
|
"cdlmorningstar",
|
|
"cdlonneck",
|
|
"cdlpiercing",
|
|
"cdlrickshawman",
|
|
"cdlrisefall3methods",
|
|
"cdlseparatinglines",
|
|
"cdlshootingstar",
|
|
"cdlshortline",
|
|
"cdlspinningtop",
|
|
"cdlstalledpattern",
|
|
"cdlsticksandwich",
|
|
"cdltakuri",
|
|
"cdltasukigap",
|
|
"cdlthrusting",
|
|
"cdltristar",
|
|
"cdlunique3river",
|
|
"cdlupsidegap2crows",
|
|
"cdlxsidegap3methods",
|
|
# Batch (Rust-side 2-D loops — single GIL release)
|
|
"batch_sma",
|
|
"batch_ema",
|
|
"batch_rsi",
|
|
# Extended indicators (Rust)
|
|
"vwap",
|
|
"vwma",
|
|
"supertrend",
|
|
"donchian",
|
|
"choppiness_index",
|
|
"keltner_channels",
|
|
"hull_ma",
|
|
"chandelier_exit",
|
|
"ichimoku",
|
|
"pivot_points",
|
|
# Rolling math operators (Rust)
|
|
"rolling_sum",
|
|
"rolling_max",
|
|
"rolling_min",
|
|
"rolling_maxindex",
|
|
"rolling_minindex",
|
|
# Streaming classes (Rust PyO3)
|
|
"StreamingSMA",
|
|
"StreamingEMA",
|
|
"StreamingRSI",
|
|
"StreamingATR",
|
|
"StreamingBBands",
|
|
"StreamingMACD",
|
|
"StreamingStoch",
|
|
"StreamingVWAP",
|
|
"StreamingSupertrend",
|
|
]
|