Spaces:
Paused
Paused
rcwaterman
commited on
Commit
•
54e5bf6
1
Parent(s):
5caa566
Adding dcf api retrieval
Browse files
app.py
CHANGED
@@ -22,6 +22,7 @@ from langchain_core.messages import BaseMessage
|
|
22 |
import datetime
|
23 |
import yfinance as yf
|
24 |
import pandas as pd
|
|
|
25 |
|
26 |
# GLOBAL SCOPE - ENTIRE APPLICATION HAS ACCESS TO VALUES SET IN THIS SCOPE #
|
27 |
# ---- ENV VARIABLES ---- #
|
@@ -38,6 +39,7 @@ We will load our environment variables here.
|
|
38 |
OPENAI_API_KEY = os.environ['OPENAI_API_KEY']
|
39 |
LANGCHAIN_API_KEY = os.environ['LANGCHAIN_API_KEY']
|
40 |
POLYGON_API_KEY = os.environ['POLYGON_API_KEY']
|
|
|
41 |
|
42 |
#-----DEFINE ADDITIONAL TOOLS AND FUNCTIONS-----#
|
43 |
|
@@ -120,6 +122,24 @@ def calculate_wacc( #refer to https://www.gurufocus.com/term/wacc/SOFI#:~:text=S
|
|
120 |
wacc = round((weight_of_equity * cost_of_equity) + ((weight_of_debt * cost_of_debt ) * (1-tax_rate)),3)
|
121 |
return wacc
|
122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
def get_weights(market_cap, long_term_debt):
|
124 |
e = market_cap
|
125 |
d = long_term_debt
|
@@ -156,7 +176,7 @@ tool_belt = [
|
|
156 |
get_time,
|
157 |
get_quarter,
|
158 |
calculate_percent_valuation,
|
159 |
-
|
160 |
RAGAgent(),
|
161 |
DuckDuckGoSearchRun(),
|
162 |
PolygonAggregates(api_wrapper=api_wrapper),
|
|
|
22 |
import datetime
|
23 |
import yfinance as yf
|
24 |
import pandas as pd
|
25 |
+
import requests
|
26 |
|
27 |
# GLOBAL SCOPE - ENTIRE APPLICATION HAS ACCESS TO VALUES SET IN THIS SCOPE #
|
28 |
# ---- ENV VARIABLES ---- #
|
|
|
39 |
OPENAI_API_KEY = os.environ['OPENAI_API_KEY']
|
40 |
LANGCHAIN_API_KEY = os.environ['LANGCHAIN_API_KEY']
|
41 |
POLYGON_API_KEY = os.environ['POLYGON_API_KEY']
|
42 |
+
FMP_API_KEY = os.environ['FMP_API_KEY']
|
43 |
|
44 |
#-----DEFINE ADDITIONAL TOOLS AND FUNCTIONS-----#
|
45 |
|
|
|
122 |
wacc = round((weight_of_equity * cost_of_equity) + ((weight_of_debt * cost_of_debt ) * (1-tax_rate)),3)
|
123 |
return wacc
|
124 |
|
125 |
+
@tool
|
126 |
+
def get_dcf(ticker):
|
127 |
+
"""This tool takes a stock ticker as an argument and returns the discounted cash flow valuation, in dollars. This tool is helpful when trying to determine the intrinsic value of a company, or if a company is overvalued or undervalued."""
|
128 |
+
url = f'https://financialmodelingprep.com/api/v3/discounted-cash-flow/{ticker}?apikey={FMP_API_KEY}'
|
129 |
+
|
130 |
+
# Make the request to the API
|
131 |
+
response = requests.get(url)
|
132 |
+
|
133 |
+
# Check if the request was successful
|
134 |
+
if response.status_code == 200:
|
135 |
+
# Parse the response JSON
|
136 |
+
dcf_data = response.json()
|
137 |
+
# return the DCF data
|
138 |
+
return dcf_data[0]["dcf"]
|
139 |
+
else:
|
140 |
+
# return the error message
|
141 |
+
return f"Failed to retrieve data: {response.status_code}"
|
142 |
+
|
143 |
def get_weights(market_cap, long_term_debt):
|
144 |
e = market_cap
|
145 |
d = long_term_debt
|
|
|
176 |
get_time,
|
177 |
get_quarter,
|
178 |
calculate_percent_valuation,
|
179 |
+
get_dcf,
|
180 |
RAGAgent(),
|
181 |
DuckDuckGoSearchRun(),
|
182 |
PolygonAggregates(api_wrapper=api_wrapper),
|