YaakovY commited on
Commit
5e9b196
1 Parent(s): 1141e89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -11
app.py CHANGED
@@ -10,8 +10,7 @@ url_stocks = "https://financialmodelingprep.com/api/v3/stock/list?apikey="
10
  url_sentiment = "https://yaakovy-fin-proj-docker.hf.space/ticker/"
11
  url_timeGpt = "https://ofirmatzlawi-fin-proj-docker-1.hf.space/ticker/"
12
  url_forecast_eod = "https://yaakovy-lasthourforcast.hf.space/ticker/"
13
-
14
-
15
 
16
  def get_max_sentiment(row):
17
  if row["sentiment_score"] > 0.05: # Threshold for positive sentiment
@@ -22,7 +21,6 @@ def get_max_sentiment(row):
22
  return "neutral"
23
 
24
 
25
-
26
  def get_sentiment_data(stock_info):
27
  symbol = stock_info.info['symbol']
28
  url_sentiment_with_ticker = f"{url_sentiment}{symbol}"
@@ -44,18 +42,29 @@ def print_sentiment(stock_info):
44
  return df
45
 
46
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  def get_eod_forecast(stock_info):
48
  symbol = stock_info.info['symbol']
49
  url_forecast_eod_with_ticker = f"{url_forecast_eod}{symbol}"
50
  response = requests.get(url_forecast_eod_with_ticker)
51
  if response.status_code == 200:
52
  json_data = json.loads(response.json())
 
53
  eod_forecast = json_data["latest_prediction"]
54
  return eod_forecast
55
  else:
56
  return
57
-
58
-
59
 
60
  def print_sentiment_summery(df) :
61
  column_name = "sentiment"
@@ -91,13 +100,12 @@ def get_stock_info_from_html(stock_info):
91
  f"<b>Stock Price: </b> {si['currentPrice']} {str(si['financialCurrency'])}")
92
  return text
93
 
 
 
94
  def get_forecast_html(stock_info):
95
 
96
  currentPrice = stock_info.info['currentPrice']
97
  eod_forecast = get_eod_forecast(stock_info)
98
- #st.write(eod_forecast)
99
- #eod_forecast = float(get_eod_forecast(stock_info))
100
- #st.write(type(eod_forecast))
101
  eod_forecast_price = currentPrice * (1 + eod_forecast/100)
102
  color = 'red' if eod_forecast < 0 else 'green'
103
  mark = '+' if eod_forecast >= 0 else '-'
@@ -107,7 +115,17 @@ def get_forecast_html(stock_info):
107
 
108
  return html
109
 
110
-
 
 
 
 
 
 
 
 
 
 
111
 
112
  def plot_graph(stock_info):
113
  period = st.session_state.chart_time_frame or "5Y"
@@ -202,5 +220,6 @@ with st.spinner('Wait for it...'):
202
  df = print_sentiment(stock_info)
203
  st.write(f"<H6>Sentiment summery</H6>", unsafe_allow_html=True)
204
  print_sentiment_summery(df)
205
- st.write(f"<H4>Prediction</H4>", unsafe_allow_html=True)
206
- st.write(get_forecast_html(stock_info), unsafe_allow_html=True)
 
 
10
  url_sentiment = "https://yaakovy-fin-proj-docker.hf.space/ticker/"
11
  url_timeGpt = "https://ofirmatzlawi-fin-proj-docker-1.hf.space/ticker/"
12
  url_forecast_eod = "https://yaakovy-lasthourforcast.hf.space/ticker/"
13
+ url_forecast_eod24 = "https://ofirmatzlawi-fin-proj-docker-2.hf.space/ticker/"
 
14
 
15
  def get_max_sentiment(row):
16
  if row["sentiment_score"] > 0.05: # Threshold for positive sentiment
 
21
  return "neutral"
22
 
23
 
 
24
  def get_sentiment_data(stock_info):
25
  symbol = stock_info.info['symbol']
26
  url_sentiment_with_ticker = f"{url_sentiment}{symbol}"
 
42
  return df
43
 
44
 
45
+ def get_eod_forecast24(stock_info):
46
+ symbol = stock_info.info['symbol']
47
+ url_forecast_eod_with_ticker = f"{url_forecast_eod24}{symbol}"
48
+ response = requests.get(url_forecast_eod_with_ticker)
49
+ if response.status_code == 200:
50
+ eod_forecast = json.loads(response.json())
51
+ #st.write(json_data)
52
+ #eod_forecast = json_data["latest_prediction"]
53
+ return eod_forecast
54
+ else:
55
+ return
56
+
57
  def get_eod_forecast(stock_info):
58
  symbol = stock_info.info['symbol']
59
  url_forecast_eod_with_ticker = f"{url_forecast_eod}{symbol}"
60
  response = requests.get(url_forecast_eod_with_ticker)
61
  if response.status_code == 200:
62
  json_data = json.loads(response.json())
63
+
64
  eod_forecast = json_data["latest_prediction"]
65
  return eod_forecast
66
  else:
67
  return
 
 
68
 
69
  def print_sentiment_summery(df) :
70
  column_name = "sentiment"
 
100
  f"<b>Stock Price: </b> {si['currentPrice']} {str(si['financialCurrency'])}")
101
  return text
102
 
103
+
104
+
105
  def get_forecast_html(stock_info):
106
 
107
  currentPrice = stock_info.info['currentPrice']
108
  eod_forecast = get_eod_forecast(stock_info)
 
 
 
109
  eod_forecast_price = currentPrice * (1 + eod_forecast/100)
110
  color = 'red' if eod_forecast < 0 else 'green'
111
  mark = '+' if eod_forecast >= 0 else '-'
 
115
 
116
  return html
117
 
118
+ def get_forecast_html24(stock_info):
119
+
120
+ currentPrice = stock_info.info['currentPrice']
121
+ eod_forecast = get_eod_forecast24(stock_info)
122
+ eod_forecast_price = currentPrice * (1 + eod_forecast/100)
123
+ color = 'red' if eod_forecast < 0 else 'green'
124
+ mark = '+' if eod_forecast >= 0 else '-'
125
+ eod_forecast_p = abs(round(eod_forecast, 2))
126
+ html = (f"<b>EOD Tomorrow Close Price: </b> <span style='color:{color};'> {eod_forecast_price:.2f} </span> &emsp; <span style='color:{color};'> {mark}{eod_forecast_p}% </span> ")
127
+
128
+ return html
129
 
130
  def plot_graph(stock_info):
131
  period = st.session_state.chart_time_frame or "5Y"
 
220
  df = print_sentiment(stock_info)
221
  st.write(f"<H6>Sentiment summery</H6>", unsafe_allow_html=True)
222
  print_sentiment_summery(df)
223
+ st.write(f"<H4>Forecasting</H4>", unsafe_allow_html=True)
224
+ st.write(get_forecast_html(stock_info), unsafe_allow_html=True)
225
+ st.write(get_forecast_html24(stock_info), unsafe_allow_html=True)