mintalib.core
moduleCalculation routines implemented in cython.
Routines are typically named calc_
followed by an indicator name all in lower caps as in calc_sma
.
The first parameter series
or prices
indicates whether the calculation accepts a single series or a prices dataframe.
A prices
dataframe should contain the columns open
, high
, low
, close
and optionally volume
all in lower case.
The wrap
parameter dictates whether to wrap the calculation result to match the type of the inputs.
check_size
functioncheck_size(*args)
check all series have the same size and return the size
column_accessor
functioncolumn_accessor(data)
column accessor if applicable
get_series
functionget_series(data, item: str = None, *, default_item: str = 'close')
get series from prices or series data
with_metadata
functionwith_metadata(*, same_scale: bool = None)
update function with metadata
wrap_function
functionwrap_function(source)
decorator to update function with documentation from source
wrap_indicator
functionwrap_indicator(source)
decorator to update indicator with documentation from source
wrap_result
functionwrap_result(result, source, name: str = None)
wrap result to match source data type
calc_price
functioncalc_price(prices, item: str = None, *, wrap: bool = False)
Generic Price
Args:
calc_avgprice
functioncalc_avgprice(prices, *, wrap: bool = False)
Average Price
Value of (open + high + low + close) / 4
calc_typprice
functioncalc_typprice(prices, *, wrap: bool = False)
Typical Price
Value of (high + low + close ) / 3
calc_wclprice
functioncalc_wclprice(prices, *, wrap: bool = False)
Weighted Close Price
Value of (high + low + 2 * close) / 4
calc_midprice
functioncalc_midprice(prices, *, wrap: bool = False)
Mid Price
Value of (high + low) / 2
calc_crossover
functioncalc_crossover(series, level: float = 0.0, *, wrap: bool = False)
Cross Over
Yields a value of 1 at the point where series crosses over level
Args:
calc_crossunder
functioncalc_crossunder(series, level: float = 0.0, *, wrap: bool = False)
Cross Under
Yields a value of 1 at the point where series crosses under level
Args:
calc_flag
functioncalc_flag(series, *, wrap: bool = False)
Flag Value
Flag value of 1 for positive, 0 for zero or negative, and NaN otherwize
calc_updown
functioncalc_updown(series, up_level: float = 0.0, down_level: float = 0.0, *, wrap: bool = False)
Flag for value crossing up & down levels
Args:
where_flag
functionwhere_flag(flag, x, y, z: float = nan, *, wrap: bool = False)
Value according to flag, selecting between x, y or z
calc_sign
functioncalc_sign(series, na_value: float = nan, *, wrap: bool = False)
Sign
calc_step
functioncalc_step(series, threshold: float = 1.0, *, wrap: bool = False)
Step Function
Limit value changes to threshold (in absolute value)
Args:
calc_clag
functioncalc_clag(series, period: int = 1, *, wrap: bool = False)
Confirmation Lag
Changes value only after a confirmation period
Args:
calc_abs
functioncalc_abs(series, *, wrap: bool = False)
Absolute Value
calc_log
functioncalc_log(series, *, wrap: bool = False)
Logarithm
calc_exp
functioncalc_exp(series, *, wrap: bool = False)
Exponential
calc_shift
functioncalc_shift(series, period: int, *, wrap: bool = False)
Shift Function
Args:
calc_diff
functioncalc_diff(series, period: int = 1, *, wrap: bool = False)
Difference
Difference between current value and the one offset by period
Args:
calc_lag
functioncalc_lag(series, period: int, *, wrap: bool = False)
Lag Function
Args:
calc_min
functioncalc_min(series, period: int, *, wrap: bool = False)
Rolling Minimum
Args:
calc_max
functioncalc_max(series, period: int, *, wrap: bool = False)
Rolling Maximum
calc_sum
functioncalc_sum(series, period: int, *, wrap: bool = False)
Rolling sum
Args:
calc_roc
functioncalc_roc(series, period: int = 1, *, wrap: bool = False)
Rate of Change
Args:
calc_lroc
functioncalc_lroc(series, period: int = 1, *, wrap: bool = False)
Logarithmic Rate of Change
Equivalent to the difference of log values
Args:
calc_mad
functioncalc_mad(series, period: int = 14, *, wrap: bool = False)
Rolling Mean Absolute Deviation
calc_stdev
functioncalc_stdev(series, period: int = 20, *, wrap: bool = False)
Standard Deviation
Args:
calc_mav
functioncalc_mav(series, period: int = 20, *, ma_type: str = 'SMA', wrap: bool = False)
Generic Moving Average
Moving average computed according to ma_type
Args:
calc_sma
functioncalc_sma(series, period: int, *, wrap: bool = False)
Simple Moving Average
Args:
calc_ema
functioncalc_ema(series, period: int, *, adjust: bool = False, wrap: bool = False)
Exponential Moving Average
Args:
Formula:
calc_rma
functioncalc_rma(series, period: int, *, wrap: bool = False)
Rolling Moving Average (RSI style)
Exponential moving average with alpha = 2 / period
,
that starts as a simple moving average until
number of bars is equal to period
.
calc_wma
functioncalc_wma(series, period: int, *, wrap: bool = False)
Weighted Moving Average
Args:
calc_hma
functioncalc_hma(series, period: int, *, wrap: bool = False)
Hull Moving Average
Args:
calc_dema
functioncalc_dema(series, period: int, *, wrap: bool = False)
Double Exponential Moving Average
Args:
calc_tema
functioncalc_tema(series, period: int = 20, *, wrap: bool = False)
Triple Exponential Moving Average
Args:
calc_alma
functioncalc_alma(series, period: int = 9, offset: float = 0.85, sigma: float = 6.0, *, wrap: bool = False)
Arnaud Legoux Moving Average
calc_rsi
functioncalc_rsi(series, period: int = 14, *, wrap: bool = False)
Relative Strength Index
Args:
calc_dmi
functioncalc_dmi(prices, period: int = 14, *, wrap: bool = False)
Directional Movement Indicator
Args:
calc_adx
functioncalc_adx(prices, period: int = 14, *, wrap: bool = False)
Average Directional Index
Args:
calc_pdi
functioncalc_pdi(prices, period: int = 14, *, wrap: bool = False)
Plus Directional Index
Args:
calc_mdi
functioncalc_mdi(prices, period: int = 14, *, wrap: bool = False)
Minus Directional Index
Args:
calc_trange
functioncalc_trange(prices, *, log_prices: bool = False, percent: bool = False, wrap: bool = False)
True Range
Args:
calc_atr
functioncalc_atr(prices, period: int = 14, *, wrap: bool = False)
Average True Range
Args:
calc_natr
functioncalc_natr(prices, period: int = 14, *, wrap: bool = False)
Average True Range (normalized)
Args:
calc_sar
functioncalc_sar(prices, afs: float = 0.02, maxaf: float = 0.2, *, wrap: bool = False)
Parabolic Stop and Reverse
Args:
calc_cci
functioncalc_cci(prices, period: int = 20, *, wrap: bool = False)
Commodity Channel Index
Args:
calc_cmf
functioncalc_cmf(prices, period: int = 20, *, wrap: bool = False)
Chaikin Money Flow
Args:
calc_mfi
functioncalc_mfi(prices, period: int = 14, *, wrap: bool = False)
Money Flow Index
Args:
calc_bop
functioncalc_bop(prices, period: int = 20, *, wrap: bool = False)
Balance of Power
Args:
calc_bbands
functioncalc_bbands(prices, period: int = 20, nbdev: float = 2.0, *, wrap: bool = False)
Bollinger Bands
Args:
calc_keltner
functioncalc_keltner(prices, period: int = 20, nbatr: float = 2.0, *, wrap: bool = False)
Keltner Channel
Args:
calc_ker
functioncalc_ker(series, period: int = 10, *, wrap: bool = False)
Kaufman Efficiency Ratio
Args:
calc_kama
functioncalc_kama(series, period: int = 10, fastn: int = 2, slown: int = 30, *, wrap: bool = False)
Kaufman Adaptive Moving Average
Args:
calc_macd
functioncalc_macd(series, n1: int = 12, n2: int = 26, n3: int = 9, *, wrap: bool = False)
Moving Average Convergenge Divergence
Args:
Outputs:
calc_ppo
functioncalc_ppo(series, n1: int = 12, n2: int = 26, n3: int = 9, *, wrap: bool = False)
Price Percentage Oscillator
Args:
Outputs:
linear_regression
functionlinear_regression(series, period: int = 20, *, option: int = 0, offset: int = 0, wrap: bool = False)
Linear Regression
Args:
calc_slope
functioncalc_slope(series, period: int = 20, *, wrap: bool = False)
Slope (linear regression)
Args:
calc_rvalue
functioncalc_rvalue(series, period: int = 20, *, wrap: bool = False)
R-Value (linear regression)
Args:
calc_tsf
functioncalc_tsf(series, period: int = 20, offset: int = 0, *, wrap: bool = False)
Time Series Forecast (linear regression)
Args:
quadratic_regression
functionquadratic_regression(series, period: int = 20, *, option: int = 0, offset: int = 0, wrap: bool = False)
Curve (quadratic regression)
calc_curve
functioncalc_curve(series, period: int = 20, *, wrap: bool = False)
Curve (quadratic regression)
calc_qsf
functioncalc_qsf(series, period: int = 20, offset: int = 0, *, wrap: bool = False)
Quadratic Series Forecast (quadratic regression)
Args:
calc_stoch
functioncalc_stoch(prices, period: int = 14, fastn: int = 3, slown: int = 3, *, wrap: bool = False)
Stochastic Oscillator
Args:
calc_streak
functioncalc_streak(series, *, wrap: bool = False)
Consecutive streak of ups or downs
Length of streak of values all up or down, times +1 or -1 whether ups or downs.
calc_eval
functioncalc_eval(prices, expr: str, *, as_flag: bool = False, wrap: bool = False)
Expression Eval (pandas only)
Args: