RobertCastagna commited on
Commit
aec0d9c
1 Parent(s): 2c32154

Update pages/data-feed.py

Browse files
Files changed (1) hide show
  1. pages/data-feed.py +28 -1
pages/data-feed.py CHANGED
@@ -5,6 +5,8 @@ import pandas as pd
5
  import streamlit as st
6
  import os
7
  import re
 
 
8
 
9
  def get_finnhub_data(example: str) -> json:
10
  """
@@ -120,4 +122,29 @@ if ticker:
120
  t_bill_data = get_alpha_vantage_data(q)
121
 
122
  df_t_bills = pd.DataFrame(t_bill_data['data'], columns = [['date','t_bill_as_pct']])
123
- st.write(df_t_bills)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  import streamlit as st
6
  import os
7
  import re
8
+ import yfinance as yf
9
+
10
 
11
  def get_finnhub_data(example: str) -> json:
12
  """
 
122
  t_bill_data = get_alpha_vantage_data(q)
123
 
124
  df_t_bills = pd.DataFrame(t_bill_data['data'], columns = [['date','t_bill_as_pct']])
125
+ st.write(df_t_bills)
126
+
127
+
128
+ # ------------------------ yfinance API --------------------------------- #
129
+ # index and ticker price data (beta calculations)
130
+ #
131
+
132
+ sp = yf.Ticker("^GSPC")
133
+ sp_hist = sp.history(period="1y")['Close']
134
+
135
+ sp = yf.Ticker(f'{ticker}')
136
+ ticker_hist = sp.history(period="1y")['Close']
137
+
138
+ sp500 = sp_hist.reset_index().rename(columns={'Close':'sp500_Close'})
139
+ sp500['sp500_variance'] = sp500['sp500_Close'].var()
140
+
141
+ merged_df = sp500.merge(ticker_hist, how='outer', on='Date')
142
+
143
+ beta = merged_df.cov().loc['sp500_Close']['Close'] / sp500['sp500_variance'].max()
144
+ max_date = merged_df['Date'].max()
145
+
146
+ d = {'Date': max_date, 'Beta': beta, 'Symbol': ticker}
147
+ df_beta = pd.DataFrame(d, index = [0])
148
+ st.write(df_beta)
149
+
150
+