Spaces:
Sleeping
Sleeping
File size: 1,252 Bytes
1243c9b | 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 41 42 43 44 45 46 47 | import numpy as np
import pandas as pd
def add_technical_indicators(df: pd.DataFrame) -> pd.DataFrame:
df = df.copy()
# RSI
delta = df["Close"].diff()
gain = delta.where(delta > 0, 0).rolling(window=14).mean()
loss = -delta.where(delta < 0, 0).rolling(window=14).mean()
rs = gain / loss
df["RSI"] = 100 - (100 / (1 + rs))
# MACD
exp1 = df["Close"].ewm(span=12, adjust=False).mean()
exp2 = df["Close"].ewm(span=26, adjust=False).mean()
df["MACD"] = exp1 - exp2
# Simple 50-day MA
df["MA50"] = df["Close"].rolling(window=50).mean()
# Log Volume
df["Log_Volume"] = np.log(df["Volume"] + 1)
df = df.dropna()
return df
def classify_signal(predicted_change: float) -> str:
if predicted_change > 1.0:
return "STRONG BUY"
if predicted_change > 0:
return "BUY"
if predicted_change < -1.0:
return "STRONG SELL"
if predicted_change < 0:
return "SELL"
return "HOLD"
def classify_volatility(df: pd.DataFrame) -> str:
returns = df["Close"].pct_change().dropna()
vol = returns.std()
if vol < 0.01:
return "Low"
if vol < 0.025:
return "Medium"
return "High"
|