Skip to content

Commit

Permalink
Some changes to momentum_indicators to satisfy mypy. More needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
fmilthaler committed Oct 1, 2023
1 parent 0006823 commit d1cc80f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
19 changes: 9 additions & 10 deletions finquant/momentum_indicators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" This module provides function(s) to compute momentum indicators
used in technical analysis such as RSI, MACD etc. """
import datetime
from typing import List
from typing import List, Optional

import matplotlib.pyplot as plt
import mplfinance as mpf
Expand Down Expand Up @@ -121,17 +121,17 @@ def relative_strength_index(
# Single plot
fig = plt.figure()
axis = fig.add_subplot(111)
axis.axhline(y=overbought, color="r", linestyle="dashed", label="overbought")
axis.axhline(y=oversold, color="g", linestyle="dashed", label="oversold")
axis.axhline(y=float(overbought), color="r", linestyle="dashed", label="overbought")
axis.axhline(y=float(oversold), color="g", linestyle="dashed", label="oversold")
axis.set_ylim(0, 100)
data["rsi"].plot(ylabel="RSI", xlabel="Date", ax=axis, grid=True)
plt.title("RSI Plot")
plt.legend(loc="center left", bbox_to_anchor=(1, 0.5))
else:
# RSI against price in 2 plots
fig, axis = plt.subplots(2, 1, sharex=True, sharey=False)
axis[0].axhline(y=overbought, color="r", linestyle="dashed", label="overbought")
axis[0].axhline(y=oversold, color="g", linestyle="dashed", label="oversold")
axis[0].axhline(y=float(overbought), color="r", linestyle="dashed", label="overbought")
axis[0].axhline(y=float(oversold), color="g", linestyle="dashed", label="oversold")
axis[0].set_title("RSI + Price Plot")
axis[0].set_ylim(0, 100)
# plot 2 graphs in 2 colors
Expand Down Expand Up @@ -217,10 +217,10 @@ def gen_macd_color(df: pd.DataFrame) -> List[str]:

def mpl_macd(
data: SERIES_OR_DATAFRAME,
longer_ema_window: INT = 26,
shorter_ema_window: INT = 12,
signal_ema_window: INT = 9,
stock_name: str = None,
longer_ema_window: Optional[INT] = 26,
shorter_ema_window: Optional[INT] = 12,
signal_ema_window: Optional[INT] = 9,
stock_name: Optional[str] = None,
):
"""
Generate a Matplotlib candlestick chart with MACD (Moving Average Convergence Divergence) indicators.
Expand All @@ -231,7 +231,6 @@ def mpl_macd(
MACD, MACD Signal Line, and MACD Histogram indicators. The MACD is calculated by taking
the difference between two Exponential Moving Averages (EMAs) of the closing price.
:param data: Time series data containing stock price information. If a
DataFrame is provided, it should have columns 'Open', 'Close', 'High', 'Low', and 'Volume'.
Else, stock price data for given time frame is downloaded again.
Expand Down
3 changes: 1 addition & 2 deletions finquant/type_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ def _check_type(

if element_type is not None:
if isinstance(arg_values, pd.DataFrame) and not all(
np.issubdtype(value_type, element_type)
for value_type in arg_values.dtypes
np.issubdtype(value_type, element_type) for value_type in arg_values.dtypes
):
validation_failed = True

Expand Down
3 changes: 0 additions & 3 deletions finquant/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from typing import List

from finquant.data_types import ELEMENT_TYPE, LIST_DICT_KEYS


def all_list_ele_in_other(
# l_1: List, l_2: List
l_1: LIST_DICT_KEYS[ELEMENT_TYPE],
l_2: LIST_DICT_KEYS[ELEMENT_TYPE],
) -> bool:
Expand Down

0 comments on commit d1cc80f

Please sign in to comment.