mintalib


Namemintalib JSON
Version 0.0.8 PyPI version JSON
download
home_pageNone
SummaryMinimal Technical Analysis Library for Python
upload_time2024-04-26 01:16:31
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT License
keywords python cython finance technical-analysis
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Minimal Technical Analysis Library for Python


This library offers a curated list of technical analysis indicators
implemented in cython.
It is built around `numpy` arrays and aims to be compatible
with both `pandas` and `polars` dataframes where possible.


> **Warning**
> This project is experimental and the interface can change.
> For a similar project with a mature api you may want to look at
> [ta-lib](https://pypi.org/project/TA-Lib/).


## Structure
The `mintalib` package contains three main modules:
- `mintalib.core` low level calculation rountines implemented in cython
- `mintalib.functions` single use functions to compute indicators
- `mintalib.indicators` composable interface to indicators

## Functions

Indicators are available as simple functions via the `functions` module,
with names like `SMA`, `EMA`, `RSI`, `MACD`, all in **upper case**.
The first parameter of a function is either `prices` or `series` depending 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 
the `close` column by default or otherwize the column specified with the `item` parameter.

A `prices` dataframe can be a pandas dataframe, a polars dataframe or a dictionary of numpy arrays.
The column names for prices are expected to include `open`, `high`, `low`, `close` all in **lower case**.
A `series` can 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.


```python
import yfinance as yf

from mintalib.functions import SMA, MAX

# fetch prices (eg with yfinance)
prices = yf.Ticker('AAPL').history('5y')

# convert column names to lower case
prices = prices.rename(columns=str.lower).rename_axis(index=str.lower)

# compute indicators
sma50 = SMA(prices, 50)  # SMA of 'close' with period = 50
sma200 = SMA(prices, 200)  # SMA of 'close' with period = 200
high200 = MAX(prices, 200, item='high')  # MAX of 'high' with period = 200

```


## Composable Interface

Indicators are also available through a composable interface via the `indicators` module,
with similar the same names all in **uper 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 example `SMA(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 example `EMA(20) @ ROC(5)` means `EMA(20)` applied to `ROC(5)`.
The same `@` operator can also be used to apply an indicator to some data,
where for example `SMA(50) @ prices` can be used to compute the 50 period simple moving average on `prices`. 

Please note that with pandas dataframes you can compose and assign multiple indicators in one go
using the builtin `assign` method.

```python
import yfinance as yf

from mintalib.indicators import EMA, SMA, ROC, RSI, SLOPE, EVAL

# fetch prices (eg with yfinance)
prices = yf.Ticker('AAPL').history('5y')

# convert column names to lower case
prices = prices.rename(columns=str.lower).rename_axis(index=str.lower)

# compute and append indicators to prices
result = 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!
```


## Examples

You can find example notebooks in the examples folder. 


## Installation

You can install the current version of this package with pip
```console
python -mpip install git+https://github.com/furechan/mintalib.git
```

## Related Projects
- [ta-lib](https://github.com/mrjbq7/ta-lib) Python wrapper for TA-Lib
- [qtalib](https://github.com/josephchenhk/qtalib) Quantitative Technical Analysis Library
- [numpy](https://github.com/numpy/numpy) The fundamental package for scientific computing with Python
- [pandas](https://github.com/pandas-dev/pandas) Flexible and powerful data analysis / manipulation library for Python
- [polars](https://github.com/pola-rs/polars) Fast multi-threaded, hybrid-out-of-core query engine focussing on DataFrame front-ends
- [yfinance](https://github.com/ranaroussi/yfinance) Download market data from Yahoo! Finance's API

## List of Indicators

| Name             | Description                               |
|:-----------------|:------------------------------------------|
| ADX              | Average Directional Index                 |
| ATR              | Average True Range                        |
| AVGPRICE         | Average Price                             |
| BBANDS           | Bollinger Bands                           |
| BOP              | Balance of Power                          |
| CCI              | Commodity Channel Index                   |
| CMF              | Chaikin Money Flow                        |
| CROSSOVER        | Cross Over                                |
| CROSSUNDER       | Cross Under                               |
| DEMA             | Double Exponential Moving Average         |
| DIFF             | Difference                                |
| EFFICIENCY_RATIO | Efficiency Ratio (Kaufman)                |
| EMA              | Exponential Moving Average                |
| EVAL             | Expression Eval (pandas only)             |
| EXP              | Exponential                               |
| FLAG_ABOVE       | Flag for value above level                |
| FLAG_BELOW       | Flag for value below level                |
| FORECAST         | Forecast (time linear regression)         |
| INVERT_FLAG      | Invert flag                               |
| KAMA             | Kaufman Adaptive Moving Average (Kaufman) |
| KELTNER          | Keltner Channel                           |
| LATR             | Average True Range (logarithmic)          |
| LOG              | Logarithm                                 |
| MA               | Generic Moving Average                    |
| MACD             | Moving Average Convergenge Divergence     |
| MAD              | Mean Absolute Deviation                   |
| MAX              | Rolling Maximum                           |
| MFI              | Money Flow Index                          |
| MIDPRICE         | Mid Price                                 |
| MIN              | Rolling Minimum                           |
| MINUSDI          | Minus Directional Index                   |
| NATR             | Average True Range (normalized)           |
| PLUSDI           | Plus Directional Index                    |
| PPO              | Price Percentage Oscillator               |
| PRICE            | Generic Price                             |
| RMA              | Rolling Moving Average (RSI Style)        |
| ROC              | Rate of Change                            |
| RSI              | Relative Strength Index                   |
| RVALUE           | RValue (time linear regression)           |
| SAR              | Parabolic Stop and Reverse                |
| SLOPE            | Slope (time linear regression)            |
| SMA              | Simple Moving Average                     |
| STDEV            | Standard Deviation                        |
| STOCH            | Stochastic Oscillator                     |
| STREAK_DOWN      | Consecutive streak of downs               |
| STREAK_UP        | Consecutive streak of ups                 |
| SUM              | Rolling Sum                               |
| TEMA             | Triple Exponential Moving Average         |
| TRANGE           | True Range                                |
| TYPPRICE         | Typical Price                             |
| UPDOWN_FLAG      | Flag for value crossing levels up & down  |
| WCLPRICE         | Weighted Close Price                      |
| WMA              | Weighted Moving Average                   |



            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "mintalib",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "python, cython, finance, technical-analysis",
    "author": null,
    "author_email": "Furechan <furechan@xsmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/be/a9/333b94eb9eb9a579b444b1f81ec9efccaca23f21d57ff0b019cc175f1f7e/mintalib-0.0.8.tar.gz",
    "platform": null,
    "description": "# Minimal Technical Analysis Library for Python\n\n\nThis library offers a curated list of technical analysis indicators\nimplemented in cython.\nIt is built around `numpy` arrays and aims to be compatible\nwith both `pandas` and `polars` dataframes where possible.\n\n\n> **Warning**\n> This project is experimental and the interface can change.\n> For a similar project with a mature api you may want to look at\n> [ta-lib](https://pypi.org/project/TA-Lib/).\n\n\n## Structure\nThe `mintalib` package contains three main modules:\n- `mintalib.core` low level calculation rountines implemented in cython\n- `mintalib.functions` single use functions to compute indicators\n- `mintalib.indicators` composable interface to indicators\n\n## Functions\n\nIndicators are available as simple functions via the `functions` module,\nwith names like `SMA`, `EMA`, `RSI`, `MACD`, all in **upper case**.\nThe first parameter of a function is either `prices` or `series` depending on whether\nthe functions expects a dataframe of prices or a single series.\nFunctions that expect series data can still be applied to prices data, in which case they use \nthe `close` column by default or otherwize the column specified with the `item` parameter.\n\nA `prices` dataframe can be a pandas dataframe, a polars dataframe or a dictionary of numpy arrays.\nThe column names for prices are expected to include `open`, `high`, `low`, `close` all in **lower case**.\nA `series` can be a pandas series, a polars series or any iterable compatible with numpy arrays.\n\nFunctions attempt to wrap their result to match their input, so that for example \npandas based inputs will yield pandas based results with matching index.\n\n\n```python\nimport yfinance as yf\n\nfrom mintalib.functions import SMA, MAX\n\n# fetch prices (eg with yfinance)\nprices = yf.Ticker('AAPL').history('5y')\n\n# convert column names to lower case\nprices = prices.rename(columns=str.lower).rename_axis(index=str.lower)\n\n# compute indicators\nsma50 = SMA(prices, 50)  # SMA of 'close' with period = 50\nsma200 = SMA(prices, 200)  # SMA of 'close' with period = 200\nhigh200 = MAX(prices, 200, item='high')  # MAX of 'high' with period = 200\n\n```\n\n\n## Composable Interface\n\nIndicators are also available through a composable interface via the `indicators` module,\nwith similar the same names all in **uper case**.\nEach indicator is implemented as a class to be instanciated with calculation parameters.\nThe instance objects are callables that can be applied to series or prices data like regular functions. \nSo for example `SMA(50)` is a callable object that will return the 50 period simple moving average of its argument.\n\nIndicators can be composed with the `@` operator,\nwhere for example `EMA(20) @ ROC(5)` means `EMA(20)` applied to `ROC(5)`.\nThe same `@` operator can also be used to apply an indicator to some data,\nwhere for example `SMA(50) @ prices` can be used to compute the 50 period simple moving average on `prices`. \n\nPlease note that with pandas dataframes you can compose and assign multiple indicators in one go\nusing the builtin `assign` method.\n\n```python\nimport yfinance as yf\n\nfrom mintalib.indicators import EMA, SMA, ROC, RSI, SLOPE, EVAL\n\n# fetch prices (eg with yfinance)\nprices = yf.Ticker('AAPL').history('5y')\n\n# convert column names to lower case\nprices = prices.rename(columns=str.lower).rename_axis(index=str.lower)\n\n# compute and append indicators to prices\nresult = prices.assign(\n    sma50 = SMA(50),\n    sma200 = SMA(200),\n    rsi = RSI(14),\n    slope = SLOPE(20),\n    trend = EMA(20) @ ROC(5),\n    pos = EVAL(\"sma50 > sma200\")\n)\n\n# you will notice that the EVAL expression at the end\n# can use the names sma50 and sma200 that where defined\n# just above in the same function call!\n```\n\n\n## Examples\n\nYou can find example notebooks in the examples folder. \n\n\n## Installation\n\nYou can install the current version of this package with pip\n```console\npython -mpip install git+https://github.com/furechan/mintalib.git\n```\n\n## Related Projects\n- [ta-lib](https://github.com/mrjbq7/ta-lib) Python wrapper for TA-Lib\n- [qtalib](https://github.com/josephchenhk/qtalib) Quantitative Technical Analysis Library\n- [numpy](https://github.com/numpy/numpy) The fundamental package for scientific computing with Python\n- [pandas](https://github.com/pandas-dev/pandas) Flexible and powerful data analysis / manipulation library for Python\n- [polars](https://github.com/pola-rs/polars) Fast multi-threaded, hybrid-out-of-core query engine focussing on DataFrame front-ends\n- [yfinance](https://github.com/ranaroussi/yfinance) Download market data from Yahoo! Finance's API\n\n## List of Indicators\n\n| Name             | Description                               |\n|:-----------------|:------------------------------------------|\n| ADX              | Average Directional Index                 |\n| ATR              | Average True Range                        |\n| AVGPRICE         | Average Price                             |\n| BBANDS           | Bollinger Bands                           |\n| BOP              | Balance of Power                          |\n| CCI              | Commodity Channel Index                   |\n| CMF              | Chaikin Money Flow                        |\n| CROSSOVER        | Cross Over                                |\n| CROSSUNDER       | Cross Under                               |\n| DEMA             | Double Exponential Moving Average         |\n| DIFF             | Difference                                |\n| EFFICIENCY_RATIO | Efficiency Ratio (Kaufman)                |\n| EMA              | Exponential Moving Average                |\n| EVAL             | Expression Eval (pandas only)             |\n| EXP              | Exponential                               |\n| FLAG_ABOVE       | Flag for value above level                |\n| FLAG_BELOW       | Flag for value below level                |\n| FORECAST         | Forecast (time linear regression)         |\n| INVERT_FLAG      | Invert flag                               |\n| KAMA             | Kaufman Adaptive Moving Average (Kaufman) |\n| KELTNER          | Keltner Channel                           |\n| LATR             | Average True Range (logarithmic)          |\n| LOG              | Logarithm                                 |\n| MA               | Generic Moving Average                    |\n| MACD             | Moving Average Convergenge Divergence     |\n| MAD              | Mean Absolute Deviation                   |\n| MAX              | Rolling Maximum                           |\n| MFI              | Money Flow Index                          |\n| MIDPRICE         | Mid Price                                 |\n| MIN              | Rolling Minimum                           |\n| MINUSDI          | Minus Directional Index                   |\n| NATR             | Average True Range (normalized)           |\n| PLUSDI           | Plus Directional Index                    |\n| PPO              | Price Percentage Oscillator               |\n| PRICE            | Generic Price                             |\n| RMA              | Rolling Moving Average (RSI Style)        |\n| ROC              | Rate of Change                            |\n| RSI              | Relative Strength Index                   |\n| RVALUE           | RValue (time linear regression)           |\n| SAR              | Parabolic Stop and Reverse                |\n| SLOPE            | Slope (time linear regression)            |\n| SMA              | Simple Moving Average                     |\n| STDEV            | Standard Deviation                        |\n| STOCH            | Stochastic Oscillator                     |\n| STREAK_DOWN      | Consecutive streak of downs               |\n| STREAK_UP        | Consecutive streak of ups                 |\n| SUM              | Rolling Sum                               |\n| TEMA             | Triple Exponential Moving Average         |\n| TRANGE           | True Range                                |\n| TYPPRICE         | Typical Price                             |\n| UPDOWN_FLAG      | Flag for value crossing levels up & down  |\n| WCLPRICE         | Weighted Close Price                      |\n| WMA              | Weighted Moving Average                   |\n\n\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Minimal Technical Analysis Library for Python",
    "version": "0.0.8",
    "project_urls": {
        "homepage": "https://github.com/furechan/mintalib"
    },
    "split_keywords": [
        "python",
        " cython",
        " finance",
        " technical-analysis"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bea9333b94eb9eb9a579b444b1f81ec9efccaca23f21d57ff0b019cc175f1f7e",
                "md5": "e13e3f7888d81a98376ae4a83641d80d",
                "sha256": "59cbaf42ba04c464e10866c3da094db001a5d1af77c002bdc4048a6c0d224d76"
            },
            "downloads": -1,
            "filename": "mintalib-0.0.8.tar.gz",
            "has_sig": false,
            "md5_digest": "e13e3f7888d81a98376ae4a83641d80d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 411292,
            "upload_time": "2024-04-26T01:16:31",
            "upload_time_iso_8601": "2024-04-26T01:16:31.789675Z",
            "url": "https://files.pythonhosted.org/packages/be/a9/333b94eb9eb9a579b444b1f81ec9efccaca23f21d57ff0b019cc175f1f7e/mintalib-0.0.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-26 01:16:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "furechan",
    "github_project": "mintalib",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "mintalib"
}
        
Elapsed time: 0.24594s