Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -584,74 +584,64 @@ with final_recs:
|
|
| 584 |
st.write("""This module provides trading recommendation for the following day based on the current date.
|
| 585 |
For demo purpose this is restricted to test data from (Aug 12, 2021- Aug 31,2021).
|
| 586 |
The results shown here are based on our model's inference on this test data, which is available in the Colab Notebook.
|
| 587 |
-
Real time recommendation
|
|
|
|
| 588 |
|
| 589 |
-
|
| 590 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 591 |
|
| 592 |
# print(events.columns)
|
| 593 |
-
|
| 594 |
-
# Extract date component from the datetime column
|
| 595 |
-
trade_recs['Date'] = trade_recs['Date'].dt.date
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
dates =
|
| 599 |
-
|
| 600 |
-
#
|
| 601 |
-
|
| 602 |
-
num_dates = len(dates)
|
| 603 |
# st.subheader("GenAI Recommendations")
|
| 604 |
genrec_container = st.container(border=False)
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
genrec = 'Recommendation for following day will go here.'
|
| 610 |
-
genrec_container.write(genrec)
|
| 611 |
|
| 612 |
-
|
| 613 |
line_stock = go.Scatter(x=events['Date'], y=events['Price'], mode='lines', name='OGDCL Close Price',
|
| 614 |
-
line=dict(dash='solid',color=cs.close_line_color, width=2),
|
| 615 |
-
text=events['
|
| 616 |
-
hovertext=events['
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
hovertemplate='%{x}<br>Close: %{y}<br> EMA9_Signal: %{text}<br>EMA55_Signal: %{hovertext}<br> RSI_Signal: %{meta}<br>MACD_Signal: %{customdata}<br>',
|
| 620 |
# hoverlabel=dict(font=dict(color=events
|
| 621 |
# ['FeatureSentiment'].apply(lambda x: 'red' if x == 'Negative' else 'blue' if x == 'Neutral' else 'green'))), # Customize the line style, color, and width
|
| 622 |
)
|
| 623 |
-
|
| 624 |
-
dummy_positive = go.Scatter(x=[None], y=[None], mode='lines', name='Positive Impacts',
|
| 625 |
-
marker=dict(color=cs.pos_impacts_color, size=15), showlegend=True,
|
| 626 |
-
# visible='legendonly'
|
| 627 |
-
)
|
| 628 |
-
dummy_negative = go.Scatter(x=[None], y=[None], mode='lines', name='Negative Impacts',
|
| 629 |
-
marker=dict(color=cs.neg_impacts_color, size=15), showlegend=True,
|
| 630 |
-
# visible='legendonly'
|
| 631 |
-
)
|
| 632 |
-
|
| 633 |
-
fontsize = 12
|
| 634 |
-
annotations = []
|
| 635 |
-
# Create annotations for the Positive points
|
| 636 |
-
for index, row in plot_sub_pos.iterrows():
|
| 637 |
-
annotation1 = dict(x=row['Date'], y=row['Price'], text = row['Positive_Impacts'],
|
| 638 |
-
showarrow=True, arrowhead=0, # arrowcolor='black',
|
| 639 |
-
ax=10, ay=-20, # Dynamic offset
|
| 640 |
-
font=dict(size=fontsize, color=cs.pos_impacts_color),
|
| 641 |
-
)
|
| 642 |
-
annotations.append(annotation1)
|
| 643 |
-
|
| 644 |
-
# Create annotations for the Negative points
|
| 645 |
-
for index, row in plot_sub_neg.iterrows():
|
| 646 |
-
annotation2 = dict(x=row['Date'], y=row['Price'], text = row['Negative_Impacts'],
|
| 647 |
-
showarrow=True, arrowhead=0, arrowcolor=cs.close_line_color,
|
| 648 |
-
ax=10, ay=-20, # Dynamic offset
|
| 649 |
-
font=dict(size=fontsize, color=cs.neg_impacts_color),
|
| 650 |
-
)
|
| 651 |
-
annotations.append(annotation2)
|
| 652 |
-
|
| 653 |
-
# Create the layout
|
| 654 |
-
title = 'OGDCL Close Price w.r.t. News Impacts'
|
| 655 |
layout = go.Layout(
|
| 656 |
title=title,
|
| 657 |
xaxis=dict(
|
|
@@ -662,23 +652,21 @@ with final_recs:
|
|
| 662 |
# tickvals=list(range(dateA, dateB, 3)),
|
| 663 |
),
|
| 664 |
yaxis=dict(
|
| 665 |
-
title='
|
| 666 |
# gridcolor='lightgray',
|
| 667 |
range=[90, 120],
|
| 668 |
tickvals=list(range(90, 120, 5)),
|
| 669 |
-
)
|
| 670 |
-
# plot_bgcolor='rgba(245, 245, 245, 0.8)',
|
| 671 |
-
# paper_bgcolor='white',
|
| 672 |
-
# hoverlabel=dict(
|
| 673 |
-
# bgcolor='white',
|
| 674 |
-
# font=dict(color='black'),
|
| 675 |
-
# ),
|
| 676 |
-
annotations=annotations,
|
| 677 |
)
|
| 678 |
|
| 679 |
# Add all traces to the figure
|
| 680 |
-
figure = go.Figure(data=[line_stock
|
| 681 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 682 |
figure.update_layout(
|
| 683 |
title={
|
| 684 |
'text': title,
|
|
@@ -690,6 +678,8 @@ with final_recs:
|
|
| 690 |
},
|
| 691 |
hovermode='closest',
|
| 692 |
margin=dict(l=40, r=40, t=80, b=40),
|
|
|
|
|
|
|
| 693 |
)
|
| 694 |
figure.update_xaxes(
|
| 695 |
rangeslider_visible=True,
|
|
@@ -703,6 +693,8 @@ with final_recs:
|
|
| 703 |
])
|
| 704 |
)
|
| 705 |
)
|
|
|
|
|
|
|
| 706 |
st.plotly_chart(figure)
|
| 707 |
|
| 708 |
|
|
|
|
| 584 |
st.write("""This module provides trading recommendation for the following day based on the current date.
|
| 585 |
For demo purpose this is restricted to test data from (Aug 12, 2021- Aug 31,2021).
|
| 586 |
The results shown here are based on our model's inference on this test data, which is available in the Colab Notebook.
|
| 587 |
+
Real time calls for recommendation to GenAI based model can be provided as and when required as we are using paid services
|
| 588 |
+
for model inference.""")
|
| 589 |
|
| 590 |
+
|
| 591 |
+
recs = pd.read_csv("test_recom.csv")
|
| 592 |
+
recs['Date'] = pd.to_datetime(recs['Date'])
|
| 593 |
+
recs['Date'] = recs['Date'].dt.date
|
| 594 |
+
rec_dates = np.sort(list(rec['Date'].unique()))
|
| 595 |
+
pred_date = st.selectbox("Pick the Test Date", rec_dates)
|
| 596 |
+
|
| 597 |
+
# date_value = pd.to_datetime('2021-08-12')
|
| 598 |
+
# pred_date = st.date_input("Pick Test Date", value=date_value, min_value=date_value, max_value=date_limit)
|
| 599 |
+
role = genrec_container.radio(
|
| 600 |
+
"Show recommendation summary as:",
|
| 601 |
+
["Active Trader", "Equity Analyst"], horizontal=True)
|
| 602 |
+
|
| 603 |
+
filter_recs = recs[recs['Date'] == pred_date]
|
| 604 |
+
if role == 'Active Trader':
|
| 605 |
+
trade_recs = filter_recs[['Date', 'Recommendations_Active_Trader']]
|
| 606 |
+
# Convert back to Dictionaries from strings
|
| 607 |
+
trade_recs['Recommendations_Active_Trader'] = trade_recs['Recommendations_Active_Trader'].apply(convert_str_to_list)
|
| 608 |
+
trade_recs.rename(columns={'Recommendations_Active_Trader': 'Recommendations'}, inplace=True)
|
| 609 |
+
elif role == 'Equity Analyst':
|
| 610 |
+
trade_recs = filter_recs[['Date', 'Recommendations_Equity_Analyst']]
|
| 611 |
+
# Convert back to Dictionaries from strings
|
| 612 |
+
trade_recs['Recommendations_Equity_Analyst'] = trade_recs['Recommendations_Equity_Analyst'].apply(convert_str_to_list)
|
| 613 |
+
trade_recs.rename(columns={'Recommendations_Equity_Analyst': 'Recommendations'}, inplace=True)
|
| 614 |
+
# if 'Trading_Recommendations\r' in events.columns:
|
| 615 |
+
# events.rename(columns={'Trading_Recommendations\r': 'Trading_Recommendations'}, inplace=True)
|
| 616 |
|
| 617 |
# print(events.columns)
|
| 618 |
+
|
| 619 |
+
# # Extract date component from the datetime column
|
| 620 |
+
# trade_recs['Date'] = trade_recs['Date'].dt.date
|
| 621 |
+
|
| 622 |
+
# dates = list(trade_recs['Date'].unique())
|
| 623 |
+
# dates = np.sort(dates)
|
| 624 |
+
# # Reverse the array to have the latest date at index 0
|
| 625 |
+
# dates = dates[::-1]
|
| 626 |
+
# num_dates = len(dates)
|
|
|
|
| 627 |
# st.subheader("GenAI Recommendations")
|
| 628 |
genrec_container = st.container(border=False)
|
| 629 |
+
genrec_container.write(f'<span style="font-size: large;"><b>Date:</b> <u>{pred_date}</u></span>', unsafe_allow_html=True)
|
| 630 |
+
|
| 631 |
+
# genrec = 'Recommendation for following day will go here.'
|
| 632 |
+
genrec_container.write(trade_recs['Recommendations'])
|
|
|
|
|
|
|
| 633 |
|
| 634 |
+
# Create the line trace for stock prices
|
| 635 |
line_stock = go.Scatter(x=events['Date'], y=events['Price'], mode='lines', name='OGDCL Close Price',
|
| 636 |
+
line=dict(dash='solid', color=cs.close_line_color, width=2),
|
| 637 |
+
# text=events['Cleaned_Headline'],
|
| 638 |
+
# hovertext=events['FeatureSentiment'],
|
| 639 |
+
customdata=events['Feature'],
|
| 640 |
+
hovertemplate='%{x}<br>Close: %{y}<br>Feature: %{customdata}<br>',
|
|
|
|
| 641 |
# hoverlabel=dict(font=dict(color=events
|
| 642 |
# ['FeatureSentiment'].apply(lambda x: 'red' if x == 'Negative' else 'blue' if x == 'Neutral' else 'green'))), # Customize the line style, color, and width
|
| 643 |
)
|
| 644 |
+
title = 'Market and News Analysis w.r.t. OGDCL Close Price'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 645 |
layout = go.Layout(
|
| 646 |
title=title,
|
| 647 |
xaxis=dict(
|
|
|
|
| 652 |
# tickvals=list(range(dateA, dateB, 3)),
|
| 653 |
),
|
| 654 |
yaxis=dict(
|
| 655 |
+
title='Price in Rs.',
|
| 656 |
# gridcolor='lightgray',
|
| 657 |
range=[90, 120],
|
| 658 |
tickvals=list(range(90, 120, 5)),
|
| 659 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 660 |
)
|
| 661 |
|
| 662 |
# Add all traces to the figure
|
| 663 |
+
figure = go.Figure(data=[line_stock], layout=layout)
|
| 664 |
+
figure.add_scatter(x=plot_sub_pos['Date'], y=plot_sub_pos['Price'], mode='markers',
|
| 665 |
+
marker=dict(symbol='triangle-up', size=10, color=cs.pos_impacts_color), name='Positive Impact',
|
| 666 |
+
customdata=events['Feature'], hovertemplate='%{x}<br>Close: %{y}<br>Feature: %{customdata}<br>')
|
| 667 |
+
figure.add_scatter(x=plot_sub_neg['Date'], y=plot_sub_neg['Price'], mode='markers',
|
| 668 |
+
marker=dict(symbol='triangle-down', size=10, color=cs.neg_impacts_color), name='Negative Impact',
|
| 669 |
+
customdata=events['Feature'], hovertemplate='%{x}<br>Close: %{y}<br>Feature: %{customdata}<br>',)
|
| 670 |
figure.update_layout(
|
| 671 |
title={
|
| 672 |
'text': title,
|
|
|
|
| 678 |
},
|
| 679 |
hovermode='closest',
|
| 680 |
margin=dict(l=40, r=40, t=80, b=40),
|
| 681 |
+
modebar_add="togglespikelines",
|
| 682 |
+
# scrollZoom=True,
|
| 683 |
)
|
| 684 |
figure.update_xaxes(
|
| 685 |
rangeslider_visible=True,
|
|
|
|
| 693 |
])
|
| 694 |
)
|
| 695 |
)
|
| 696 |
+
# Update y-axis to allow vertical scrolling and dragging
|
| 697 |
+
figure.update_yaxes(fixedrange=False)
|
| 698 |
st.plotly_chart(figure)
|
| 699 |
|
| 700 |
|