Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
furechan committed Oct 17, 2024
1 parent b93445a commit 1d6b4bb
Show file tree
Hide file tree
Showing 39 changed files with 2,001 additions and 1,060 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Change Log

## 0.0.14
- Added STOCH Indicator (Stochastic Oscillator)
- Added `STOCH` Indicator (Stochastic Oscillator)
- Added `LinePlot`, `AreaPlot` and `BarPlot` primitives


## 0.0.13
- Updated Pypi README
Expand Down
44 changes: 34 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import yfinance as yf

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

ticker = 'AAPL'
prices = yf.Ticker(ticker).history('5y')
Expand All @@ -51,15 +51,15 @@ chart.show()

Price data is expected to be presented as a pandas DataFrame
with columns `open`, `high`, `low`, `close` `volume`
and a timestamp index named `date` or `datetime`.
and a datetime index named `date` or `datetime`.
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 like an indicator in the plot api.
Primitives are classes and must be instantiated before being used as parameters to the plot api.
Primitives are classes and must be instantiated as objects before being used with the plot api.

```python
from mplchart.chart import Chart
Expand All @@ -76,12 +76,19 @@ The main drawing primitives are :
- `Price` for price line plots
- `Volume` for volume bar plots
- `Peaks` to mark peaks and valleys
- `SameAxes` to use same axes as last plot
- `NewAxes` to use new axes above or below
- `LinePlot` draw an indicator as line plot
- `AreaPlot` draw an indicator as area plot
- `BarPlot` draw an indicator as bar plot




## Builtin Indicators

The libary contains some basic technical analysis indicators implemented in pandas/numpy.
Indicators are classes and must be instantiated before being used as parameters to the plot api.
The libary includes some standard technical analysis indicators implemented in pandas/numpy.
Indicators are classes and must be instantiated as objects before being used with the plot api.

Some of the indicators included are:

Expand All @@ -103,7 +110,7 @@ Some of the indicators included are:



## Talib Abstract Functions
## Talib Functions

If you have [ta-lib](https://github.com/mrjbq7/ta-lib) installed you can use the library abstract functions as indicators.
The indicators are created by calling `Function` with the name of the indicator and its parameters.
Expand All @@ -122,12 +129,29 @@ indicators = [
```


## Select target axes with `NewAxes` and `SameAxes` modifiers
## Override indicator rendering with the plotting primitives

Most indicators are drawn as line plots with default colors and settings. You can override the rendering of an indicator by piping it with the `|` operator into a primitive like `LinePlot`, `AreaPlot` or `BarPlot` as in the example below. If the indicator returns a dataframe instead of a series you need to specify an `item` (column name) in the primitive.


```python
from mplchart.indicators import SMA, EMA, ROC
from mplchart.primitives import Candlesticks, LinePlot

indicators = [
Candlesticks(),
SMA(20) | LinePlot(style="dashed", color="red", alpha=0.5, width=3)
]
```


## Override target axes with `NewAxes` and `SameAxes` primitives

Indicators usually plot in a new axes below, except for a few indicators that plot by default in the main axes. You can change the target axes to use for any indicator by using an axes modifier. A modifier is applied to an indicator with the `|` operator as in the example below.
Indicators usually plot in a new axes below, except for a few indicators that plot by default in the main axes. You can change the target axes for any indicator by piping it into an axes primitive as in the example below.

```python
from mplchart.modifiers import NewAxes, SameAxes
from mplchart.indicators import SMA, EMA, ROC
from mplchart.primitives import Candlesticks, NewAxes, SameAxes

indicators = [
Candlesticks(),
Expand Down Expand Up @@ -168,7 +192,7 @@ class DEMA(Indicator):

## Examples

You can find example notebooks and scripts in the examples folder.
You can find example notebooks and scripts in the `examples` folder.

## Installation

Expand Down
92 changes: 13 additions & 79 deletions examples/candlesticks-chart.ipynb

Large diffs are not rendered by default.

115 changes: 65 additions & 50 deletions examples/chart-primitives.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
},
"source": [
"# DMI Indicator Example"
"# Directional Movement Index Example"
]
},
{
Expand Down
16 changes: 0 additions & 16 deletions examples/macd-indicator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,6 @@
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
26 changes: 16 additions & 10 deletions examples/ohlc-chart.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
},
"source": [
"# RSI Indicator Example"
"# Relative Strength Index Example"
]
},
{
Expand Down
File renamed without changes.
74 changes: 53 additions & 21 deletions examples/talib-examples.ipynb

Large diffs are not rendered by default.

134 changes: 134 additions & 0 deletions misc/areplot-primitive.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion misc/axes-modifiers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
},
"source": [
"# Axes Modifiers (preliminary)"
"# Axes Modifiers (legacy)"
]
},
{
Expand Down
182 changes: 182 additions & 0 deletions misc/axes-primitives.ipynb

Large diffs are not rendered by default.

139 changes: 139 additions & 0 deletions misc/barplot-primitive.ipynb

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions misc/design-ideas.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ MACD() | Styles(macd=..., macdsignal)

ADX() | Replace(yticks=(20, 40)) # indicator.info

# Specific Plot Primitives

SMA(50) | LinePlot(color="...")
SMA(50) | AreaPlot(color="...")
SMA(50) | BarPlot(color="...")
SMA(50) | ScatterPlot(color="...")

# Generic Plot Primitive

SMA(50) | Plot("line", color="...")
SMA(50) | Plot("area", AreaPlot(color="...")
SMA(50) | Plot("scatter", color="...")
SMA(50) | Plot("bars", color="...")



# Style dataclass ???

Expand Down
161 changes: 161 additions & 0 deletions misc/lineplot-primitive.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion misc/matplotlib-stylelib.ipynb

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions misc/mplchart-tests.ipynb

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions misc/peaks-primitive.ipynb

Large diffs are not rendered by default.

174 changes: 174 additions & 0 deletions misc/price-primitive.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 1d6b4bb

Please sign in to comment.