Spaces:
Sleeping
Sleeping
| import pandas as pd | |
| import numpy as np | |
| from datetime import datetime, timedelta | |
| def format_currency(value): | |
| """Format number as currency""" | |
| return f"${value:,.2f}" | |
| def format_percentage(value): | |
| """Format number as percentage""" | |
| return f"{value:+.2f}%" | |
| def get_market_status(): | |
| """Get current market status""" | |
| now = datetime.now() | |
| if now.weekday() >= 5: # Weekend | |
| return "Market Closed" | |
| market_open = now.replace(hour=9, minute=30, second=0, microsecond=0) | |
| market_close = now.replace(hour=16, minute=0, second=0, microsecond=0) | |
| if now < market_open: | |
| return "Pre-Market" | |
| elif now > market_close: | |
| return "After-Hours" | |
| else: | |
| return "Market Open" | |
| def calculate_support_resistance(prices): | |
| """Calculate simple support and resistance levels""" | |
| if len(prices) < 5: | |
| return {"support": prices[-1] * 0.95, "resistance": prices[-1] * 1.05} | |
| support = min(prices[-5:]) * 0.98 | |
| resistance = max(prices[-5:]) * 1.02 | |
| return { | |
| "support": round(support, 2), | |
| "resistance": round(resistance, 2) | |
| } |