Skip to content

Commit

Permalink
Merge pull request peerchemist#124 from flamingrickpat/wavepm
Browse files Browse the repository at this point in the history
added mark whistler's wavepm
  • Loading branch information
peerchemist authored Oct 19, 2021
2 parents 6789c5a + d7ee503 commit 2c4431b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Finta supports over 80 trading indicators:
* Volume Flow Indicator 'VFI'
* Moving Standard deviation 'MSD'
* Schaff Trend Cycle 'STC'
* Mark Whistler's WAVE PM 'WAVEPM'
```

## Dependencies:
Expand Down
44 changes: 44 additions & 0 deletions finta/finta.py
Original file line number Diff line number Diff line change
Expand Up @@ -2258,6 +2258,50 @@ def VC(cls, ohlc: DataFrame, period: int = 5) -> DataFrame:

return pd.concat([value_chart_high, value_chart_low, value_chart_close, value_chart_open], axis=1)

@classmethod
def WAVEPM(
cls,
ohlc: DataFrame,
period: int = 14,
lookback_period: int = 100,
column: str = "close"
) -> Series:
"""
The Wave PM (Whistler Active Volatility Energy Price Mass) indicator is an oscillator described in the Mark
Whistler’s book “Volatility Illuminated”.
:param DataFrame ohlc: data
:param int period: period for moving average
:param int lookback_period: period for oscillator lookback
:return Series: WAVE PM
"""

ma = ohlc[column].rolling(window=period).mean()
std = ohlc[column].rolling(window=period).std(ddof=0)

def tanh(x):
two = np.where(x > 0, -2, 2)
what = two * x
ex = np.exp(what)
j = 1 - ex
k = ex - 1
l = np.where(x > 0, j, k)
output = l / (1 + ex)
return output

def osc(input_dev, mean, power):
variance = Series(power).rolling(window=lookback_period).sum() / lookback_period
calc_dev = np.sqrt(variance) * mean
y = (input_dev / calc_dev)
oscLine = tanh(y)
return oscLine

dev = 3.2 * std
power = np.power(dev / ma, 2)
wavepm = osc(dev, ma, power)

return pd.Series(wavepm, name="{0} period WAVEPM".format(period))


if __name__ == "__main__":
print([k for k in TA.__dict__.keys() if k[0] not in "_"])
8 changes: 8 additions & 0 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,3 +879,11 @@ def test_vc():
assert isinstance(vc["Value Chart Open"], series.Series)
assert vc.values[-1][0] == 0.50469864
assert vc.values[-1][-1] == -0.87573258

def test_sma():
"""test TA.WAVEPM"""

wavepm = TA.WAVEPM(ohlc, 14, 100, "close").round(decimals=8)

assert isinstance(wavepm, series.Series)
assert wavepm.values[-1] == 0.83298565

0 comments on commit 2c4431b

Please sign in to comment.