From 31d5d46dde5cebd0d0f662993f3bf8b6de602e8a Mon Sep 17 00:00:00 2001 From: Cedric Zhuang Date: Sat, 8 Jul 2023 22:49:21 +0800 Subject: [PATCH] [GH-165] Add Know Sure Thing support (#166) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- README.md | 15 +++++++++++++++ stockstats.py | 28 ++++++++++++++++++++++++++++ test.py | 7 +++++++ 3 files changed, 50 insertions(+) diff --git a/README.md b/README.md index 4e93595..fdf97ce 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/stockstats.py b/stockstats.py index 739357c..cab7f86 100644 --- a/stockstats.py +++ b/stockstats.py @@ -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) @@ -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): diff --git a/test.py b/test.py index 33ec9fa..8225392 100644 --- a/test.py +++ b/test.py @@ -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))