Spaces:
Paused
Paused
Tonic commited on
attempt better market data for open / close and info
Browse files
app.py
CHANGED
|
@@ -1540,7 +1540,7 @@ def make_prediction_enhanced(symbol: str, timeframe: str = "1d", prediction_days
|
|
| 1540 |
]])
|
| 1541 |
advanced_uncertainties = calculate_advanced_uncertainty(
|
| 1542 |
dummy_quantiles, historical_volatility, market_conditions
|
| 1543 |
-
|
| 1544 |
|
| 1545 |
print(f"Technical strategy completed: {len(final_pred)} predictions generated")
|
| 1546 |
|
|
@@ -2002,7 +2002,7 @@ def get_market_data(symbol: str = "^GSPC", lookback_days: int = 365) -> pd.DataF
|
|
| 2002 |
else:
|
| 2003 |
print(f"Warning: No data returned for {symbol}")
|
| 2004 |
df = pd.DataFrame()
|
| 2005 |
-
|
| 2006 |
return df
|
| 2007 |
except Exception as e:
|
| 2008 |
print(f"Warning: Could not fetch market data for {symbol}: {str(e)}")
|
|
@@ -2995,24 +2995,20 @@ The **Advanced Stock Prediction System** is a cutting-edge AI-powered platform w
|
|
| 2995 |
value="Select a market and click 'Check Market Status' to see current trading status.",
|
| 2996 |
label="Market Status Result"
|
| 2997 |
)
|
| 2998 |
-
|
| 2999 |
# Enhanced Market Information Section
|
| 3000 |
with gr.Accordion("🌍 Enhanced Market Information", open=False):
|
| 3001 |
with gr.Row():
|
| 3002 |
with gr.Column():
|
| 3003 |
gr.Markdown("### Market Summary")
|
| 3004 |
market_summary_display = gr.JSON(label="Market Summary", value={})
|
| 3005 |
-
|
| 3006 |
def update_market_summary():
|
| 3007 |
"""Update market summary with enhanced yfinance data"""
|
| 3008 |
return get_enhanced_market_summary()
|
| 3009 |
-
|
| 3010 |
update_market_summary_btn = gr.Button("🔄 Update Market Summary")
|
| 3011 |
update_market_summary_btn.click(
|
| 3012 |
fn=update_market_summary,
|
| 3013 |
outputs=[market_summary_display]
|
| 3014 |
)
|
| 3015 |
-
|
| 3016 |
with gr.Column():
|
| 3017 |
gr.Markdown("### Market Types Supported")
|
| 3018 |
gr.Markdown("""
|
|
@@ -4607,6 +4603,8 @@ def get_market_info_from_yfinance(symbol: str) -> Dict:
|
|
| 4607 |
symbols_without_earnings = ['^', '=', 'F', 'X', 'USD', 'EUR', 'GBP', 'JPY', 'BTC', 'ETH', 'GC', 'SI', 'CL', 'NG']
|
| 4608 |
skip_earnings = any(symbol in symbol.upper() for symbol in symbols_without_earnings)
|
| 4609 |
|
|
|
|
|
|
|
| 4610 |
if skip_earnings:
|
| 4611 |
market_data['earnings'] = []
|
| 4612 |
market_data['recommendations'] = []
|
|
@@ -4621,7 +4619,7 @@ def get_market_info_from_yfinance(symbol: str) -> Dict:
|
|
| 4621 |
except Exception as e:
|
| 4622 |
print(f"Error fetching recommendations for {symbol}: {str(e)}")
|
| 4623 |
market_data['recommendations'] = []
|
| 4624 |
-
|
| 4625 |
# Get earnings info if available with retry - use get_earnings() method
|
| 4626 |
try:
|
| 4627 |
earnings = retry_yfinance_request(lambda: ticker.get_earnings())
|
|
@@ -4633,11 +4631,8 @@ def get_market_info_from_yfinance(symbol: str) -> Dict:
|
|
| 4633 |
except Exception as e:
|
| 4634 |
print(f"Error fetching earnings for {symbol}: {str(e)}")
|
| 4635 |
market_data['earnings'] = []
|
| 4636 |
-
|
| 4637 |
-
|
| 4638 |
-
|
| 4639 |
-
# For stocks, try to get dividends and splits
|
| 4640 |
-
if not skip_earnings:
|
| 4641 |
try:
|
| 4642 |
dividends = retry_yfinance_request(lambda: ticker.get_dividends())
|
| 4643 |
if dividends is not None and hasattr(dividends, 'empty') and not dividends.empty:
|
|
|
|
| 1540 |
]])
|
| 1541 |
advanced_uncertainties = calculate_advanced_uncertainty(
|
| 1542 |
dummy_quantiles, historical_volatility, market_conditions
|
| 1543 |
+
)
|
| 1544 |
|
| 1545 |
print(f"Technical strategy completed: {len(final_pred)} predictions generated")
|
| 1546 |
|
|
|
|
| 2002 |
else:
|
| 2003 |
print(f"Warning: No data returned for {symbol}")
|
| 2004 |
df = pd.DataFrame()
|
| 2005 |
+
|
| 2006 |
return df
|
| 2007 |
except Exception as e:
|
| 2008 |
print(f"Warning: Could not fetch market data for {symbol}: {str(e)}")
|
|
|
|
| 2995 |
value="Select a market and click 'Check Market Status' to see current trading status.",
|
| 2996 |
label="Market Status Result"
|
| 2997 |
)
|
|
|
|
| 2998 |
# Enhanced Market Information Section
|
| 2999 |
with gr.Accordion("🌍 Enhanced Market Information", open=False):
|
| 3000 |
with gr.Row():
|
| 3001 |
with gr.Column():
|
| 3002 |
gr.Markdown("### Market Summary")
|
| 3003 |
market_summary_display = gr.JSON(label="Market Summary", value={})
|
|
|
|
| 3004 |
def update_market_summary():
|
| 3005 |
"""Update market summary with enhanced yfinance data"""
|
| 3006 |
return get_enhanced_market_summary()
|
|
|
|
| 3007 |
update_market_summary_btn = gr.Button("🔄 Update Market Summary")
|
| 3008 |
update_market_summary_btn.click(
|
| 3009 |
fn=update_market_summary,
|
| 3010 |
outputs=[market_summary_display]
|
| 3011 |
)
|
|
|
|
| 3012 |
with gr.Column():
|
| 3013 |
gr.Markdown("### Market Types Supported")
|
| 3014 |
gr.Markdown("""
|
|
|
|
| 4603 |
symbols_without_earnings = ['^', '=', 'F', 'X', 'USD', 'EUR', 'GBP', 'JPY', 'BTC', 'ETH', 'GC', 'SI', 'CL', 'NG']
|
| 4604 |
skip_earnings = any(symbol in symbol.upper() for symbol in symbols_without_earnings)
|
| 4605 |
|
| 4606 |
+
additional_data = {}
|
| 4607 |
+
|
| 4608 |
if skip_earnings:
|
| 4609 |
market_data['earnings'] = []
|
| 4610 |
market_data['recommendations'] = []
|
|
|
|
| 4619 |
except Exception as e:
|
| 4620 |
print(f"Error fetching recommendations for {symbol}: {str(e)}")
|
| 4621 |
market_data['recommendations'] = []
|
| 4622 |
+
|
| 4623 |
# Get earnings info if available with retry - use get_earnings() method
|
| 4624 |
try:
|
| 4625 |
earnings = retry_yfinance_request(lambda: ticker.get_earnings())
|
|
|
|
| 4631 |
except Exception as e:
|
| 4632 |
print(f"Error fetching earnings for {symbol}: {str(e)}")
|
| 4633 |
market_data['earnings'] = []
|
| 4634 |
+
|
| 4635 |
+
# For stocks, try to get dividends and splits
|
|
|
|
|
|
|
|
|
|
| 4636 |
try:
|
| 4637 |
dividends = retry_yfinance_request(lambda: ticker.get_dividends())
|
| 4638 |
if dividends is not None and hasattr(dividends, 'empty') and not dividends.empty:
|