mintalib

mintalib.core module

Calculation 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 function

check_size(*args)

check all series have the same size and return the size

column_accessor function

column_accessor(data)

column accessor if applicable

get_series function

get_series(data, item: str = None, *, default_item: str = 'close')

get series from prices or series data

with_metadata function

with_metadata(*, same_scale: bool = None)

update function with metadata

wrap_function function

wrap_function(source)

decorator to update function with documentation from source

wrap_indicator function

wrap_indicator(source)

decorator to update indicator with documentation from source

wrap_result function

wrap_result(result, source, name: str = None)

wrap result to match source data type

calc_price function

calc_price(prices, item: str = None, *, wrap: bool = False)

Generic Price

Args:

calc_avgprice function

calc_avgprice(prices, *, wrap: bool = False)

Average Price

Value of (open + high + low + close) / 4

calc_typprice function

calc_typprice(prices, *, wrap: bool = False)

Typical Price

Value of (high + low + close ) / 3

calc_wclprice function

calc_wclprice(prices, *, wrap: bool = False)

Weighted Close Price

Value of (high + low + 2 * close) / 4

calc_midprice function

calc_midprice(prices, *, wrap: bool = False)

Mid Price

Value of (high + low) / 2

calc_crossover function

calc_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 function

calc_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 function

calc_flag(series, *, wrap: bool = False)

Flag Value

Flag value of 1 for positive, 0 for zero or negative, and NaN otherwize

calc_updown function

calc_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 function

where_flag(flag, x, y, z: float = nan, *, wrap: bool = False)

Value according to flag, selecting between x, y or z

calc_sign function

calc_sign(series, na_value: float = nan, *, wrap: bool = False)

Sign

calc_step function

calc_step(series, threshold: float = 1.0, *, wrap: bool = False)

Step Function

Limit value changes to threshold (in absolute value)

Args:

calc_clag function

calc_clag(series, period: int = 1, *, wrap: bool = False)

Confirmation Lag

Changes value only after a confirmation period

Args:

calc_abs function

calc_abs(series, *, wrap: bool = False)

Absolute Value

calc_log function

calc_log(series, *, wrap: bool = False)

Logarithm

calc_exp function

calc_exp(series, *, wrap: bool = False)

Exponential

calc_shift function

calc_shift(series, period: int, *, wrap: bool = False)

Shift Function

Args:

calc_diff function

calc_diff(series, period: int = 1, *, wrap: bool = False)

Difference

Difference between current value and the one offset by period

Args:

calc_lag function

calc_lag(series, period: int, *, wrap: bool = False)

Lag Function

Args:

calc_min function

calc_min(series, period: int, *, wrap: bool = False)

Rolling Minimum

Args:

calc_max function

calc_max(series, period: int, *, wrap: bool = False)

Rolling Maximum

calc_sum function

calc_sum(series, period: int, *, wrap: bool = False)

Rolling sum

Args:

calc_roc function

calc_roc(series, period: int = 1, *, wrap: bool = False)

Rate of Change

Args:

calc_lroc function

calc_lroc(series, period: int = 1, *, wrap: bool = False)

Logarithmic Rate of Change

Equivalent to the difference of log values

Args:

calc_mad function

calc_mad(series, period: int = 14, *, wrap: bool = False)

Rolling Mean Absolute Deviation

calc_stdev function

calc_stdev(series, period: int = 20, *, wrap: bool = False)

Standard Deviation

Args:

calc_mav function

calc_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 function

calc_sma(series, period: int, *, wrap: bool = False)

Simple Moving Average

Args:

calc_ema function

calc_ema(series, period: int, *, adjust: bool = False, wrap: bool = False)

Exponential Moving Average

Args:

Formula:

calc_rma function

calc_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 function

calc_wma(series, period: int, *, wrap: bool = False)

Weighted Moving Average

Args:

calc_hma function

calc_hma(series, period: int, *, wrap: bool = False)

Hull Moving Average

Args:

calc_dema function

calc_dema(series, period: int, *, wrap: bool = False)

Double Exponential Moving Average

Args:

calc_tema function

calc_tema(series, period: int = 20, *, wrap: bool = False)

Triple Exponential Moving Average

Args:

calc_alma function

calc_alma(series, period: int = 9, offset: float = 0.85, sigma: float = 6.0, *, wrap: bool = False)

Arnaud Legoux Moving Average

calc_rsi function

calc_rsi(series, period: int = 14, *, wrap: bool = False)

Relative Strength Index

Args:

calc_dmi function

calc_dmi(prices, period: int = 14, *, wrap: bool = False)

Directional Movement Indicator

Args:

calc_adx function

calc_adx(prices, period: int = 14, *, wrap: bool = False)

Average Directional Index

Args:

calc_pdi function

calc_pdi(prices, period: int = 14, *, wrap: bool = False)

Plus Directional Index

Args:

calc_mdi function

calc_mdi(prices, period: int = 14, *, wrap: bool = False)

Minus Directional Index

Args:

calc_trange function

calc_trange(prices, *, log_prices: bool = False, percent: bool = False, wrap: bool = False)

True Range

Args:

calc_atr function

calc_atr(prices, period: int = 14, *, wrap: bool = False)

Average True Range

Args:

calc_natr function

calc_natr(prices, period: int = 14, *, wrap: bool = False)

Average True Range (normalized)

Args:

calc_sar function

calc_sar(prices, afs: float = 0.02, maxaf: float = 0.2, *, wrap: bool = False)

Parabolic Stop and Reverse

Args:

calc_cci function

calc_cci(prices, period: int = 20, *, wrap: bool = False)

Commodity Channel Index

Args:

calc_cmf function

calc_cmf(prices, period: int = 20, *, wrap: bool = False)

Chaikin Money Flow

Args:

calc_mfi function

calc_mfi(prices, period: int = 14, *, wrap: bool = False)

Money Flow Index

Args:

calc_bop function

calc_bop(prices, period: int = 20, *, wrap: bool = False)

Balance of Power

Args:

calc_bbands function

calc_bbands(prices, period: int = 20, nbdev: float = 2.0, *, wrap: bool = False)

Bollinger Bands

Args:

calc_keltner function

calc_keltner(prices, period: int = 20, nbatr: float = 2.0, *, wrap: bool = False)

Keltner Channel

Args:

calc_ker function

calc_ker(series, period: int = 10, *, wrap: bool = False)

Kaufman Efficiency Ratio

Args:

calc_kama function

calc_kama(series, period: int = 10, fastn: int = 2, slown: int = 30, *, wrap: bool = False)

Kaufman Adaptive Moving Average

Args:

calc_macd function

calc_macd(series, n1: int = 12, n2: int = 26, n3: int = 9, *, wrap: bool = False)

Moving Average Convergenge Divergence

Args:

Outputs:

calc_ppo function

calc_ppo(series, n1: int = 12, n2: int = 26, n3: int = 9, *, wrap: bool = False)

Price Percentage Oscillator

Args:

Outputs:

linear_regression function

linear_regression(series, period: int = 20, *, option: int = 0, offset: int = 0, wrap: bool = False)

Linear Regression

Args:

calc_slope function

calc_slope(series, period: int = 20, *, wrap: bool = False)

Slope (linear regression)

Args:

calc_rvalue function

calc_rvalue(series, period: int = 20, *, wrap: bool = False)

R-Value (linear regression)

Args:

calc_tsf function

calc_tsf(series, period: int = 20, offset: int = 0, *, wrap: bool = False)

Time Series Forecast (linear regression)

Args:

quadratic_regression function

quadratic_regression(series, period: int = 20, *, option: int = 0, offset: int = 0, wrap: bool = False)

Curve (quadratic regression)

calc_curve function

calc_curve(series, period: int = 20, *, wrap: bool = False)

Curve (quadratic regression)

calc_qsf function

calc_qsf(series, period: int = 20, offset: int = 0, *, wrap: bool = False)

Quadratic Series Forecast (quadratic regression)

Args:

calc_stoch function

calc_stoch(prices, period: int = 14, fastn: int = 3, slown: int = 3, *, wrap: bool = False)

Stochastic Oscillator

Args:

calc_streak function

calc_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 function

calc_eval(prices, expr: str, *, as_flag: bool = False, wrap: bool = False)

Expression Eval (pandas only)

Args: