Akshayram1 commited on
Commit
fe775f1
1 Parent(s): a7d0af8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -19
app.py CHANGED
@@ -108,38 +108,64 @@ def score_news(parsed_news_df):
108
 
109
  return parsed_and_scored_news
110
 
111
- def plot_hourly_sentiment(parsed_and_scored_news, ticker):
112
  mean_scores = parsed_and_scored_news['sentiment_score'].resample('h').mean()
 
113
 
114
- fig = px.bar(mean_scores, x=mean_scores.index, y='sentiment_score',
115
  title=f'{ticker} Hourly Sentiment Scores',
116
  color='sentiment_score',
117
  color_continuous_scale=['red', 'yellow', 'green'],
118
  range_color=[-1, 1])
119
-
120
- fig.update_layout(coloraxis_colorbar=dict(
121
- title="Sentiment",
122
- tickvals=[-1, 0, 1],
123
- ticktext=["Negative", "Neutral", "Positive"],
124
- ))
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
  return fig
127
 
128
- def plot_daily_sentiment(parsed_and_scored_news, ticker):
129
  mean_scores = parsed_and_scored_news['sentiment_score'].resample('D').mean()
130
-
 
131
  fig = px.bar(mean_scores, x=mean_scores.index, y='sentiment_score',
132
  title=f'{ticker} Daily Sentiment Scores',
133
  color='sentiment_score',
134
  color_continuous_scale=['red', 'yellow', 'green'],
135
  range_color=[-1, 1])
136
-
137
- fig.update_layout(coloraxis_colorbar=dict(
138
- title="Sentiment",
139
- tickvals=[-1, 0, 1],
140
- ticktext=["Negative", "Neutral", "Positive"],
141
- ))
142
-
 
 
 
 
 
 
 
 
 
 
 
 
143
  return fig
144
 
145
  def get_recommendation(sentiment_scores):
@@ -170,8 +196,8 @@ try:
170
  # Display a disclaimer
171
  st.warning("Disclaimer: This recommendation is based solely on recent news sentiment and should not be considered as financial advice. Always do your own research and consult with a qualified financial advisor before making investment decisions.")
172
 
173
- fig_hourly = plot_hourly_sentiment(parsed_and_scored_news, ticker)
174
- fig_daily = plot_daily_sentiment(parsed_and_scored_news, ticker)
175
 
176
  st.plotly_chart(fig_hourly)
177
  st.plotly_chart(fig_daily)
 
108
 
109
  return parsed_and_scored_news
110
 
111
+ def plot_hourly_sentiment_with_confidence(parsed_and_scored_news, ticker):
112
  mean_scores = parsed_and_scored_news['sentiment_score'].resample('h').mean()
113
+ mean_confidence = parsed_and_scored_news['confidence'].resample('h').mean()
114
 
115
+ fig = px.bar(mean_scores, x=mean_scores.index, y='sentiment_score',
116
  title=f'{ticker} Hourly Sentiment Scores',
117
  color='sentiment_score',
118
  color_continuous_scale=['red', 'yellow', 'green'],
119
  range_color=[-1, 1])
120
+
121
+ fig.add_scatter(x=mean_confidence.index, y=mean_confidence,
122
+ mode='lines', name='Confidence Score',
123
+ line=dict(color='blue', width=2), yaxis='y2')
124
+
125
+ fig.update_layout(
126
+ yaxis2=dict(
127
+ title="Confidence Score",
128
+ overlaying='y',
129
+ side='right',
130
+ range=[0, 1]
131
+ ),
132
+ coloraxis_colorbar=dict(
133
+ title="Sentiment",
134
+ tickvals=[-1, 0, 1],
135
+ ticktext=["Negative", "Neutral", "Positive"],
136
+ )
137
+ )
138
 
139
  return fig
140
 
141
+ def plot_daily_sentiment_with_confidence(parsed_and_scored_news, ticker):
142
  mean_scores = parsed_and_scored_news['sentiment_score'].resample('D').mean()
143
+ mean_confidence = parsed_and_scored_news['confidence'].resample('D').mean()
144
+
145
  fig = px.bar(mean_scores, x=mean_scores.index, y='sentiment_score',
146
  title=f'{ticker} Daily Sentiment Scores',
147
  color='sentiment_score',
148
  color_continuous_scale=['red', 'yellow', 'green'],
149
  range_color=[-1, 1])
150
+
151
+ fig.add_scatter(x=mean_confidence.index, y=mean_confidence,
152
+ mode='lines', name='Confidence Score',
153
+ line=dict(color='blue', width=2), yaxis='y2')
154
+
155
+ fig.update_layout(
156
+ yaxis2=dict(
157
+ title="Confidence Score",
158
+ overlaying='y',
159
+ side='right',
160
+ range=[0, 1]
161
+ ),
162
+ coloraxis_colorbar=dict(
163
+ title="Sentiment",
164
+ tickvals=[-1, 0, 1],
165
+ ticktext=["Negative", "Neutral", "Positive"],
166
+ )
167
+ )
168
+
169
  return fig
170
 
171
  def get_recommendation(sentiment_scores):
 
196
  # Display a disclaimer
197
  st.warning("Disclaimer: This recommendation is based solely on recent news sentiment and should not be considered as financial advice. Always do your own research and consult with a qualified financial advisor before making investment decisions.")
198
 
199
+ fig_hourly = plot_hourly_sentiment_with_confidence(parsed_and_scored_news, ticker)
200
+ fig_daily = plot_daily_sentiment_with_confidence(parsed_and_scored_news, ticker)
201
 
202
  st.plotly_chart(fig_hourly)
203
  st.plotly_chart(fig_daily)