Spaces:
Runtime error
Runtime error
Ken Sang Tang commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,10 +38,19 @@ def fetch_stock_data(symbol, start_date, end_date):
|
|
| 38 |
# Step 2: Add Technical Indicators
|
| 39 |
def add_technical_indicators(data):
|
| 40 |
print("Adding technical indicators...")
|
|
|
|
| 41 |
data['RSI'] = ta.rsi(data['Close'], length=14)
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
return data
|
| 46 |
|
| 47 |
# Step 3: Analyze Sentiment using FinBERT
|
|
|
|
| 38 |
# Step 2: Add Technical Indicators
|
| 39 |
def add_technical_indicators(data):
|
| 40 |
print("Adding technical indicators...")
|
| 41 |
+
# Compute RSI
|
| 42 |
data['RSI'] = ta.rsi(data['Close'], length=14)
|
| 43 |
+
|
| 44 |
+
# Compute MACD (usually generates three columns: MACD, MACD_Signal, MACD_Histogram)
|
| 45 |
+
macd = ta.macd(data['Close'], fast=12, slow=26, signal=9)
|
| 46 |
+
data['MACD'] = macd['MACD_12_26_9']
|
| 47 |
+
|
| 48 |
+
# Compute Bollinger Bands
|
| 49 |
+
bbands = ta.bbands(data['Close'], length=20, std=2.0)
|
| 50 |
+
data['BB_upper'] = bbands[f'BBU_20_2.0'] if f'BBU_20_2.0' in bbands.columns else bbands.iloc[:, 0]
|
| 51 |
+
data['BB_middle'] = bbands[f'BBM_20_2.0'] if f'BBM_20_2.0' in bbands.columns else bbands.iloc[:, 1]
|
| 52 |
+
data['BB_lower'] = bbands[f'BBL_20_2.0'] if f'BBL_20_2.0' in bbands.columns else bbands.iloc[:, 2]
|
| 53 |
+
|
| 54 |
return data
|
| 55 |
|
| 56 |
# Step 3: Analyze Sentiment using FinBERT
|