Nazhar commited on
Commit
738d3a3
·
verified ·
1 Parent(s): ce24902

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +155 -150
app.py CHANGED
@@ -86,17 +86,18 @@ date_limit = pd.to_datetime('2021-08-12') # Set date limit for end date picker
86
 
87
 
88
  # Create Tabs
89
- market_analysis, news_analysis, trade_recs, final_recs, chat = st.tabs(["Market Analysis", "News Analysis", "Trading Recommendations", "GenAI Recommendations","AI Stock Advisor"])
90
 
91
  with market_analysis:
92
  st.header("Market Analysis")
93
  st.write("This module provides market analysis for the following day based on the selected current date.")
94
- date_container = st.container(height = 90, border=False)
95
  # main_container.write(f"Date: {date}")
96
 
97
  col1, col2 = date_container.columns([0.5, 0.5], gap='medium')
98
- start_date = col1.date_input('Start Date', value=default_start_date, min_value=data['Date'].min(), max_value=date_limit)
99
- end_date = col2.date_input("Current Date", value=date_limit, min_value=data['Date'].min(), max_value=date_limit)
 
100
  start_date = pd.to_datetime(start_date)
101
  end_date = pd.to_datetime(end_date)
102
  data2 = data[data['Date'].between(start_date, end_date)]
@@ -457,121 +458,154 @@ with news_analysis:
457
  with st.expander("Oil Sector Features"):
458
  st.write(set(features))
459
 
460
- with trade_recs:
461
- st.header("Trading Recommendations")
462
-
463
- # Create the line trace for stock prices
464
- # Dropdown for selecting the indicator
465
- selected_indicator = st.selectbox("Indicator to Show", ['EMA 9', 'EMA 55', 'MACD', 'RSI'])
466
- if selected_indicator == 'EMA 9':
467
- column = 'EMA9_Signal'
468
- hover_text = '%{x}<br>Close: %{y}<br> EMA9_Signal: %{customdata}<br>'
469
- elif selected_indicator == 'EMA 55':
470
- column = 'EMA55_Signal'
471
- hover_text = '%{x}<br>Close: %{y}<br> EMA55_Signal: %{customdata}<br>'
472
- elif selected_indicator == 'MACD':
473
- column = 'MACD_Signals'
474
- hover_text = '%{x}<br>Close: %{y}<br> MACD_Signal: %{customdata}<br>'
475
- elif selected_indicator == 'RSI':
476
- column = 'RSI_Signals'
477
- hover_text = '%{x}<br>Close: %{y}<br> RSI_Signal: %{customdata}<br>'
478
- line_stock = go.Scatter(x=events['Date'], y=events['Price'], mode='lines', name='OGDCL Close Price',
479
- line=dict(dash='solid',color=cs.close_line_color, width=2), # color='royalblue'
480
- text=[column],
481
- # hovertext=events['FeatureSentiment'],
482
- customdata=events[column],
483
- hovertemplate=hover_text,
484
- # hoverlabel=dict(font=dict(color=events
485
- # ['FeatureSentiment'].apply(lambda x: 'red' if x == 'Negative' else 'blue' if x == 'Neutral' else 'green'))), # Customize the line style, color, and width
486
- )
487
- # Create dummy traces for the legend
488
- dummy_positive = go.Scatter(x=[None], y=[None], mode='lines', name='Positive Impacts',
489
- marker=dict(color=cs.pos_impacts_color, size=15), showlegend=True,
490
- # visible='legendonly'
491
- )
492
- dummy_negative = go.Scatter(x=[None], y=[None], mode='lines', name='Negative Impacts',
493
- marker=dict(color=cs.neg_impacts_color, size=15), showlegend=True,
494
- # visible='legendonly'
495
- )
496
-
497
- fontsize = 12
498
- annotations = []
499
- # Create annotations for the Positive points
500
- for index, row in plot_sub_pos.iterrows():
501
- annotation1 = dict(x=row['Date'], y=row['Price'], text = row['Positive_Impacts'],
502
- showarrow=True, arrowhead=0, # arrowcolor='black',
503
- ax=10, ay=-20, # Dynamic offset
504
- font=dict(size=fontsize, color=cs.pos_impacts_color),
505
- )
506
- annotations.append(annotation1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
507
 
508
- # Create annotations for the Negative points
509
- for index, row in plot_sub_neg.iterrows():
510
- annotation2 = dict(x=row['Date'], y=row['Price'], text = row['Negative_Impacts'],
511
- showarrow=True, arrowhead=0, arrowcolor=cs.close_line_color,
512
- ax=10, ay=-20, # Dynamic offset
513
- font=dict(size=fontsize, color=cs.neg_impacts_color),
514
- )
515
- annotations.append(annotation2)
516
 
517
- # Create the layout
518
- title = 'OGDCL Close Price w.r.t. News Impacts'
519
- layout = go.Layout(
520
- title=title,
521
- xaxis=dict(
522
- title='Date',
523
- tickformat='%b %d, %Y',
524
- # gridcolor='lightgray',
525
- range=[start_date, end_date],
526
- # tickvals=list(range(dateA, dateB, 3)),
527
- ),
528
- yaxis=dict(
529
- title='OGDCL Close Price',
530
- # gridcolor='lightgray',
531
- range=[90, 120],
532
- tickvals=list(range(90, 120, 5)),
533
- ),
534
- # plot_bgcolor='rgba(245, 245, 245, 0.8)',
535
- # paper_bgcolor='white',
536
- # hoverlabel=dict(
537
- # bgcolor='white',
538
- # font=dict(color='black'),
539
- # ),
540
- annotations=annotations,
541
- )
542
 
543
- # Add all traces to the figure
544
- figure = go.Figure(data=[line_stock, dummy_negative, dummy_positive], layout=layout)
545
- # figure.update_traces(mode="markers+lines")
546
- figure.update_layout(
547
- title={
548
- 'text': title,
549
- 'x': 0.5,
550
- 'y': 0.95,
551
- 'xanchor': 'center',
552
- 'yanchor': 'top',
553
- 'font': dict(size=12),
554
- },
555
- hovermode='closest',
556
- margin=dict(l=40, r=40, t=80, b=40),
557
- )
558
- figure.update_xaxes(
559
- rangeslider_visible=True,
560
- rangeselector=dict(
561
- buttons=list([
562
- dict(count=1, label="1m", step="month", stepmode="backward"),
563
- dict(count=6, label="6m", step="month", stepmode="backward"),
564
- dict(count=1, label="YTD", step="year", stepmode="todate"),
565
- dict(count=1, label="1y", step="year", stepmode="backward"),
566
- dict(step="all")
567
- ])
568
- )
569
- )
570
- st.plotly_chart(figure)
571
  if 'Trading_Recommendations\r' in events.columns:
572
  events.rename(columns={'Trading_Recommendations\r': 'Trading_Recommendations'}, inplace=True)
573
 
574
- print(events.columns)
575
  trade_recs = events[['Date', 'Trading_Recommendations']]
576
  # Extract date component from the datetime column
577
  trade_recs['Date'] = trade_recs['Date'].dt.date
@@ -582,22 +616,14 @@ with trade_recs:
582
  # Reverse the array to have the latest date at index 0
583
  dates = dates[::-1]
584
  num_dates = len(dates)
585
- items_per_page = min(num_dates, 5)
586
- for i, date in paginator("Select Page Number", dates, items_per_page=items_per_page, on_sidebar=False, ukey='trade_pages'):
587
- st.write(f'<span style="font-size: large;"><b>Date:</b> <u>{date}</u></span>', unsafe_allow_html=True)
588
-
589
- filtered_trades = trade_recs[trade_recs['Date'] == date]
590
- filtered_trades.reset_index(inplace=True)
591
- rec = filtered_trades['Trading_Recommendations'][0]
592
- print(type(rec), rec)
593
- trade_container = st.container(border=False)
594
- trade_container.write(rec)
595
-
596
- # st.write(trade_recs)
597
-
598
- with final_recs:
599
- st.header("GenAI Recommendations")
600
- st.write("This module provides trading recommendation for the following day based on the selected current date.")
601
 
602
  # Create the line trace for stock prices
603
  line_stock = go.Scatter(x=events['Date'], y=events['Price'], mode='lines', name='OGDCL Close Price',
@@ -694,28 +720,7 @@ with final_recs:
694
  )
695
  )
696
  st.plotly_chart(figure)
697
- if 'Trading_Recommendations\r' in events.columns:
698
- events.rename(columns={'Trading_Recommendations\r': 'Trading_Recommendations'}, inplace=True)
699
 
700
- print(events.columns)
701
- trade_recs = events[['Date', 'Trading_Recommendations']]
702
- # Extract date component from the datetime column
703
- trade_recs['Date'] = trade_recs['Date'].dt.date
704
- # Convert back to Dictionaries from strings
705
- trade_recs['Trading_Recommendations'] = trade_recs['Trading_Recommendations'].apply(convert_str_to_list)
706
- dates = list(trade_recs['Date'].unique())
707
- dates = np.sort(dates)
708
- # Reverse the array to have the latest date at index 0
709
- dates = dates[::-1]
710
- num_dates = len(dates)
711
- st.subheader("GenAI Recommendations")
712
- genrec_container = st.container(border=False)
713
- role = genrec_container.radio(
714
- "Get your recommendation summary as:",
715
- ["Trader", "Equity Analyst"], horizontal=True)
716
-
717
- genrec = 'Recommendation for following day will go here.'
718
- genrec_container.write(genrec)
719
 
720
 
721
  with chat:
 
86
 
87
 
88
  # Create Tabs
89
+ market_analysis, news_analysis, final_recs, chat = st.tabs(["Market Analysis", "News Analysis", "GenAI Recommendations","AI Stock Advisor"])
90
 
91
  with market_analysis:
92
  st.header("Market Analysis")
93
  st.write("This module provides market analysis for the following day based on the selected current date.")
94
+ date_container = st.container(border=False)
95
  # main_container.write(f"Date: {date}")
96
 
97
  col1, col2 = date_container.columns([0.5, 0.5], gap='medium')
98
+ # start_date = col1.date_input('Start Date', value=default_start_date, min_value=data['Date'].min(), max_value=date_limit)
99
+ end_date = col1.date_input("Current Date", value=date_limit, min_value=data['Date'].min(), max_value=date_limit)
100
+ start_date = data['Date'].min()
101
  start_date = pd.to_datetime(start_date)
102
  end_date = pd.to_datetime(end_date)
103
  data2 = data[data['Date'].between(start_date, end_date)]
 
458
  with st.expander("Oil Sector Features"):
459
  st.write(set(features))
460
 
461
+ # with trade_recs:
462
+ # st.header("Trading Recommendations")
463
+
464
+ # # Create the line trace for stock prices
465
+ # # Dropdown for selecting the indicator
466
+ # selected_indicator = st.selectbox("Indicator to Show", ['EMA 9', 'EMA 55', 'MACD', 'RSI'])
467
+ # if selected_indicator == 'EMA 9':
468
+ # column = 'EMA9_Signal'
469
+ # hover_text = '%{x}<br>Close: %{y}<br> EMA9_Signal: %{customdata}<br>'
470
+ # elif selected_indicator == 'EMA 55':
471
+ # column = 'EMA55_Signal'
472
+ # hover_text = '%{x}<br>Close: %{y}<br> EMA55_Signal: %{customdata}<br>'
473
+ # elif selected_indicator == 'MACD':
474
+ # column = 'MACD_Signals'
475
+ # hover_text = '%{x}<br>Close: %{y}<br> MACD_Signal: %{customdata}<br>'
476
+ # elif selected_indicator == 'RSI':
477
+ # column = 'RSI_Signals'
478
+ # hover_text = '%{x}<br>Close: %{y}<br> RSI_Signal: %{customdata}<br>'
479
+ # line_stock = go.Scatter(x=events['Date'], y=events['Price'], mode='lines', name='OGDCL Close Price',
480
+ # line=dict(dash='solid',color=cs.close_line_color, width=2), # color='royalblue'
481
+ # text=[column],
482
+ # # hovertext=events['FeatureSentiment'],
483
+ # customdata=events[column],
484
+ # hovertemplate=hover_text,
485
+ # # hoverlabel=dict(font=dict(color=events
486
+ # # ['FeatureSentiment'].apply(lambda x: 'red' if x == 'Negative' else 'blue' if x == 'Neutral' else 'green'))), # Customize the line style, color, and width
487
+ # )
488
+ # # Create dummy traces for the legend
489
+ # dummy_positive = go.Scatter(x=[None], y=[None], mode='lines', name='Positive Impacts',
490
+ # marker=dict(color=cs.pos_impacts_color, size=15), showlegend=True,
491
+ # # visible='legendonly'
492
+ # )
493
+ # dummy_negative = go.Scatter(x=[None], y=[None], mode='lines', name='Negative Impacts',
494
+ # marker=dict(color=cs.neg_impacts_color, size=15), showlegend=True,
495
+ # # visible='legendonly'
496
+ # )
497
+
498
+ # fontsize = 12
499
+ # annotations = []
500
+ # # Create annotations for the Positive points
501
+ # for index, row in plot_sub_pos.iterrows():
502
+ # annotation1 = dict(x=row['Date'], y=row['Price'], text = row['Positive_Impacts'],
503
+ # showarrow=True, arrowhead=0, # arrowcolor='black',
504
+ # ax=10, ay=-20, # Dynamic offset
505
+ # font=dict(size=fontsize, color=cs.pos_impacts_color),
506
+ # )
507
+ # annotations.append(annotation1)
508
+
509
+ # # Create annotations for the Negative points
510
+ # for index, row in plot_sub_neg.iterrows():
511
+ # annotation2 = dict(x=row['Date'], y=row['Price'], text = row['Negative_Impacts'],
512
+ # showarrow=True, arrowhead=0, arrowcolor=cs.close_line_color,
513
+ # ax=10, ay=-20, # Dynamic offset
514
+ # font=dict(size=fontsize, color=cs.neg_impacts_color),
515
+ # )
516
+ # annotations.append(annotation2)
517
+
518
+ # # Create the layout
519
+ # title = 'OGDCL Close Price w.r.t. News Impacts'
520
+ # layout = go.Layout(
521
+ # title=title,
522
+ # xaxis=dict(
523
+ # title='Date',
524
+ # tickformat='%b %d, %Y',
525
+ # # gridcolor='lightgray',
526
+ # range=[start_date, end_date],
527
+ # # tickvals=list(range(dateA, dateB, 3)),
528
+ # ),
529
+ # yaxis=dict(
530
+ # title='OGDCL Close Price',
531
+ # # gridcolor='lightgray',
532
+ # range=[90, 120],
533
+ # tickvals=list(range(90, 120, 5)),
534
+ # ),
535
+ # # plot_bgcolor='rgba(245, 245, 245, 0.8)',
536
+ # # paper_bgcolor='white',
537
+ # # hoverlabel=dict(
538
+ # # bgcolor='white',
539
+ # # font=dict(color='black'),
540
+ # # ),
541
+ # annotations=annotations,
542
+ # )
543
+
544
+ # # Add all traces to the figure
545
+ # figure = go.Figure(data=[line_stock, dummy_negative, dummy_positive], layout=layout)
546
+ # # figure.update_traces(mode="markers+lines")
547
+ # figure.update_layout(
548
+ # title={
549
+ # 'text': title,
550
+ # 'x': 0.5,
551
+ # 'y': 0.95,
552
+ # 'xanchor': 'center',
553
+ # 'yanchor': 'top',
554
+ # 'font': dict(size=12),
555
+ # },
556
+ # hovermode='closest',
557
+ # margin=dict(l=40, r=40, t=80, b=40),
558
+ # )
559
+ # figure.update_xaxes(
560
+ # rangeslider_visible=True,
561
+ # rangeselector=dict(
562
+ # buttons=list([
563
+ # dict(count=1, label="1m", step="month", stepmode="backward"),
564
+ # dict(count=6, label="6m", step="month", stepmode="backward"),
565
+ # dict(count=1, label="YTD", step="year", stepmode="todate"),
566
+ # dict(count=1, label="1y", step="year", stepmode="backward"),
567
+ # dict(step="all")
568
+ # ])
569
+ # )
570
+ # )
571
+ # st.plotly_chart(figure)
572
+ # if 'Trading_Recommendations\r' in events.columns:
573
+ # events.rename(columns={'Trading_Recommendations\r': 'Trading_Recommendations'}, inplace=True)
574
+
575
+ # print(events.columns)
576
+ # trade_recs = events[['Date', 'Trading_Recommendations']]
577
+ # # Extract date component from the datetime column
578
+ # trade_recs['Date'] = trade_recs['Date'].dt.date
579
+ # # Convert back to Dictionaries from strings
580
+ # trade_recs['Trading_Recommendations'] = trade_recs['Trading_Recommendations'].apply(convert_str_to_list)
581
+ # dates = list(trade_recs['Date'].unique())
582
+ # dates = np.sort(dates)
583
+ # # Reverse the array to have the latest date at index 0
584
+ # dates = dates[::-1]
585
+ # num_dates = len(dates)
586
+ # items_per_page = min(num_dates, 5)
587
+ # for i, date in paginator("Select Page Number", dates, items_per_page=items_per_page, on_sidebar=False, ukey='trade_pages'):
588
+ # st.write(f'<span style="font-size: large;"><b>Date:</b> <u>{date}</u></span>', unsafe_allow_html=True)
589
+
590
+ # filtered_trades = trade_recs[trade_recs['Date'] == date]
591
+ # filtered_trades.reset_index(inplace=True)
592
+ # rec = filtered_trades['Trading_Recommendations'][0]
593
+ # print(type(rec), rec)
594
+ # trade_container = st.container(border=False)
595
+ # trade_container.write(rec)
596
+
597
+ # # st.write(trade_recs)
598
+
599
 
 
 
 
 
 
 
 
 
600
 
601
+ with final_recs:
602
+ st.header("GenAI Recommendations")
603
+ st.write("This module provides trading recommendation for the following day based on the selected current date.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
604
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
605
  if 'Trading_Recommendations\r' in events.columns:
606
  events.rename(columns={'Trading_Recommendations\r': 'Trading_Recommendations'}, inplace=True)
607
 
608
+ # print(events.columns)
609
  trade_recs = events[['Date', 'Trading_Recommendations']]
610
  # Extract date component from the datetime column
611
  trade_recs['Date'] = trade_recs['Date'].dt.date
 
616
  # Reverse the array to have the latest date at index 0
617
  dates = dates[::-1]
618
  num_dates = len(dates)
619
+ st.subheader("GenAI Recommendations")
620
+ genrec_container = st.container(border=False)
621
+ role = genrec_container.radio(
622
+ "Get your recommendation summary as:",
623
+ ["Trader", "Equity Analyst"], horizontal=True)
624
+
625
+ genrec = 'Recommendation for following day will go here.'
626
+ genrec_container.write(genrec)
 
 
 
 
 
 
 
 
627
 
628
  # Create the line trace for stock prices
629
  line_stock = go.Scatter(x=events['Date'], y=events['Price'], mode='lines', name='OGDCL Close Price',
 
720
  )
721
  )
722
  st.plotly_chart(figure)
 
 
723
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
724
 
725
 
726
  with chat: