Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
furechan committed Sep 27, 2024
1 parent 39c38b5 commit f32bfb2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
14 changes: 7 additions & 7 deletions examples/dmi-indicator.ipynb

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions examples/rsi-indicator.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions misc/matplotlib-stylelib.ipynb

Large diffs are not rendered by default.

7 changes: 1 addition & 6 deletions src/mplchart/indicators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" technical analysis indicators """
"""technical analysis indicators"""

import numpy as np

Expand All @@ -9,7 +9,6 @@
from .colors import default_edgecolor, closest_color



class SMA(Indicator):
"""Simple Moving Average"""

Expand Down Expand Up @@ -104,8 +103,6 @@ def __call__(self, prices):
return library.calc_slope(series, self.period)




class RSI(Indicator):
"""Relative Strengh Index"""

Expand Down Expand Up @@ -167,7 +164,6 @@ def plot_result(self, data, chart, ax=None):
ax.grid(axis="y", which="major", linestyle="-", linewidth=2)



class DMI(Indicator):
"""Directional Movement Index"""

Expand All @@ -187,7 +183,6 @@ def plot_result(self, data, chart, ax=None):
pdi = data.iloc[:, 1]
ndi = data.iloc[:, 2]


adxcolor = default_edgecolor()
pdicolor = closest_color("green")
ndicolor = closest_color("red")
Expand Down
15 changes: 7 additions & 8 deletions src/mplchart/library.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
""" technical analysis library """
"""technical analysis library"""

import math
import numpy as np
import pandas as pd

from .utils import get_series # noqa F401
from .utils import get_series # noqa F401

# TODO remove get_series import

Expand Down Expand Up @@ -43,9 +43,9 @@ def calc_hma(series, period: int = 20):
if period <= 0:
raise ValueError("period must be greater than zero")

m1 = calc_wma(series, round(period/2))
m1 = calc_wma(series, round(period / 2))
m2 = calc_wma(series, period)
m3 = (2 * m1) - m2
m3 = (2 * m1) - m2

result = calc_wma(m3, round(math.sqrt(period)))

Expand All @@ -68,17 +68,17 @@ def calc_rsi(series, period: int = 14):
def calc_atr(prices, period: int = 14, *, percent: bool = False):
"""Average True Range"""

hlc = prices.filter(['high', 'low']).join(prices['close'].shift(1))
hlc = prices.filter(["high", "low"]).join(prices["close"].shift(1))
trange = hlc.max(axis=1) - hlc.min(axis=1)

if period > 0:
ewm = dict(alpha=1 / period, min_periods=period, adjust=True, ignore_na=True)
result = trange.ewm(**ewm).mean()
else:
result = trange

if percent:
result = 100 * result / prices['close']
result = 100 * result / prices["close"]

return result

Expand Down Expand Up @@ -152,7 +152,6 @@ def calc_ndi(prices, period: int = 14):
return calc_dmi(prices, period).ndi



def calc_slope(series, period: int = 20):
"""calculates the slope (lnear regression) over a rolling window"""

Expand Down
5 changes: 5 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ basepython = python3
skip_install = true
setenv = RUFF_CACHE_DIR={env:TMPDIR}/ruff_cache

[flake8]
exclude = .*, build, dist
max-line-length = 88
per-file-ignores =
__init__.py: F401

0 comments on commit f32bfb2

Please sign in to comment.