diff --git a/features/__pycache__/__init__.cpython-311.pyc b/features/__pycache__/__init__.cpython-311.pyc deleted file mode 100644 index f20d9b9..0000000 Binary files a/features/__pycache__/__init__.cpython-311.pyc and /dev/null differ diff --git a/features/__pycache__/__init__.cpython-312.pyc b/features/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index b2bc762..0000000 Binary files a/features/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/features/__pycache__/feature_engineering.cpython-311.pyc b/features/__pycache__/feature_engineering.cpython-311.pyc deleted file mode 100644 index ca342a2..0000000 Binary files a/features/__pycache__/feature_engineering.cpython-311.pyc and /dev/null differ diff --git a/features/__pycache__/feature_engineering.cpython-312.pyc b/features/__pycache__/feature_engineering.cpython-312.pyc deleted file mode 100644 index abdc0ef..0000000 Binary files a/features/__pycache__/feature_engineering.cpython-312.pyc and /dev/null differ diff --git a/features/__pycache__/labeling.cpython-311.pyc b/features/__pycache__/labeling.cpython-311.pyc deleted file mode 100644 index 2502012..0000000 Binary files a/features/__pycache__/labeling.cpython-311.pyc and /dev/null differ diff --git a/features/__pycache__/labeling_schemes.cpython-311.pyc b/features/__pycache__/labeling_schemes.cpython-311.pyc deleted file mode 100644 index a66a95a..0000000 Binary files a/features/__pycache__/labeling_schemes.cpython-311.pyc and /dev/null differ diff --git a/features/__pycache__/labeling_schemes.cpython-312.pyc b/features/__pycache__/labeling_schemes.cpython-312.pyc deleted file mode 100644 index e1bc53d..0000000 Binary files a/features/__pycache__/labeling_schemes.cpython-312.pyc and /dev/null differ diff --git a/features/feature_engineering.py b/features/feature_engineering.py index ae6e644..145296e 100644 --- a/features/feature_engineering.py +++ b/features/feature_engineering.py @@ -129,11 +129,9 @@ def parkinson_estimator(window: pd.DataFrame) -> float: def moving_parkinson_estimator(df: pd.DataFrame, window_size: int = 30) -> pd.DataFrame: dfc = df.copy() - rolling_vol = pd.Series(dtype="float64", index=dfc.index) - for i in range(window_size, len(dfc)): - w = dfc.iloc[i - window_size : i] - rolling_vol.iloc[i] = parkinson_estimator(w) - dfc["rolling_volatility_parkinson"] = rolling_vol + sq_log_hl = np.log(dfc["high"] / dfc["low"]) ** 2 + rolling_sum = sq_log_hl.rolling(window=window_size).sum().shift(1) + dfc["rolling_volatility_parkinson"] = np.sqrt(rolling_sum / (4 * math.log(2) * window_size)) return dfc @@ -148,11 +146,11 @@ def yang_zhang_estimator(window: pd.DataFrame) -> float: def moving_yang_zhang_estimator(df: pd.DataFrame, window_size: int = 30) -> pd.DataFrame: dfc = df.copy() - rolling_vol = pd.Series(dtype="float64", index=dfc.index) - for i in range(window_size, len(dfc)): - w = dfc.iloc[i - window_size : i] - rolling_vol.iloc[i] = yang_zhang_estimator(w) - dfc["rolling_volatility_yang_zhang"] = rolling_vol + term1 = np.log(dfc["high"] / dfc["low"]) ** 2 + term2 = np.log(dfc["close"] / dfc["open"]) ** 2 + term_sum = term1 + term2 + rolling_mean = term_sum.rolling(window=window_size).mean().shift(1) + dfc["rolling_volatility_yang_zhang"] = np.sqrt(rolling_mean) return dfc