diff --git a/docs/_indicators/Roc.md b/docs/_indicators/Roc.md index 99246f83..85f04e2f 100644 --- a/docs/_indicators/Roc.md +++ b/docs/_indicators/Roc.md @@ -41,6 +41,7 @@ ROCResults[ROCResult] | name | type | notes | -- |-- |-- | `date` | datetime | Date +| `momentum` | float, Optional | Raw change in price over `N` periods | `roc` | float, Optional | Rate of Change over `N` lookback periods (%, not decimal) | `roc_sma` | float, Optional | Moving average (SMA) of ROC based on `sma_periods` periods, if specified @@ -95,7 +96,7 @@ ROCWBResults[ROCWBResult] ## About {{ page.title }} -[Rate of Change](https://en.wikipedia.org/wiki/Momentum_(technical_analysis)), also known as Momentum Oscillator, is the percent change of Close price over a lookback window. A [Rate of Change with Bands](#roc-with-bands) variant, created by Vitali Apirine, is also included. +[Rate of Change](https://en.wikipedia.org/wiki/Momentum_(technical_analysis)), also known as Momentum Oscillator, is the percent change of Close price over a lookback window. Momentum is the raw price change equivalent. A [Rate of Change with Bands](#roc-with-bands) variant, created by Vitali Apirine, is also available. [[Discuss] 💬]({{site.dotnet.repo}}/discussions/242 "Community discussion about this indicator") ![image]({{site.dotnet.charts}}/Roc.png) diff --git a/stock_indicators/indicators/roc.py b/stock_indicators/indicators/roc.py index 48ce0655..e6c1b785 100644 --- a/stock_indicators/indicators/roc.py +++ b/stock_indicators/indicators/roc.py @@ -70,6 +70,14 @@ class ROCResult(ResultBase): A wrapper class for a single unit of ROC results. """ + @property + def momentum(self) -> Optional[float]: + return self._csdata.Momentum + + @momentum.setter + def momentum(self, value): + self._csdata.Momentum = value + @property def roc(self) -> Optional[float]: return self._csdata.Roc diff --git a/tests/test_roc.py b/tests/test_roc.py index 94a0faf9..1d266625 100644 --- a/tests/test_roc.py +++ b/tests/test_roc.py @@ -6,14 +6,22 @@ def test_standard(self, quotes): results = indicators.get_roc(quotes, 20) assert 502 == len(results) + assert 482 == len(list(filter(lambda x: x.momentum is not None, results))) assert 482 == len(list(filter(lambda x: x.roc is not None, results))) assert 000 == len(list(filter(lambda x: x.roc_sma is not None, results))) + r = results[49] + assert 4.96 == round(float(r.momentum), 4) + assert 2.2465 == round(float(r.roc), 4) + assert r.roc_sma is None + r = results[249] + assert 6.25 == round(float(r.momentum), 4) assert 2.4827 == round(float(r.roc), 4) assert r.roc_sma is None r = results[501] + assert -22.05 == round(float(r.momentum), 4) assert -8.2482 == round(float(r.roc), 4) assert r.roc_sma is None