Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ from plotly.subplots import make_subplots
|
|
| 6 |
import numpy as np
|
| 7 |
import ast
|
| 8 |
from pagination import paginator
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
|
|
@@ -264,9 +265,11 @@ with news_analysis:
|
|
| 264 |
# Fill NaN values in the new columns with 0
|
| 265 |
events['Positive_Impacts'].fillna("", inplace=True)
|
| 266 |
events['Negative_Impacts'].fillna("", inplace=True)
|
|
|
|
|
|
|
| 267 |
# Create the line trace for stock prices
|
| 268 |
line_stock = go.Scatter(x=events['Date'], y=events['Price'], mode='lines', name='OGDCL Close Price',
|
| 269 |
-
line=dict(dash='solid', color=
|
| 270 |
# text=events['Cleaned_Headline'],
|
| 271 |
# hovertext=events['FeatureSentiment'],
|
| 272 |
customdata=events['Feature'],
|
|
@@ -276,31 +279,31 @@ with news_analysis:
|
|
| 276 |
)
|
| 277 |
# Create dummy traces for the legend
|
| 278 |
dummy_positive = go.Scatter(x=[None], y=[None], mode='lines', name='Positive Impacts',
|
| 279 |
-
marker=dict(color=
|
| 280 |
# visible='legendonly'
|
| 281 |
)
|
| 282 |
dummy_negative = go.Scatter(x=[None], y=[None], mode='lines', name='Negative Impacts',
|
| 283 |
-
marker=dict(color=
|
| 284 |
# visible='legendonly'
|
| 285 |
)
|
| 286 |
|
| 287 |
fontsize = 12
|
| 288 |
annotations = []
|
| 289 |
# Create annotations for the Positive points
|
| 290 |
-
for index, row in
|
| 291 |
annotation1 = dict(x=row['Date'], y=row['Price'], text = row['Positive_Impacts'],
|
| 292 |
showarrow=True, arrowhead=0, # arrowcolor='black',
|
| 293 |
ax=10, ay=-20, # Dynamic offset
|
| 294 |
-
font=dict(size=fontsize, color=
|
| 295 |
)
|
| 296 |
annotations.append(annotation1)
|
| 297 |
|
| 298 |
# Create annotations for the Negative points
|
| 299 |
-
for index, row in
|
| 300 |
annotation2 = dict(x=row['Date'], y=row['Price'], text = row['Negative_Impacts'],
|
| 301 |
-
showarrow=True, arrowhead=0, arrowcolor=
|
| 302 |
ax=10, ay=-20, # Dynamic offset
|
| 303 |
-
font=dict(size=fontsize, color=
|
| 304 |
)
|
| 305 |
annotations.append(annotation2)
|
| 306 |
|
|
@@ -382,7 +385,7 @@ with news_analysis:
|
|
| 382 |
print(dates, len(dates))
|
| 383 |
num_dates = len(dates)
|
| 384 |
items_per_page = min(num_dates, 5)
|
| 385 |
-
for i, date in paginator("Select Page Number", dates, items_per_page=items_per_page, on_sidebar=False):
|
| 386 |
st.write(f'<span style="font-size: large;"><b>Date:</b> <u>{date}</u></span>', unsafe_allow_html=True)
|
| 387 |
|
| 388 |
|
|
@@ -415,7 +418,7 @@ with news_analysis:
|
|
| 415 |
|
| 416 |
with trade_recs:
|
| 417 |
st.header("Trading Recommendations")
|
| 418 |
-
|
| 419 |
# Create the line trace for stock prices
|
| 420 |
# Dropdown for selecting the indicator
|
| 421 |
selected_indicator = st.selectbox("Indicator to Show", ['EMA 9', 'EMA 55', 'MACD', 'RSI'])
|
|
@@ -432,7 +435,7 @@ with trade_recs:
|
|
| 432 |
column = 'RSI_Signals'
|
| 433 |
hover_text = '%{x}<br>Close: %{y}<br> RSI_Signal: %{customdata}<br>'
|
| 434 |
line_stock = go.Scatter(x=events['Date'], y=events['Price'], mode='lines', name='OGDCL Close Price',
|
| 435 |
-
line=dict(dash='solid',color=
|
| 436 |
text=[column],
|
| 437 |
# hovertext=events['FeatureSentiment'],
|
| 438 |
customdata=events[column],
|
|
@@ -442,31 +445,31 @@ with trade_recs:
|
|
| 442 |
)
|
| 443 |
# Create dummy traces for the legend
|
| 444 |
dummy_positive = go.Scatter(x=[None], y=[None], mode='lines', name='Positive Impacts',
|
| 445 |
-
marker=dict(color=
|
| 446 |
# visible='legendonly'
|
| 447 |
)
|
| 448 |
dummy_negative = go.Scatter(x=[None], y=[None], mode='lines', name='Negative Impacts',
|
| 449 |
-
marker=dict(color=
|
| 450 |
# visible='legendonly'
|
| 451 |
)
|
| 452 |
|
| 453 |
fontsize = 12
|
| 454 |
annotations = []
|
| 455 |
# Create annotations for the Positive points
|
| 456 |
-
for index, row in
|
| 457 |
annotation1 = dict(x=row['Date'], y=row['Price'], text = row['Positive_Impacts'],
|
| 458 |
showarrow=True, arrowhead=0, # arrowcolor='black',
|
| 459 |
ax=10, ay=-20, # Dynamic offset
|
| 460 |
-
font=dict(size=fontsize, color=
|
| 461 |
)
|
| 462 |
annotations.append(annotation1)
|
| 463 |
|
| 464 |
# Create annotations for the Negative points
|
| 465 |
-
for index, row in
|
| 466 |
annotation2 = dict(x=row['Date'], y=row['Price'], text = row['Negative_Impacts'],
|
| 467 |
-
showarrow=True, arrowhead=0, arrowcolor=
|
| 468 |
ax=10, ay=-20, # Dynamic offset
|
| 469 |
-
font=dict(size=fontsize, color=
|
| 470 |
)
|
| 471 |
annotations.append(annotation2)
|
| 472 |
|
|
@@ -531,7 +534,25 @@ with trade_recs:
|
|
| 531 |
trade_recs = events[['Date', 'Trading_Recommendations']]
|
| 532 |
# Extract date component from the datetime column
|
| 533 |
trade_recs['Date'] = trade_recs['Date'].dt.date
|
| 534 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 535 |
|
| 536 |
with chat:
|
| 537 |
st.balloons()
|
|
|
|
| 6 |
import numpy as np
|
| 7 |
import ast
|
| 8 |
from pagination import paginator
|
| 9 |
+
import style as cs
|
| 10 |
|
| 11 |
|
| 12 |
|
|
|
|
| 265 |
# Fill NaN values in the new columns with 0
|
| 266 |
events['Positive_Impacts'].fillna("", inplace=True)
|
| 267 |
events['Negative_Impacts'].fillna("", inplace=True)
|
| 268 |
+
plot_sub_pos = events[events['Positive_Impacts']!='']
|
| 269 |
+
plot_sub_neg = events[events['Negative_Impacts']!='']
|
| 270 |
# Create the line trace for stock prices
|
| 271 |
line_stock = go.Scatter(x=events['Date'], y=events['Price'], mode='lines', name='OGDCL Close Price',
|
| 272 |
+
line=dict(dash='solid', color=cs.close_line_color, width=2),
|
| 273 |
# text=events['Cleaned_Headline'],
|
| 274 |
# hovertext=events['FeatureSentiment'],
|
| 275 |
customdata=events['Feature'],
|
|
|
|
| 279 |
)
|
| 280 |
# Create dummy traces for the legend
|
| 281 |
dummy_positive = go.Scatter(x=[None], y=[None], mode='lines', name='Positive Impacts',
|
| 282 |
+
marker=dict(color=cs.pos_impacts_color, size=15), showlegend=True,
|
| 283 |
# visible='legendonly'
|
| 284 |
)
|
| 285 |
dummy_negative = go.Scatter(x=[None], y=[None], mode='lines', name='Negative Impacts',
|
| 286 |
+
marker=dict(color=cs.neg_impacts_color, size=15), showlegend=True,
|
| 287 |
# visible='legendonly'
|
| 288 |
)
|
| 289 |
|
| 290 |
fontsize = 12
|
| 291 |
annotations = []
|
| 292 |
# Create annotations for the Positive points
|
| 293 |
+
for index, row in plot_sub_pos.iterrows():
|
| 294 |
annotation1 = dict(x=row['Date'], y=row['Price'], text = row['Positive_Impacts'],
|
| 295 |
showarrow=True, arrowhead=0, # arrowcolor='black',
|
| 296 |
ax=10, ay=-20, # Dynamic offset
|
| 297 |
+
font=dict(size=fontsize, color=cs.pos_impacts_color),
|
| 298 |
)
|
| 299 |
annotations.append(annotation1)
|
| 300 |
|
| 301 |
# Create annotations for the Negative points
|
| 302 |
+
for index, row in plot_sub_neg.iterrows():
|
| 303 |
annotation2 = dict(x=row['Date'], y=row['Price'], text = row['Negative_Impacts'],
|
| 304 |
+
showarrow=True, arrowhead=0, arrowcolor=cs.close_line_color,
|
| 305 |
ax=10, ay=-20, # Dynamic offset
|
| 306 |
+
font=dict(size=fontsize, color=cs.neg_impacts_color),
|
| 307 |
)
|
| 308 |
annotations.append(annotation2)
|
| 309 |
|
|
|
|
| 385 |
print(dates, len(dates))
|
| 386 |
num_dates = len(dates)
|
| 387 |
items_per_page = min(num_dates, 5)
|
| 388 |
+
for i, date in paginator("Select Page Number", dates, items_per_page=items_per_page, on_sidebar=False, ukey='news_pages'):
|
| 389 |
st.write(f'<span style="font-size: large;"><b>Date:</b> <u>{date}</u></span>', unsafe_allow_html=True)
|
| 390 |
|
| 391 |
|
|
|
|
| 418 |
|
| 419 |
with trade_recs:
|
| 420 |
st.header("Trading Recommendations")
|
| 421 |
+
|
| 422 |
# Create the line trace for stock prices
|
| 423 |
# Dropdown for selecting the indicator
|
| 424 |
selected_indicator = st.selectbox("Indicator to Show", ['EMA 9', 'EMA 55', 'MACD', 'RSI'])
|
|
|
|
| 435 |
column = 'RSI_Signals'
|
| 436 |
hover_text = '%{x}<br>Close: %{y}<br> RSI_Signal: %{customdata}<br>'
|
| 437 |
line_stock = go.Scatter(x=events['Date'], y=events['Price'], mode='lines', name='OGDCL Close Price',
|
| 438 |
+
line=dict(dash='solid',color=cs.close_line_color, width=2), # color='royalblue'
|
| 439 |
text=[column],
|
| 440 |
# hovertext=events['FeatureSentiment'],
|
| 441 |
customdata=events[column],
|
|
|
|
| 445 |
)
|
| 446 |
# Create dummy traces for the legend
|
| 447 |
dummy_positive = go.Scatter(x=[None], y=[None], mode='lines', name='Positive Impacts',
|
| 448 |
+
marker=dict(color=cs.pos_impacts_color, size=15), showlegend=True,
|
| 449 |
# visible='legendonly'
|
| 450 |
)
|
| 451 |
dummy_negative = go.Scatter(x=[None], y=[None], mode='lines', name='Negative Impacts',
|
| 452 |
+
marker=dict(color=cs.neg_impacts_color, size=15), showlegend=True,
|
| 453 |
# visible='legendonly'
|
| 454 |
)
|
| 455 |
|
| 456 |
fontsize = 12
|
| 457 |
annotations = []
|
| 458 |
# Create annotations for the Positive points
|
| 459 |
+
for index, row in plot_sub_pos.iterrows():
|
| 460 |
annotation1 = dict(x=row['Date'], y=row['Price'], text = row['Positive_Impacts'],
|
| 461 |
showarrow=True, arrowhead=0, # arrowcolor='black',
|
| 462 |
ax=10, ay=-20, # Dynamic offset
|
| 463 |
+
font=dict(size=fontsize, color=cs.pos_impacts_color),
|
| 464 |
)
|
| 465 |
annotations.append(annotation1)
|
| 466 |
|
| 467 |
# Create annotations for the Negative points
|
| 468 |
+
for index, row in plot_sub_neg.iterrows():
|
| 469 |
annotation2 = dict(x=row['Date'], y=row['Price'], text = row['Negative_Impacts'],
|
| 470 |
+
showarrow=True, arrowhead=0, arrowcolor=cs.close_line_color,
|
| 471 |
ax=10, ay=-20, # Dynamic offset
|
| 472 |
+
font=dict(size=fontsize, color=cs.neg_impacts_color),
|
| 473 |
)
|
| 474 |
annotations.append(annotation2)
|
| 475 |
|
|
|
|
| 534 |
trade_recs = events[['Date', 'Trading_Recommendations']]
|
| 535 |
# Extract date component from the datetime column
|
| 536 |
trade_recs['Date'] = trade_recs['Date'].dt.date
|
| 537 |
+
# Convert back to Dictionaries from strings
|
| 538 |
+
trade_recs['Trading_Recommendations'] = trade_recs['Trading_Recommendations'].apply(convert_str_to_list)
|
| 539 |
+
dates = list(trade_recs['Date'].unique())
|
| 540 |
+
dates = np.sort(dates)
|
| 541 |
+
# Reverse the array to have the latest date at index 0
|
| 542 |
+
dates = dates[::-1]
|
| 543 |
+
num_dates = len(dates)
|
| 544 |
+
items_per_page = min(num_dates, 5)
|
| 545 |
+
for i, date in paginator("Select Page Number", dates, items_per_page=items_per_page, on_sidebar=False, ukey='trade_pages'):
|
| 546 |
+
st.write(f'<span style="font-size: large;"><b>Date:</b> <u>{date}</u></span>', unsafe_allow_html=True)
|
| 547 |
+
|
| 548 |
+
filtered_trades = trade_recs[trade_recs['Date'] == date]
|
| 549 |
+
filtered_trades.reset_index(inplace=True)
|
| 550 |
+
rec = filtered_trades['Trading_Recommendations'][0]
|
| 551 |
+
print(type(rec), rec)
|
| 552 |
+
trade_container = st.container(border=False)
|
| 553 |
+
trade_container.write(rec)
|
| 554 |
+
|
| 555 |
+
# st.write(trade_recs)
|
| 556 |
|
| 557 |
with chat:
|
| 558 |
st.balloons()
|