CCockrum commited on
Commit
27fa885
·
verified ·
1 Parent(s): 701e46b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -12
app.py CHANGED
@@ -2,7 +2,8 @@ import pandas as pd
2
  import numpy as np
3
  import gradio as gr
4
  import matplotlib.pyplot as plt
5
- import yfinance as yf
 
6
  from transformers import pipeline
7
 
8
  # Initialize Summarizer
@@ -30,16 +31,17 @@ def discounted_cash_flow(fcf, growth_rate, discount_rate, terminal_growth_rate,
30
  return fcf_forecast, present_values, terminal_value, terminal_value_pv, total_value
31
 
32
  def get_company_fcf(symbol):
33
- ticker = yf.Ticker(symbol)
 
34
  try:
35
- fcf = ticker.free_cashflow
36
- if fcf is not None:
37
- return fcf.iloc[0] # Get the most recent free cash flow
38
- else:
39
- cashflow = ticker.cashflow
40
- operating_cash_flow = cashflow.loc["Total Cash From Operating Activities"].iloc[0]
41
- capex = cashflow.loc["Capital Expenditures"].iloc[0]
42
- return operating_cash_flow + capex # Capex is negative so add
43
  except Exception as e:
44
  print(f"DEBUG: Error fetching FCF for {symbol}: {e}")
45
  return None
@@ -98,8 +100,8 @@ iface = gr.Interface(
98
  ["AAPL", 0.06, 0.08, 0.025, 5]
99
  ],
100
  title="AI-Powered DCF Valuation Calculator",
101
- description="Enter a stock symbol and your assumptions. The app pulls live data, runs a DCF, and generates a research summary."
102
  )
103
 
104
  if __name__ == "__main__":
105
- iface.launch()
 
2
  import numpy as np
3
  import gradio as gr
4
  import matplotlib.pyplot as plt
5
+ import requests
6
+ import os
7
  from transformers import pipeline
8
 
9
  # Initialize Summarizer
 
31
  return fcf_forecast, present_values, terminal_value, terminal_value_pv, total_value
32
 
33
  def get_company_fcf(symbol):
34
+ api_key = os.getenv("POLYGON_API_KEY")
35
+ url = f"https://api.polygon.io/vX/reference/financials?ticker={symbol}&apiKey={api_key}"
36
  try:
37
+ response = requests.get(url)
38
+ response.raise_for_status()
39
+ data = response.json()
40
+
41
+ # Navigate the JSON to find Free Cash Flow
42
+ fcf = data['results'][0]['financials']['cash_flow_statement']['free_cash_flow']['value']
43
+ return float(fcf)
44
+
45
  except Exception as e:
46
  print(f"DEBUG: Error fetching FCF for {symbol}: {e}")
47
  return None
 
100
  ["AAPL", 0.06, 0.08, 0.025, 5]
101
  ],
102
  title="AI-Powered DCF Valuation Calculator",
103
+ description="Enter a stock symbol and your assumptions. The app pulls live data from Polygon.io, runs a DCF, and generates a research summary."
104
  )
105
 
106
  if __name__ == "__main__":
107
+ iface.launch()