feat: add volatility labeling scheme
- Removed requirements.txt file - Added volatility label function - Created pyproject.toml - Added uv.lock file
This commit is contained in:
@@ -143,3 +143,33 @@ def create_labels_regime_detection(df, short_window=20, long_window=50):
|
||||
df_copy.dropna(subset=["ma_short", "ma_long"], inplace=True)
|
||||
|
||||
return df_copy
|
||||
|
||||
|
||||
def create_labels_volatility(df: pd.DataFrame, returns_window: int = 1, vol_window: int = 20) -> pd.DataFrame:
|
||||
"""
|
||||
Creates labels based on volatility and future returns.
|
||||
|
||||
The function calculates the future returns and the rolling volatility, then
|
||||
assigns labels based on the following conditions:
|
||||
- 1: if future return > volatility
|
||||
- -1: if future return < -volatility
|
||||
- 0: otherwise
|
||||
|
||||
Args:
|
||||
df (pd.DataFrame): DataFrame containing the 'close' column.
|
||||
returns_window (int): Horizon for calculating future returns.
|
||||
vol_window (int): Rolling window for calculating volatility.
|
||||
|
||||
Returns:
|
||||
pd.DataFrame: A new DataFrame with a 'volatility_label' column in {-1, 0, +1}.
|
||||
"""
|
||||
df_copy = df.copy()
|
||||
df_copy = calculate_future_returns(df_copy, horizon=returns_window)
|
||||
df_copy["volatility"] = df_copy["future_returns"].rolling(vol_window, min_periods=1).std()
|
||||
|
||||
df_copy["volatility_label"] = 0
|
||||
df_copy.loc[df_copy["future_returns"] > df_copy["volatility"], "volatility_label"] = 1
|
||||
df_copy.loc[df_copy["future_returns"] < -df_copy["volatility"], "volatility_label"] = -1
|
||||
|
||||
df_copy.dropna(subset=["volatility", "future_returns"], inplace=True)
|
||||
return df_copy
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
[project]
|
||||
name = "alphaflow-trading-lab"
|
||||
version = "0.1.0"
|
||||
description = "AlphaFlow ML & DL Trading Bot is an end-to-end machine learning and deep learning trading framework for MetaTrader 5. It covers data loading, feature engineering, model training/tuning, backtesting with vectorbt, and live deployment—all in one repository."
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
dependencies = [
|
||||
"apscheduler>=3.11.0",
|
||||
"ipykernel>=6.30.1",
|
||||
"joblib>=1.5.2",
|
||||
"lightgbm==4.6.0",
|
||||
"matplotlib>=3.10.6",
|
||||
"matplotlib-inline>=0.1.7",
|
||||
"metatrader5>=5.0.4874 ; sys_platform == 'win32'",
|
||||
"nbformat>=5.10.4",
|
||||
"numpy>=1.23.5",
|
||||
"optuna>=4.5.0",
|
||||
"pandas>=2.3.3",
|
||||
"plotly>=5.24.1",
|
||||
"psutil>=7.1.0",
|
||||
"scikit-learn>=1.7.1",
|
||||
"scipy>=1.15.3",
|
||||
"seaborn>=0.13.2",
|
||||
"six>=1.17.0",
|
||||
"statsmodels>=0.14.5",
|
||||
"streamlit>=1.50.0",
|
||||
"streamlit-autorefresh>=1.0.1",
|
||||
"ta>=0.11.0",
|
||||
"ta-lib>=0.6.7",
|
||||
"tensorboard>=2.20.0",
|
||||
"tensorboard-data-server>=0.7.2",
|
||||
"tensorflow>=2.20.0",
|
||||
"tensorflow-intel>=0.0.1",
|
||||
"tensorflow-io-gcs-filesystem<=0.31.0",
|
||||
"vectorbt<=0.28.0",
|
||||
"xgboost==2.1.4",
|
||||
]
|
||||
Binary file not shown.
Reference in New Issue
Block a user