Ken Sang Tang commited on
Commit
3a949ee
·
verified ·
1 Parent(s): 9600abf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
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
- data['MACD'] = ta.macd(data['Close'], fast=12, slow=26)['MACD_12_26_9']
43
- bbands = ta.bbands(data['Close'])
44
- data['BB_upper'], data['BB_middle'], data['BB_lower'] = bbands['BBU_20_2.0'], bbands['BBM_20_2.0'], bbands['BBL_20_2.0']
 
 
 
 
 
 
 
 
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