File size: 1,127 Bytes
7a4b161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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)
    }