Spaces:
Running
Running
Updated the chart title
Browse files
app.py
CHANGED
|
@@ -6,7 +6,9 @@ from datetime import date
|
|
| 6 |
import plotly.graph_objects as go
|
| 7 |
import itertools
|
| 8 |
import json
|
| 9 |
-
from ta
|
|
|
|
|
|
|
| 10 |
from multiprocessing import Pool, cpu_count
|
| 11 |
from functools import partial
|
| 12 |
|
|
@@ -161,10 +163,16 @@ def run_backtest(data, params, use_rsi, use_volatility, use_trend, use_volume, r
|
|
| 161 |
if len(df) < params.get('large_ma_period', 200) or len(df) < params.get('bband_period', 20):
|
| 162 |
return 0, 0, 0, 0, None, ([], [], [], []), []
|
| 163 |
df['large_ma'] = df['Close'].rolling(window=params['large_ma_period']).mean()
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
df['
|
| 167 |
-
df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
df['Volatility_p'] = df['Close'].pct_change().rolling(window=14).std()
|
| 169 |
df['SMA_200'] = df['Close'].rolling(window=200, min_periods=1).mean()
|
| 170 |
if 'Volume' in df.columns:
|
|
@@ -540,9 +548,9 @@ def generate_advisor_report(main_df, main_content_placeholder):
|
|
| 540 |
data_for_backtest = main_df[cols_to_use].rename(columns={ticker_symbol: 'Close', f'{ticker_symbol}_Volume': 'Volume'})
|
| 541 |
|
| 542 |
_, _, _, _, _, _, open_trades = run_backtest(data_for_backtest, params_for_run,
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
|
| 547 |
if open_trades:
|
| 548 |
for trade in open_trades:
|
|
|
|
| 6 |
import plotly.graph_objects as go
|
| 7 |
import itertools
|
| 8 |
import json
|
| 9 |
+
# --- MODIFIED IMPORTS: Changed to import specific indicator classes from 'ta' ---
|
| 10 |
+
from ta.volatility import BollingerBands
|
| 11 |
+
from ta.momentum import RSIIndicator
|
| 12 |
from multiprocessing import Pool, cpu_count
|
| 13 |
from functools import partial
|
| 14 |
|
|
|
|
| 163 |
if len(df) < params.get('large_ma_period', 200) or len(df) < params.get('bband_period', 20):
|
| 164 |
return 0, 0, 0, 0, None, ([], [], [], []), []
|
| 165 |
df['large_ma'] = df['Close'].rolling(window=params['large_ma_period']).mean()
|
| 166 |
+
|
| 167 |
+
# --- MODIFIED: Calculate Bollinger Bands using the 'ta' library ---
|
| 168 |
+
indicator_bb = BollingerBands(close=df['Close'], window=params['bband_period'], window_dev=params['bband_std_dev'])
|
| 169 |
+
df['bband_lower'] = indicator_bb.bollinger_lband()
|
| 170 |
+
df['bband_upper'] = indicator_bb.bollinger_hband()
|
| 171 |
+
|
| 172 |
+
# --- MODIFIED: Calculate RSI using the 'ta' library ---
|
| 173 |
+
indicator_rsi = RSIIndicator(close=df['Close'], window=14)
|
| 174 |
+
df['RSI'] = indicator_rsi.rsi()
|
| 175 |
+
|
| 176 |
df['Volatility_p'] = df['Close'].pct_change().rolling(window=14).std()
|
| 177 |
df['SMA_200'] = df['Close'].rolling(window=200, min_periods=1).mean()
|
| 178 |
if 'Volume' in df.columns:
|
|
|
|
| 548 |
data_for_backtest = main_df[cols_to_use].rename(columns={ticker_symbol: 'Close', f'{ticker_symbol}_Volume': 'Volume'})
|
| 549 |
|
| 550 |
_, _, _, _, _, _, open_trades = run_backtest(data_for_backtest, params_for_run,
|
| 551 |
+
use_rsi, use_vol, use_trend, use_volume,
|
| 552 |
+
factor_weights['rsi'], factor_weights['vol'],
|
| 553 |
+
factor_weights['trend'], factor_weights['volume'])
|
| 554 |
|
| 555 |
if open_trades:
|
| 556 |
for trade in open_trades:
|