Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -100,15 +100,40 @@ def stock_research(symbol, eps=5.0, growth=0.1, book=500000000):
|
|
100 |
ratios_table = pd.DataFrame(ratios.items(), columns=["Metric", "Value"])
|
101 |
financial_health = ratios_table[ratios_table["Metric"].isin(["Debt/Equity Ratio", "Return on Equity (%)", "Free Cash Flow ($)", "Beta (Volatility)"])]
|
102 |
|
|
|
103 |
recommendation = "Hold"
|
104 |
if ratios['P/E Ratio'] < 15 and ratios['Debt/Equity Ratio'] < 1.0 and ratios['Return on Equity (%)'] > 10 and ratios['Beta (Volatility)'] < 1.2:
|
105 |
recommendation = "Buy"
|
106 |
elif ratios['P/E Ratio'] > 30 or ratios['Debt/Equity Ratio'] > 2.0 or ratios['Return on Equity (%)'] < 5:
|
107 |
recommendation = "Sell"
|
108 |
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
-
return
|
112 |
|
113 |
# Theme Selection
|
114 |
selected_theme = os.getenv("APP_THEME", "light")
|
|
|
100 |
ratios_table = pd.DataFrame(ratios.items(), columns=["Metric", "Value"])
|
101 |
financial_health = ratios_table[ratios_table["Metric"].isin(["Debt/Equity Ratio", "Return on Equity (%)", "Free Cash Flow ($)", "Beta (Volatility)"])]
|
102 |
|
103 |
+
# New Recommendation Section
|
104 |
recommendation = "Hold"
|
105 |
if ratios['P/E Ratio'] < 15 and ratios['Debt/Equity Ratio'] < 1.0 and ratios['Return on Equity (%)'] > 10 and ratios['Beta (Volatility)'] < 1.2:
|
106 |
recommendation = "Buy"
|
107 |
elif ratios['P/E Ratio'] > 30 or ratios['Debt/Equity Ratio'] > 2.0 or ratios['Return on Equity (%)'] < 5:
|
108 |
recommendation = "Sell"
|
109 |
|
110 |
+
# Detailed report for summarization
|
111 |
+
report = (
|
112 |
+
f"Company Overview:\n"
|
113 |
+
f"Name: {info['Name']}\n"
|
114 |
+
f"Industry: {info['Industry']}\n"
|
115 |
+
f"Sector: {info['Sector']}\n"
|
116 |
+
f"Market Cap: ${info['Market Cap']:,.2f}\n\n"
|
117 |
+
f"Financial Metrics:\n"
|
118 |
+
f"P/E Ratio: {ratios['P/E Ratio']}\n"
|
119 |
+
f"P/S Ratio: {ratios['P/S Ratio']}\n"
|
120 |
+
f"P/B Ratio: {ratios['P/B Ratio']}\n"
|
121 |
+
f"PEG Ratio: {ratios['PEG Ratio']}\n"
|
122 |
+
f"Dividend Yield: {ratios['Dividend Yield']}%\n"
|
123 |
+
f"Debt/Equity Ratio: {ratios['Debt/Equity Ratio']}\n"
|
124 |
+
f"Return on Equity: {ratios['Return on Equity (%)']}%\n"
|
125 |
+
f"Free Cash Flow: ${ratios['Free Cash Flow ($)']:,.2f}\n"
|
126 |
+
f"Beta (Volatility): {ratios['Beta (Volatility)']}\n"
|
127 |
+
)
|
128 |
+
|
129 |
+
# Summarize via Mistral
|
130 |
+
summary_prompt = f\"Summarize this financial report clearly and briefly:\n\n{report}\"
|
131 |
+
ai_summary = query_mistral(summary_prompt)
|
132 |
+
|
133 |
+
# Add recommendation inside financial health
|
134 |
+
financial_health = financial_health.append({\"Metric\": \"Recommendation\", \"Value\": recommendation}, ignore_index=True)
|
135 |
|
136 |
+
return ai_summary, info_table, ratios_table, financial_health, sector_comp, fig
|
137 |
|
138 |
# Theme Selection
|
139 |
selected_theme = os.getenv("APP_THEME", "light")
|