From 95d7566f3eb874f18f3f5c677f8c68a2093f53c1 Mon Sep 17 00:00:00 2001 From: Dong-Geon Lee Date: Thu, 18 Jan 2024 22:58:27 +0900 Subject: [PATCH 1/2] Remove sma_periods default value for StarcBands --- benchmarks/test_benchmark_indicators.py | 2 +- stock_indicators/indicators/starc_bands.py | 4 ++-- tests/test_starc_bands.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/benchmarks/test_benchmark_indicators.py b/benchmarks/test_benchmark_indicators.py index d5dc70d3..e89ddabc 100644 --- a/benchmarks/test_benchmark_indicators.py +++ b/benchmarks/test_benchmark_indicators.py @@ -179,7 +179,7 @@ def test_benchmark_smma(benchmark, quotes): benchmark(indicators.get_smma, quotes, 20) def test_benchmark_starc_bands(benchmark, quotes): - benchmark(indicators.get_starc_bands, quotes) + benchmark(indicators.get_starc_bands, quotes, 10) def test_benchmark_stc(benchmark, quotes): benchmark(indicators.get_stc, quotes) diff --git a/stock_indicators/indicators/starc_bands.py b/stock_indicators/indicators/starc_bands.py index 2f6d1730..59e33deb 100644 --- a/stock_indicators/indicators/starc_bands.py +++ b/stock_indicators/indicators/starc_bands.py @@ -7,7 +7,7 @@ from stock_indicators.indicators.common.quote import Quote -def get_starc_bands(quotes: Iterable[Quote], sma_periods: int = 20, +def get_starc_bands(quotes: Iterable[Quote], sma_periods: int, multiplier: float = 2, atr_periods: int = 10): """Get STARC Bands calculated. @@ -18,7 +18,7 @@ def get_starc_bands(quotes: Iterable[Quote], sma_periods: int = 20, `quotes` : Iterable[Quote] Historical price quotes. - `sma_periods` : int, defaults 20 + `sma_periods` : int Number of periods for the centerline SMA. `multiplier` : float, defaults 2 diff --git a/tests/test_starc_bands.py b/tests/test_starc_bands.py index 61f3439d..1f3d835c 100644 --- a/tests/test_starc_bands.py +++ b/tests/test_starc_bands.py @@ -46,10 +46,10 @@ def test_bad_data(self, bad_quotes): assert 502 == len(r) def test_no_quotes(self, quotes): - r = indicators.get_starc_bands([]) + r = indicators.get_starc_bands([], 10) assert 0 == len(r) - r = indicators.get_starc_bands(quotes[:1]) + r = indicators.get_starc_bands(quotes[:1], 10) assert 1 == len(r) def test_removed(self, quotes): From 55cbe1c5195b4d8fd2e546fa87f1906e866cb96b Mon Sep 17 00:00:00 2001 From: Dong-Geon Lee Date: Sat, 20 Jan 2024 18:55:34 +0900 Subject: [PATCH 2/2] Add warning msg if sma_periods is null --- stock_indicators/indicators/starc_bands.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stock_indicators/indicators/starc_bands.py b/stock_indicators/indicators/starc_bands.py index 59e33deb..4e47444f 100644 --- a/stock_indicators/indicators/starc_bands.py +++ b/stock_indicators/indicators/starc_bands.py @@ -1,4 +1,5 @@ from typing import Iterable, Optional, TypeVar +from warnings import warn from stock_indicators._cslib import CsIndicator from stock_indicators._cstypes import List as CsList @@ -7,7 +8,7 @@ from stock_indicators.indicators.common.quote import Quote -def get_starc_bands(quotes: Iterable[Quote], sma_periods: int, +def get_starc_bands(quotes: Iterable[Quote], sma_periods: int = None, multiplier: float = 2, atr_periods: int = 10): """Get STARC Bands calculated. @@ -35,6 +36,10 @@ def get_starc_bands(quotes: Iterable[Quote], sma_periods: int, - [STARC Bands Reference](https://python.stockindicators.dev/indicators/StarcBands/#content) - [Helper Methods](https://python.stockindicators.dev/utilities/#content) """ + if sma_periods is None: + warn('The default value of sma_periods will be removed in the next version. Pass sma_periods explicitly.', DeprecationWarning, stacklevel=2) + sma_periods = 20 + results = CsIndicator.GetStarcBands[Quote](CsList(Quote, quotes), sma_periods, multiplier, atr_periods) return STARCBandsResults(results, STARCBandsResult)