Package: mintalib
Minimal Technical Analysis Library for PythonThis library offers a curated list of technical analysis indicators
implemented in cython.
It is built aroundnumpyarrays and aims to be compatible
with bothpandasandpolarsdataframes where possible.WarningThis is work in progress.
For a similar project with a mature api
you may want to look atta-lib.StructureThemintalibpackage contains three main modules:mintalib.corelow level calculation rountines implemented in cythonmintalib.functionssingle use functions to compute indicatorsmintalib.indicatorscomposable interface to indicatorsFunctionsIndicators are available as simple functions via thefunctionsmodule,
with names likeSMA,EMA,RSI,MACD, all inupper case.
The first parameter of a function is eitherpricesorseriesdepending on whether
the functions expects a dataframe of prices or a single series.
Functions that expect series data can still be applied to prices data, in which case they use
theclosecolumn by default or otherwize the column specified with theitemparameter.Apricesdataframe can be a pandas dataframe, a polars dataframe or a dictionary of numpy arrays.
The column names for prices are expected to includeopen,high,low,closeall inlower case.
Aseriescan be a pandas series, a polars series or any iterable compatible with numpy arrays.Functions attempt to wrap their result to match their input, so that for example
pandas based inputs will yield pandas based results with matching index.importyfinanceasyffrommintalib.functionsimportSMA,MAX# fetch prices (eg with yfinance)prices=yf.Ticker('AAPL').history('5y')# convert column names to lower caseprices=prices.rename(columns=str.lower).rename_axis(index=str.lower)# compute indicatorssma50=SMA(prices,50)# SMA of 'close' with period = 50sma200=SMA(prices,200)# SMA of 'close' with period = 200high200=MAX(prices,200,item='high')# MAX of 'high' with period = 200Composable InterfaceIndicators are also available through a composable interface via theindicatorsmodule,
with similar the same names all inuper case.
Each indicator is implemented as a class to be instanciated with calculation parameters.
The instance objects are callables that can be applied to series or prices data like regular functions.
So for exampleSMA(50)is a callable object that will return the 50 period simple moving average of its argument.Indicators can be composed with the@operator,
where for exampleEMA(20) @ ROC(5)meansEMA(20)applied toROC(5).
The same@operator can also be used to apply an indicator to some data,
where for exampleSMA(50) @ pricescan be used to compute the 50 period simple moving average onprices.Please note that with pandas dataframes you can compose and assign multiple indicators in one go
using the builtinassignmethod.importyfinanceasyffrommintalib.indicatorsimportEMA,SMA,ROC,RSI,SLOPE,EVAL# fetch prices (eg with yfinance)prices=yf.Ticker('AAPL').history('5y')# convert column names to lower caseprices=prices.rename(columns=str.lower).rename_axis(index=str.lower)# compute and append indicators to pricesresult=prices.assign(sma50=SMA(50),sma200=SMA(200),rsi=RSI(14),slope=SLOPE(20),trend=EMA(20)@ROC(5),pos=EVAL("sma50 > sma200"))# you will notice that the EVAL expression at the end# can use the names sma50 and sma200 that where defined# just above in the same function call!ExamplesYou can find example notebooks in the examples folder.InstallationYou can install the current version of this package with pippython -mpip install git+https://github.com/furechan/mintalib.gitRelated Projectsta-libPython wrapper for TA-LibqtalibQuantitative Technical Analysis LibrarynumpyThe fundamental package for scientific computing with PythonpandasFlexible and powerful data analysis / manipulation library for PythonpolarsFast multi-threaded, hybrid-out-of-core query engine focussing on DataFrame front-endsyfinanceDownload market data from Yahoo! Finance's APIList of IndicatorsNameDescriptionADXAverage Directional IndexATRAverage True RangeAVGPRICEAverage PriceBBANDSBollinger BandsBOPBalance of PowerCCICommodity Channel IndexCMFChaikin Money FlowCROSSOVERCross OverCROSSUNDERCross UnderCURVECurve (time curvilinear regression)DEMADouble Exponential Moving AverageDIFFDifferenceEFFICIENCY_RATIOEfficiency Ratio (Kaufman)EMAExponential Moving AverageEVALExpression Eval (pandas only)EXPExponentialFLAG_ABOVEFlag for value above levelFLAG_BELOWFlag for value below levelFORECASTForecast (time linear regression)INVERT_FLAGInvert flagKAMAKaufman Adaptive Moving Average (Kaufman)KELTNERKeltner ChannelLATRAverage True Range (logarithmic)LOGLogarithmMAGeneric Moving AverageMACDMoving Average Convergenge DivergenceMADMean Absolute DeviationMAXRolling MaximumMFIMoney Flow IndexMIDPRICEMid PriceMINRolling MinimumMINUSDIMinus Directional IndexNATRAverage True Range (normalized)PLUSDIPlus Directional IndexPPOPrice Percentage OscillatorPRICEGeneric PriceRMARolling Moving Average (RSI Style)ROCRate of ChangeRSIRelative Strength IndexRVALUERValue (time linear regression)SARParabolic Stop and ReverseSLOPESlope (time linear regression)SMASimple Moving AverageSTDEVStandard DeviationSTOCHStochastic OscillatorSTREAK_DOWNConsecutive streak of downsSTREAK_UPConsecutive streak of upsSUMRolling SumTEMATriple Exponential Moving AverageTRANGETrue RangeTYPPRICETypical PriceUPDOWN_FLAGFlag for value crossing levels up & downWCLPRICEWeighted Close PriceWMAWeighted Moving Average