Skip to content

Commit

Permalink
[GH-163] Add Inertia Indicator (#164)
Browse files Browse the repository at this point in the history
In financial markets, the concept of inertia was given by Donald Dorsey
in the 1995 issue of Technical Analysis of Stocks and Commodities
through the Inertia Indicator. The Inertia Indicator is moment-based
and is an extension of Dorsey’s Relative Volatility Index (RVI).

Formular:
* inertia = n periods linear regression of RVGI

Examples:
* `df['inertia']` retrieves the inertia of 20 periods linear regression of 14 periods RVGI
* `df['inertia_10']` retrieves the inertia of 10 periods linear regression of 14 periods RVGI
  • Loading branch information
jealous authored Jul 7, 2023
1 parent e486d15 commit febcde6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![codecov](https://codecov.io/gh/jealous/stockstats/branch/master/graph/badge.svg?token=IFMD1pVJ7T)](https://codecov.io/gh/jealous/stockstats)
[![pypi](https://img.shields.io/pypi/v/stockstats.svg)](https://pypi.python.org/pypi/stockstats)

VERSION: 0.6.0
VERSION: 0.6.1

## Introduction

Expand Down Expand Up @@ -67,6 +67,7 @@ Supported statistics/indicators are:
* ERI: Elder-Ray Index
* FTR: the Gaussian Fisher Transform Price Reversals indicator
* RVGI: Relative Vigor Index
* Inertia: Inertia Indicator

## Installation

Expand Down Expand Up @@ -960,6 +961,20 @@ Examples:
* `df['rvgi_5']` retrieves the RVGI line of window 5
* `df['rvgis_5']` retrieves the RVGI signal line of window 5

#### [Inertia Indicator](https://theforexgeek.com/inertia-indicator/)

In financial markets, the concept of inertia was given by Donald Dorsey
in the 1995 issue of Technical Analysis of Stocks and Commodities
through the Inertia Indicator. The Inertia Indicator is moment-based
and is an extension of Dorsey’s Relative Volatility Index (RVI).

Formular:
* inertia = n periods linear regression of RVGI

Examples:
* `df['inertia']` retrieves the inertia of 20 periods linear regression of 14 periods RVGI
* `df['inertia_10']` retrieves the inertia of 10 periods linear regression of 14 periods RVGI

## Issues

We use [Github Issues](https://github.com/jealous/stockstats/issues) to track
Expand Down
21 changes: 21 additions & 0 deletions stockstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class StockStatsError(Exception):
'eribear': 13,
'eribull': 13,
'ichimoku': (9, 26, 52),
'inertia': (20, 14),
'ftr': 9,
'kama': (10, 5, 34), # window, fast, slow
'kdjd': 9,
Expand Down Expand Up @@ -1534,6 +1535,25 @@ def _get_rvgi(self, meta: _Meta):
self[meta.name] = rvgi
self[meta.name_ex('s')] = rvgi_s

def _inertia(self, window: int, rvgi_window: int) -> pd.Series:
""" Inertia Indicator
https://theforexgeek.com/inertia-indicator/
In financial markets, the concept of inertia was given by Donald Dorsey
in the 1995 issue of Technical Analysis of Stocks and Commodities
through the Inertia Indicator. The Inertia Indicator is moment-based
and is an extension of Dorsey’s Relative Volatility Index (RVI).
"""
rvgi = self._rvgi(rvgi_window)
value = self.linear_reg(rvgi, window)
value.iloc[:max(window, rvgi_window) + 2] = 0
return value

def _get_inertia(self, meta: _Meta):
value = self._inertia(meta.int0, meta.int1)
self[meta.name] = value

@staticmethod
def parse_column_name(name):
m = re.match(r'(.*)_([\d\-+~,.]+)_(\w+)', name)
Expand Down Expand Up @@ -1678,6 +1698,7 @@ def handler(self):
('eribull', 'eribear'): self._get_eri,
('ftr',): self._get_ftr,
('rvgi', 'rvgis'): self._get_rvgi,
('inertia',): self._get_inertia,
}

def __init_not_exist_column(self, key):
Expand Down
21 changes: 21 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,3 +1016,24 @@ def test_change_group_window_defaults(self):
assert_that(macd[i], equal_to(ref[i]))

stockstats.set_dft_window('macd', orig)

def test_inertia(self):
stock = self.get_stock_90days()
inertia = stock['inertia']
assert_that(inertia[20110209], equal_to(0))
assert_that(inertia[20110210], near_to(-0.024856))
assert_that(inertia[20110304], near_to(0.155576))

inertia_dft = stock['inertia_20,14']
assert_that(inertia_dft[20110209], equal_to(0))
assert_that(inertia_dft[20110210], near_to(-0.024856))
assert_that(inertia_dft[20110304], near_to(0.155576))

inertia14 = stock['inertia_20']
assert_that(inertia14[20110209], equal_to(0))
assert_that(inertia14[20110210], near_to(-0.024856))
assert_that(inertia14[20110304], near_to(0.155576))

inertia10 = stock['inertia_10']
assert_that(inertia10[20110209], near_to(0.011085))
assert_that(inertia10[20110210], near_to(-0.014669))

0 comments on commit febcde6

Please sign in to comment.