mplchart


Namemplchart JSON
Version 0.0.8 PyPI version JSON
download
home_page
SummaryClassic Stock Charts in Python
upload_time2024-03-15 22:03:24
maintainer
docs_urlNone
author
requires_python>=3.9
licenseMIT License
keywords candlesticks charting finance matplotlib
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Classic Stock Charts in Python


Create classic technical analysis stock charts in Python with minimal code.
The library is built around [matplotlib](https://github.com/matplotlib/matplotlib)
and [pandas](https://github.com/pandas-dev/pandas). 
Charts can be defined using a declarative interface,
based on a set of drawing primitives like `Candleststicks`, `Volume`
and technical indicators like `SMA`, `EMA`, `RSI`, `ROC`, `MACD`, etc ...


> **Warning**
> This project is work in progress and the api is bound to change.
> For a library with a mature api you may want to look into
> [mplfinance](https://pypi.org/project/mplfinance/).


![Showcase Chart](https://github.com/furechan/mplchart/raw/main/output/showcase.svg "Showcase")


## Typical Usage

```python
import yfinance as yf

from mplchart.chart import Chart
from mplchart.primitives import Candlesticks, Volume
from mplchart.indicators import ROC, SMA, EMA, RSI, MACD

ticker = 'AAPL'
prices = yf.Ticker(ticker).history('5y')

max_bars = 250

indicators = [
    Candlesticks(), SMA(50), SMA(200), Volume(),
    RSI(),
    MACD(),
]

chart = Chart(title=ticker, max_bars=max_bars)
chart.plot(prices, indicators)
```


## Conventions

Price data is expected to be presented as a pandas DataFrame
with columns `open`, `high`, `low`, `close` `volume`
and a timestamp index named `date`.
Please note, the library will automatically convert column
and index names to lower case for its internal use.


## Drawing Primitives

The library contains drawing primitives that can be used as an indicator in the plot api.
All primitives are classes that must be instantiated before being used in the plot api.

```python
from mplchart.chart import Chart
from mplchart.primitives import Candlesticks

indicators = [Candlesticks()]
chart = Chart(title=title, max_bars=max_bars)
chart.plot(prices, indicators)
```

The main drawing primitives are :
- `Candlesticks` for candlesticks plots
- `OHLC` for open, high, low, close bar plots
- `Price` for price line plots
- `Volume` for volume bar plots
- `Peaks` to plot peaks and valleys
- `SameAxes` to force plot on the same axes
- `NewAxes` to force plot on a new axes


## Builtin Indicators

The libary contains some basic technical analysis indicators implemented in pandas/numpy.
Indicators are classes that must be instantiated before being used in the plot api.

Some of the indicators included are:

- `SMA` Simple Moving Average
- `EMA` Exponential Moving Average
- `ROC` Rate of Change
- `RSI` Relative Strength Index
- `MACD` Moving Average Convergence Divergence
- `PPO` Price Percentage Oscillator 
- `SLOPE` Slope (linear regression with time)
- `BBANDS` Bolling Bands


## Ta-lib Abstract Functions

If you have [ta-lib](https://github.com/mrjbq7/ta-lib) installed you can use its abstract functions as indicators.
The indicators are created by calling `abstract.Function` with the name of the indicator and its parameters.

```python
from mplchart.primitives import Candlesticks
from talib.abstract import Function

indicators = [
    Candlesticks(),
    Function('SMA', 50),
    Function('SMA', 200),
    Function('RSI'),
    Function('MACD'),
]
```


## Custom Indicators

Any callable that takes a prices data frame and returns a series as result can be used as indicator.
A function can be used as an indicator but you can also implement an indicator as a callable dataclass.

```python
from dataclasses import dataclass

from mplchart.library import get_series, calc_ema

@dataclass
class DEMA:
    """ Double Exponential Moving Average """
    period: int = 20

    same_scale = True
    # same_scale is an optional class attribute that indicates
    # the indicator should be plot on the same axes by default

    def __call__(self, prices):
        series = get_series(prices)
        ema1 = calc_ema(series, self.period)
        ema2 = calc_ema(ema1, self.period)
        return 2 * ema1 - ema2

```

## Examples

You can find example notebooks and scripts 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/mplchart.git
```

## Requirements:

- python >= 3.8
- matplotlib
- pandas
- numpy
- yfinance


## Related Projects & Resources
- [stockcharts.com](https://stockcharts.com/) Classic stock charts and technical analysis reference
- [mplfinance](https://pypi.org/project/mplfinance/) Matplotlib utilities for the visualization,
and visual analysis, of financial data
- [matplotlib](https://github.com/matplotlib/matplotlib) Matplotlib: plotting with Python
- [yfinance](https://github.com/ranaroussi/yfinance) Download market data from Yahoo! Finance's API
- [ta-lib](https://github.com/mrjbq7/ta-lib) Python wrapper for TA-Lib
- [pandas](https://github.com/pandas-dev/pandas) Flexible and powerful data analysis / manipulation library
for Python, providing labeled data structures similar to R data.frame objects,
statistical functions, and much more
- [numpy](https://github.com/numpy/numpy) The fundamental package for scientific computing with Python

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "mplchart",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "candlesticks,charting,finance,matplotlib",
    "author": "",
    "author_email": "Furechan <furechan@xsmail.com>",
    "download_url": "",
    "platform": null,
    "description": "# Classic Stock Charts in Python\n\n\nCreate classic technical analysis stock charts in Python with minimal code.\nThe library is built around [matplotlib](https://github.com/matplotlib/matplotlib)\nand [pandas](https://github.com/pandas-dev/pandas). \nCharts can be defined using a declarative interface,\nbased on a set of drawing primitives like `Candleststicks`, `Volume`\nand technical indicators like `SMA`, `EMA`, `RSI`, `ROC`, `MACD`, etc ...\n\n\n> **Warning**\n> This project is work in progress and the api is bound to change.\n> For a library with a mature api you may want to look into\n> [mplfinance](https://pypi.org/project/mplfinance/).\n\n\n![Showcase Chart](https://github.com/furechan/mplchart/raw/main/output/showcase.svg \"Showcase\")\n\n\n## Typical Usage\n\n```python\nimport yfinance as yf\n\nfrom mplchart.chart import Chart\nfrom mplchart.primitives import Candlesticks, Volume\nfrom mplchart.indicators import ROC, SMA, EMA, RSI, MACD\n\nticker = 'AAPL'\nprices = yf.Ticker(ticker).history('5y')\n\nmax_bars = 250\n\nindicators = [\n    Candlesticks(), SMA(50), SMA(200), Volume(),\n    RSI(),\n    MACD(),\n]\n\nchart = Chart(title=ticker, max_bars=max_bars)\nchart.plot(prices, indicators)\n```\n\n\n## Conventions\n\nPrice data is expected to be presented as a pandas DataFrame\nwith columns `open`, `high`, `low`, `close` `volume`\nand a timestamp index named `date`.\nPlease note, the library will automatically convert column\nand index names to lower case for its internal use.\n\n\n## Drawing Primitives\n\nThe library contains drawing primitives that can be used as an indicator in the plot api.\nAll primitives are classes that must be instantiated before being used in the plot api.\n\n```python\nfrom mplchart.chart import Chart\nfrom mplchart.primitives import Candlesticks\n\nindicators = [Candlesticks()]\nchart = Chart(title=title, max_bars=max_bars)\nchart.plot(prices, indicators)\n```\n\nThe main drawing primitives are :\n- `Candlesticks` for candlesticks plots\n- `OHLC` for open, high, low, close bar plots\n- `Price` for price line plots\n- `Volume` for volume bar plots\n- `Peaks` to plot peaks and valleys\n- `SameAxes` to force plot on the same axes\n- `NewAxes` to force plot on a new axes\n\n\n## Builtin Indicators\n\nThe libary contains some basic technical analysis indicators implemented in pandas/numpy.\nIndicators are classes that must be instantiated before being used in the plot api.\n\nSome of the indicators included are:\n\n- `SMA` Simple Moving Average\n- `EMA` Exponential Moving Average\n- `ROC` Rate of Change\n- `RSI` Relative Strength Index\n- `MACD` Moving Average Convergence Divergence\n- `PPO` Price Percentage Oscillator \n- `SLOPE` Slope (linear regression with time)\n- `BBANDS` Bolling Bands\n\n\n## Ta-lib Abstract Functions\n\nIf you have [ta-lib](https://github.com/mrjbq7/ta-lib) installed you can use its abstract functions as indicators.\nThe indicators are created by calling `abstract.Function` with the name of the indicator and its parameters.\n\n```python\nfrom mplchart.primitives import Candlesticks\nfrom talib.abstract import Function\n\nindicators = [\n    Candlesticks(),\n    Function('SMA', 50),\n    Function('SMA', 200),\n    Function('RSI'),\n    Function('MACD'),\n]\n```\n\n\n## Custom Indicators\n\nAny callable that takes a prices data frame and returns a series as result can be used as indicator.\nA function can be used as an indicator but you can also implement an indicator as a callable dataclass.\n\n```python\nfrom dataclasses import dataclass\n\nfrom mplchart.library import get_series, calc_ema\n\n@dataclass\nclass DEMA:\n    \"\"\" Double Exponential Moving Average \"\"\"\n    period: int = 20\n\n    same_scale = True\n    # same_scale is an optional class attribute that indicates\n    # the indicator should be plot on the same axes by default\n\n    def __call__(self, prices):\n        series = get_series(prices)\n        ema1 = calc_ema(series, self.period)\n        ema2 = calc_ema(ema1, self.period)\n        return 2 * ema1 - ema2\n\n```\n\n## Examples\n\nYou can find example notebooks and scripts in the examples folder. \n\n## Installation\n\nYou can install the current version of this package with pip\n\n```console\npython -mpip install git+https://github.com/furechan/mplchart.git\n```\n\n## Requirements:\n\n- python >= 3.8\n- matplotlib\n- pandas\n- numpy\n- yfinance\n\n\n## Related Projects & Resources\n- [stockcharts.com](https://stockcharts.com/) Classic stock charts and technical analysis reference\n- [mplfinance](https://pypi.org/project/mplfinance/) Matplotlib utilities for the visualization,\nand visual analysis, of financial data\n- [matplotlib](https://github.com/matplotlib/matplotlib) Matplotlib: plotting with Python\n- [yfinance](https://github.com/ranaroussi/yfinance) Download market data from Yahoo! Finance's API\n- [ta-lib](https://github.com/mrjbq7/ta-lib) Python wrapper for TA-Lib\n- [pandas](https://github.com/pandas-dev/pandas) Flexible and powerful data analysis / manipulation library\nfor Python, providing labeled data structures similar to R data.frame objects,\nstatistical functions, and much more\n- [numpy](https://github.com/numpy/numpy) The fundamental package for scientific computing with Python\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Classic Stock Charts in Python",
    "version": "0.0.8",
    "project_urls": {
        "homepage": "https://github.com/furechan/mplchart"
    },
    "split_keywords": [
        "candlesticks",
        "charting",
        "finance",
        "matplotlib"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4aa64c237c9ff2195e54527ddbec4916aad3fdc263912a5e624d0a15f89d52ca",
                "md5": "e7adea54019bc71afbb208088bb34c60",
                "sha256": "0f3614927c4276d899e67a9d7c120adf5945571af782254dabee56ac57b0799a"
            },
            "downloads": -1,
            "filename": "mplchart-0.0.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e7adea54019bc71afbb208088bb34c60",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 427093,
            "upload_time": "2024-03-15T22:03:24",
            "upload_time_iso_8601": "2024-03-15T22:03:24.112389Z",
            "url": "https://files.pythonhosted.org/packages/4a/a6/4c237c9ff2195e54527ddbec4916aad3fdc263912a5e624d0a15f89d52ca/mplchart-0.0.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-15 22:03:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "furechan",
    "github_project": "mplchart",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "mplchart"
}
        
Elapsed time: 0.20371s