Spaces:
Running
Running
update utils
Browse files
utils.py
CHANGED
|
@@ -88,12 +88,19 @@ def calculate_technical_indicators(data):
|
|
| 88 |
}
|
| 89 |
|
| 90 |
# Moving Averages
|
|
|
|
|
|
|
|
|
|
| 91 |
indicators['moving_averages'] = {
|
| 92 |
-
'sma_20':
|
| 93 |
-
'sma_50':
|
| 94 |
'sma_200': data['Close'].rolling(200).mean().iloc[-1],
|
| 95 |
'ema_12': data['Close'].ewm(span=12).mean().iloc[-1],
|
| 96 |
-
'ema_26': data['Close'].ewm(span=26).mean().iloc[-1]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
}
|
| 98 |
|
| 99 |
# Volume indicators
|
|
@@ -341,7 +348,7 @@ def create_price_chart(data, indicators):
|
|
| 341 |
fig.add_trace(
|
| 342 |
go.Scatter(
|
| 343 |
x=data.index,
|
| 344 |
-
y=indicators['moving_averages']['
|
| 345 |
name='SMA 20',
|
| 346 |
line=dict(color='orange', width=1)
|
| 347 |
),
|
|
@@ -351,7 +358,7 @@ def create_price_chart(data, indicators):
|
|
| 351 |
fig.add_trace(
|
| 352 |
go.Scatter(
|
| 353 |
x=data.index,
|
| 354 |
-
y=indicators['moving_averages']['
|
| 355 |
name='SMA 50',
|
| 356 |
line=dict(color='blue', width=1)
|
| 357 |
),
|
|
@@ -432,7 +439,7 @@ def create_technical_chart(data, indicators):
|
|
| 432 |
fig.add_trace(
|
| 433 |
go.Scatter(
|
| 434 |
x=data.index,
|
| 435 |
-
y=
|
| 436 |
name='SMA 20',
|
| 437 |
line=dict(color='orange', dash='dash')
|
| 438 |
),
|
|
|
|
| 88 |
}
|
| 89 |
|
| 90 |
# Moving Averages
|
| 91 |
+
sma_20_series = data['Close'].rolling(20).mean()
|
| 92 |
+
sma_50_series = data['Close'].rolling(50).mean()
|
| 93 |
+
|
| 94 |
indicators['moving_averages'] = {
|
| 95 |
+
'sma_20': sma_20_series.iloc[-1], # Current value
|
| 96 |
+
'sma_50': sma_50_series.iloc[-1], # Current value
|
| 97 |
'sma_200': data['Close'].rolling(200).mean().iloc[-1],
|
| 98 |
'ema_12': data['Close'].ewm(span=12).mean().iloc[-1],
|
| 99 |
+
'ema_26': data['Close'].ewm(span=26).mean().iloc[-1],
|
| 100 |
+
|
| 101 |
+
# ADDED: Full historical series for plotting
|
| 102 |
+
'sma_20_values': sma_20_series,
|
| 103 |
+
'sma_50_values': sma_50_series
|
| 104 |
}
|
| 105 |
|
| 106 |
# Volume indicators
|
|
|
|
| 348 |
fig.add_trace(
|
| 349 |
go.Scatter(
|
| 350 |
x=data.index,
|
| 351 |
+
y=indicators['moving_averages']['sma_20_values'], # FIXED: Use full series
|
| 352 |
name='SMA 20',
|
| 353 |
line=dict(color='orange', width=1)
|
| 354 |
),
|
|
|
|
| 358 |
fig.add_trace(
|
| 359 |
go.Scatter(
|
| 360 |
x=data.index,
|
| 361 |
+
y=indicators['moving_averages']['sma_50_values'], # FIXED: Use full series
|
| 362 |
name='SMA 50',
|
| 363 |
line=dict(color='blue', width=1)
|
| 364 |
),
|
|
|
|
| 439 |
fig.add_trace(
|
| 440 |
go.Scatter(
|
| 441 |
x=data.index,
|
| 442 |
+
y=indicators['moving_averages']['sma_20_values'], # FIXED: Use full series
|
| 443 |
name='SMA 20',
|
| 444 |
line=dict(color='orange', dash='dash')
|
| 445 |
),
|