Skip to content

Commit

Permalink
[GH-165] Add Know Sure Thing support (#166)
Browse files Browse the repository at this point in the history
The Know Sure Thing (KST) is a momentum oscillator developed by
Martin Pring to make rate-of-change readings easier for traders
to interpret.

https://www.investopedia.com/terms/k/know-sure-thing-kst.asp

Formular:
* KST=(RCMA1×1)+(RCMA2×2) + (RCMA3×3)+(RCMA4×4)

Where:
* RCMA1=10-period SMA of 10-period ROC
* RCMA2=10-period SMA of 15-period ROC
* RCMA3=10-period SMA of 20-period ROC
* RCMA4=15-period SMA of 30-period ROC
  • Loading branch information
jealous authored Jul 8, 2023
1 parent febcde6 commit 31d5d46
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,21 @@ 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

#### [Know Sure Thing (kst)](https://www.investopedia.com/terms/k/know-sure-thing-kst.asp)

The Know Sure Thing (KST) is a momentum oscillator developed by
Martin Pring to make rate-of-change readings easier for traders
to interpret.

Formular:
* KST=(RCMA1×1)+(RCMA2×2) + (RCMA3×3)+(RCMA4×4)

Where:
* RCMA1=10-period SMA of 10-period ROC
* RCMA2=10-period SMA of 15-period ROC
* RCMA3=10-period SMA of 20-period ROC
* RCMA4=15-period SMA of 30-period ROC

## Issues

We use [Github Issues](https://github.com/jealous/stockstats/issues) to track
Expand Down
28 changes: 28 additions & 0 deletions stockstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,33 @@ def _get_inertia(self, meta: _Meta):
value = self._inertia(meta.int0, meta.int1)
self[meta.name] = value

def _kst(self) -> pd.Series:
""" Know Sure Thing (kst)
https://www.investopedia.com/terms/k/know-sure-thing-kst.asp
The Know Sure Thing (KST) is a momentum oscillator developed by
Martin Pring to make rate-of-change readings easier for traders
to interpret.
Formular:
* KST=(RCMA #1×1)+(RCMA #2×2) + (RCMA #3×3)+(RCMA #4×4)
where:
* RCMA #1=10-period SMA of 10-period ROC
* RCMA #2=10-period SMA of 15-period ROC
* RCMA #3=10-period SMA of 20-period ROC
* RCMA #4=15-period SMA of 30-period ROC
"""
ma1 = self.sma(self.roc(self.close, 10), 10)
ma2 = self.sma(self.roc(self.close, 15), 10)
ma3 = self.sma(self.roc(self.close, 20), 10)
ma4 = self.sma(self.roc(self.close, 30), 15)
return ma1 + ma2 * 2 + ma3 * 3 + ma4 * 4

def _get_kst(self, meta: _Meta):
self[meta.name] = self._kst()

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

def __init_not_exist_column(self, key):
Expand Down
7 changes: 7 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,3 +1037,10 @@ def test_inertia(self):
inertia10 = stock['inertia_10']
assert_that(inertia10[20110209], near_to(0.011085))
assert_that(inertia10[20110210], near_to(-0.014669))

def test_kst(self):
stock = self.get_stock_90days()
kst = stock['kst']
assert_that(kst[20110117], equal_to(0))
assert_that(kst[20110118], near_to(0.063442))
assert_that(kst[20110131], near_to(-2.519985))

0 comments on commit 31d5d46

Please sign in to comment.