From bcb2aa5bee9fc8226dc58ae765c0b9ced59d4648 Mon Sep 17 00:00:00 2001 From: Danglewood <85772166+deeleeramone@users.noreply.github.com> Date: Mon, 27 Feb 2023 18:33:53 -0800 Subject: [PATCH] improves error handling for volatility models when window length is too small --- .../technical_analysis/volatility_model.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/openbb_terminal/common/technical_analysis/volatility_model.py b/openbb_terminal/common/technical_analysis/volatility_model.py index e8a1ed0c45d..00d41e0f558 100644 --- a/openbb_terminal/common/technical_analysis/volatility_model.py +++ b/openbb_terminal/common/technical_analysis/volatility_model.py @@ -214,6 +214,10 @@ def standard_deviation( >>> df = openbb.ta.standard_deviation(data) """ + if window < 2: + print("Error: Window must be at least 2, defaulting to 30.") + window = 30 + trading_periods = 365 if is_crypto else 252 log_return = (data["Close"] / data["Close"].shift(1)).apply(np.log) @@ -263,6 +267,10 @@ def parkinson( >>> df = openbb.ta.parkinson(data, is_crypto = True) """ + if window < 1: + print("Error: Window must be at least 1, defaulting to 30.") + window = 30 + trading_periods = 365 if is_crypto else 252 rs = (1.0 / (4.0 * np.log(2.0))) * ( @@ -316,6 +324,10 @@ def garman_klass( >>> df = openbb.ta.garman_klass(data, is_crypto = True) """ + if window < 1: + print("Error: Window must be at least 1, defaulting to 30.") + window = 30 + trading_periods = 365 if is_crypto else 252 log_hl = (data["High"] / data["Low"]).apply(np.log) @@ -369,6 +381,10 @@ def hodges_tompkins( >>> df = openbb.ta.hodges_tompkins(data, is_crypto = True) """ + if window < 2: + print("Error: Window must be at least 2, defaulting to 30.") + window = 30 + trading_periods = 365 if is_crypto else 252 log_return = (data["Close"] / data["Close"].shift(1)).apply(np.log) @@ -426,6 +442,10 @@ def rogers_satchell( >>> df = openbb.ta.rogers_satchell(data, is_crypto = True) """ + if window < 1: + print("Error: Window must be at least 1, defaulting to 30.") + window = 30 + trading_periods = 365 if is_crypto else 252 log_ho = (data["High"] / data["Open"]).apply(np.log) @@ -479,6 +499,9 @@ def yang_zhang( >>> df = openbb.ta.yang_zhang(data, is_crypto = True) """ + if window < 2: + print("Error: Window must be at least 2, defaulting to 30.") + window = 30 trading_periods = 365 if is_crypto else 252 log_ho = (data["High"] / data["Open"]).apply(np.log)