Robert Castagna commited on
Commit
50fc21f
·
1 Parent(s): 8aec326

add growth metrics

Browse files
Files changed (1) hide show
  1. pages/1_Fundamentals.py +36 -2
pages/1_Fundamentals.py CHANGED
@@ -129,7 +129,6 @@ with st.form(key="selecting columns"):
129
  submit_button = st.form_submit_button(label='Compute Metrics')
130
 
131
  if submit_button and symbols and strategy_selection == 'Value':
132
- beta_dfs = []
133
  gains_data = {}
134
  hash_map = {}
135
 
@@ -174,4 +173,39 @@ with st.form(key="selecting columns"):
174
  st.write(df_final)
175
 
176
  if submit_button and symbols and strategy_selection == 'Growth':
177
- st.write("Not built yet...")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  submit_button = st.form_submit_button(label='Compute Metrics')
130
 
131
  if submit_button and symbols and strategy_selection == 'Value':
 
132
  gains_data = {}
133
  hash_map = {}
134
 
 
173
  st.write(df_final)
174
 
175
  if submit_button and symbols and strategy_selection == 'Growth':
176
+
177
+ hash_map,gains_data = {},{}
178
+ for ticker in symbols:
179
+ # make all the API calls and capture return json
180
+ basic_info = get_industry(ticker)
181
+ metric_data, annual_series_data, quarterly_series_data = get_company_metrics(ticker)
182
+
183
+ # reformat all JSON returns to be flattened dictionaries
184
+ ebitPerShare_dict = {'ebitPerShare': annual_series_data['ebitPerShare'][0]['v'] if 'ebitPerShare' in annual_series_data else 0}
185
+ ev_dict = {'ev' :annual_series_data['ev'][0]['v'] if 'ev' in annual_series_data else 0}
186
+ salesPerShare_dict = {'salesPerShare': annual_series_data['salesPerShare'][0]['v'] if 'salesPerShare' in annual_series_data else 0}
187
+ operatingMargin_dict = {'operatingMargin': annual_series_data['operatingMargin'][0]['v'] if 'operatingMargin' in annual_series_data else 0}
188
+ eps_dict = {'eps' :annual_series_data['eps'][0]['v'] if 'eps' in annual_series_data else 0}
189
+ pe_dict = {'pe': annual_series_data['pe'][0]['v'] if 'pe' in annual_series_data else 0}
190
+ ps_dict = {'ps': annual_series_data['ps'][0]['v'] if 0 in annual_series_data['ps'] else 0}
191
+ pb_dict = {'pb': annual_series_data['pb'][0]['v'] if 'pb' in annual_series_data else 0}
192
+
193
+ # merge all dictionary keys per ticker
194
+ combined_info = basic_info.copy() # Make a copy of the basic info
195
+ combined_info = combined_info | metric_data | ebitPerShare_dict | ev_dict | salesPerShare_dict | operatingMargin_dict | eps_dict | pe_dict | ps_dict | pb_dict
196
+
197
+ hash_map[ticker] = combined_info
198
+
199
+ # equity gains
200
+ _, div, close_price = get_equity_gains(ticker=ticker, period=1810)
201
+ gains_data[ticker] = [div, close_price]
202
+
203
+
204
+ # Now, create a DataFrame from the hash_map
205
+ df_1 = pd.DataFrame.from_dict(hash_map, orient='index')[['finnhubIndustry','pe','ps','pb','eps','epsGrowth5Y','ebitdPerShareAnnual', 'ebitdPerShareTTM', 'ebitdaCagr5Y', 'ebitdaInterimCagr5Y']]
206
+ df_2 = pd.DataFrame.from_dict(gains_data, orient='index', columns=['Recent Dividend','Price'])
207
+ df_final = df_1.join(df_2)
208
+
209
+ df_final['PE/G'] = df_final['pe'] / df_final['epsGrowth5Y']
210
+ df_final.rename({'finnhubIndustry':'Industry','pe':'P/E', 'ps':'P/S', 'pb':'P/B', 'eps': 'EPS'}, inplace=True, axis=1)
211
+ st.write(df_final)