Spaces:
Paused
Paused
Tonic commited on
fix fundamentals info retrieval
Browse files
app.py
CHANGED
|
@@ -3351,34 +3351,37 @@ The **Advanced Stock Prediction System** is a cutting-edge AI-powered platform w
|
|
| 3351 |
# Get historical data for additional metrics
|
| 3352 |
df = get_historical_data(symbol, timeframe, lookback_days)
|
| 3353 |
|
| 3354 |
-
#
|
|
|
|
|
|
|
|
|
|
| 3355 |
product_metrics = {
|
| 3356 |
-
"Market_Cap":
|
| 3357 |
-
"Sector":
|
| 3358 |
-
"Industry":
|
| 3359 |
-
"Dividend_Yield":
|
| 3360 |
-
"Avg_Daily_Volume":
|
| 3361 |
-
"Volume_Volatility": df['
|
| 3362 |
-
"Enterprise_Value":
|
| 3363 |
-
"P/E_Ratio":
|
| 3364 |
-
"Forward_P/E":
|
| 3365 |
-
"PEG_Ratio":
|
| 3366 |
-
"Price_to_Book":
|
| 3367 |
-
"Price_to_Sales":
|
| 3368 |
}
|
| 3369 |
|
| 3370 |
# Calculate advanced risk metrics
|
| 3371 |
risk_metrics = calculate_advanced_risk_metrics(df, market_returns, risk_free_rate)
|
| 3372 |
|
| 3373 |
-
# Calculate sector metrics
|
| 3374 |
sector_metrics = {
|
| 3375 |
-
"Sector":
|
| 3376 |
-
"Industry":
|
| 3377 |
-
"Market_Cap_Rank": "Large" if
|
| 3378 |
-
"Liquidity_Score": "High" if
|
| 3379 |
-
"Gross_Margin":
|
| 3380 |
-
"Operating_Margin":
|
| 3381 |
-
"Net_Margin":
|
| 3382 |
}
|
| 3383 |
|
| 3384 |
# Add enhanced features information
|
|
|
|
| 3351 |
# Get historical data for additional metrics
|
| 3352 |
df = get_historical_data(symbol, timeframe, lookback_days)
|
| 3353 |
|
| 3354 |
+
# Fetch fundamental data from yfinance info property
|
| 3355 |
+
fundamentals = get_fundamental_data(symbol)
|
| 3356 |
+
|
| 3357 |
+
# Calculate structured product metrics using fundamentals and price data
|
| 3358 |
product_metrics = {
|
| 3359 |
+
"Market_Cap": fundamentals.get("marketCap"),
|
| 3360 |
+
"Sector": fundamentals.get("sector"),
|
| 3361 |
+
"Industry": fundamentals.get("industry"),
|
| 3362 |
+
"Dividend_Yield": fundamentals.get("dividendYield"),
|
| 3363 |
+
"Avg_Daily_Volume": fundamentals.get("averageDailyVolume"),
|
| 3364 |
+
"Volume_Volatility": df['Volume'].rolling(window=20, min_periods=1).std().iloc[-1] if 'Volume' in df.columns else None,
|
| 3365 |
+
"Enterprise_Value": fundamentals.get("enterpriseValue"),
|
| 3366 |
+
"P/E_Ratio": fundamentals.get("trailingPE"),
|
| 3367 |
+
"Forward_P/E": fundamentals.get("forwardPE"),
|
| 3368 |
+
"PEG_Ratio": fundamentals.get("pegRatio"),
|
| 3369 |
+
"Price_to_Book": fundamentals.get("priceToBook"),
|
| 3370 |
+
"Price_to_Sales": fundamentals.get("priceToSalesTrailing12Months"),
|
| 3371 |
}
|
| 3372 |
|
| 3373 |
# Calculate advanced risk metrics
|
| 3374 |
risk_metrics = calculate_advanced_risk_metrics(df, market_returns, risk_free_rate)
|
| 3375 |
|
| 3376 |
+
# Calculate sector metrics using fundamentals
|
| 3377 |
sector_metrics = {
|
| 3378 |
+
"Sector": fundamentals.get("sector"),
|
| 3379 |
+
"Industry": fundamentals.get("industry"),
|
| 3380 |
+
"Market_Cap_Rank": "Large" if fundamentals.get("marketCap", 0) > 1e10 else "Mid" if fundamentals.get("marketCap", 0) > 1e9 else "Small",
|
| 3381 |
+
"Liquidity_Score": "High" if fundamentals.get("averageDailyVolume", 0) > 1e6 else "Medium" if fundamentals.get("averageDailyVolume", 0) > 1e5 else "Low",
|
| 3382 |
+
"Gross_Margin": fundamentals.get("grossMargins"),
|
| 3383 |
+
"Operating_Margin": fundamentals.get("operatingMargins"),
|
| 3384 |
+
"Net_Margin": fundamentals.get("netMargins"),
|
| 3385 |
}
|
| 3386 |
|
| 3387 |
# Add enhanced features information
|