Skip to content

Commit

Permalink
Added mamode in hma
Browse files Browse the repository at this point in the history
  • Loading branch information
XotEmBotZ committed Jan 6, 2025
1 parent 438f3a9 commit c481cc6
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions pandas_ta/overlap/hma.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# -*- coding: utf-8 -*-
from sys import modules as sys_modules
from numpy import sqrt
from pandas import Series
from pandas_ta._typing import DictLike, Int
from pandas_ta.utils import v_offset, v_pos_default, v_series
from pandas_ta.utils import v_offset, v_pos_default, v_series,v_mamode
from .wma import wma

from .ema import ema


def hma(
close: Series, length: Int = None,
close: Series, length: Int = None,mamode: str = None,
offset: Int = None, **kwargs: DictLike
) -> Series:
"""Hull Moving Average (HMA)
Expand All @@ -22,6 +23,7 @@ def hma(
Args:
close (pd.Series): Series of 'close's
length (int): It's period. Default: 10
mamode (str): Options: 'ema', 'wma'. Default: 'wma'
offset (int): How many periods to offset the result. Default: 0
Kwargs:
Expand All @@ -31,6 +33,7 @@ def hma(
pd.Series: New feature generated.
"""
# Validate
mamode = v_mamode(mamode, "wma")
length = v_pos_default(length, 10)
close = v_series(close, length + 2)

Expand All @@ -39,13 +42,22 @@ def hma(

offset = v_offset(offset)

supported_mas = [
"ema","wma"
]

if mamode not in supported_mas:
return

# Calculate
half_length = int(length / 2)
sqrt_length = int(sqrt(length))

wmaf = wma(close=close, length=half_length)
wmas = wma(close=close, length=length)
hma = wma(close=2 * wmaf - wmas, length=sqrt_length)
fn=getattr(sys_modules[__name__],mamode)

maf = fn(close=close, length=half_length)
mas = fn(close=close, length=length)
hma = fn(close=2 * maf - mas, length=sqrt_length)

# Offset
if offset != 0:
Expand Down

0 comments on commit c481cc6

Please sign in to comment.