Tonic commited on
Commit
229258d
·
unverified ·
1 Parent(s): 0356979

fix fundamentals info retrieval

Browse files
Files changed (1) hide show
  1. app.py +24 -21
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
- # Calculate structured product metrics
 
 
 
3355
  product_metrics = {
3356
- "Market_Cap": df['Market_Cap'].iloc[-1],
3357
- "Sector": df['Sector'].iloc[-1],
3358
- "Industry": df['Industry'].iloc[-1],
3359
- "Dividend_Yield": df['Dividend_Yield'].iloc[-1],
3360
- "Avg_Daily_Volume": df['Avg_Daily_Volume'].iloc[-1],
3361
- "Volume_Volatility": df['Volume_Volatility'].iloc[-1],
3362
- "Enterprise_Value": df['Enterprise_Value'].iloc[-1],
3363
- "P/E_Ratio": df['P/E_Ratio'].iloc[-1],
3364
- "Forward_P/E": df['Forward_P/E'].iloc[-1],
3365
- "PEG_Ratio": df['PEG_Ratio'].iloc[-1],
3366
- "Price_to_Book": df['Price_to_Book'].iloc[-1],
3367
- "Price_to_Sales": df['Price_to_Sales'].iloc[-1]
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": df['Sector'].iloc[-1],
3376
- "Industry": df['Industry'].iloc[-1],
3377
- "Market_Cap_Rank": "Large" if df['Market_Cap'].iloc[-1] > 1e10 else "Mid" if df['Market_Cap'].iloc[-1] > 1e9 else "Small",
3378
- "Liquidity_Score": "High" if df['Avg_Daily_Volume'].iloc[-1] > 1e6 else "Medium" if df['Avg_Daily_Volume'].iloc[-1] > 1e5 else "Low",
3379
- "Gross_Margin": df['Gross_Margin'].iloc[-1],
3380
- "Operating_Margin": df['Operating_Margin'].iloc[-1],
3381
- "Net_Margin": df['Net_Margin'].iloc[-1]
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