Ken Sang Tang commited on
Commit
83d6aef
·
verified ·
1 Parent(s): 23fda02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -118,6 +118,11 @@ def main():
118
  try:
119
  # 1. Fetch and Prepare Data
120
  klci_data = fetch_stock_data(SYMBOL, START_DATE, END_DATE)
 
 
 
 
 
121
 
122
  # 2. Run FinBERT Sentiment Analysis
123
  sample_text = "The market sentiment is bullish for KLCI." # Example text
@@ -129,7 +134,11 @@ def main():
129
  available_columns = [col for col in indicators if col in klci_data.columns]
130
  indicator_data = klci_data[available_columns].iloc[-1].to_dict()
131
 
132
- prompt = f"The market trend for KLCI with sentiment {sentiment} and indicators {klci_data[['RSI', 'MACD', 'BB_upper', 'BB_middle', 'BB_lower']].iloc[-1].to_dict()}"
 
 
 
 
133
  prediction = generate_prediction(prompt)
134
  print(f"Dolly Prediction: {prediction}")
135
 
@@ -142,7 +151,8 @@ def main():
142
  print("No clear trade signal from prediction.")
143
 
144
  # 5. Plot KLCI Data with Indicators
145
- plot_klci(klci_data)
 
146
 
147
  except Exception as e:
148
  print (f"An error occured: {e}")
 
118
  try:
119
  # 1. Fetch and Prepare Data
120
  klci_data = fetch_stock_data(SYMBOL, START_DATE, END_DATE)
121
+
122
+ # Ensure columns for Bollinger Bands exist before referencing them
123
+ bb_columns = ['BB_upper', 'BB_middle', 'BB_lower']
124
+ available_columns = [col for col in bb_columns if col in klci_data.columns]
125
+
126
 
127
  # 2. Run FinBERT Sentiment Analysis
128
  sample_text = "The market sentiment is bullish for KLCI." # Example text
 
134
  available_columns = [col for col in indicators if col in klci_data.columns]
135
  indicator_data = klci_data[available_columns].iloc[-1].to_dict()
136
 
137
+ if available_columns:
138
+ prompt = f"The market trend for KLCI with sentiment {sentiment} and indicators {klci_data[['RSI', 'MACD'] + available_columns].iloc[-1].to_dict()}"
139
+ else:
140
+ prompt = f"The market trend for KLCI with sentiment {sentiment} and indicators {klci_data[['RSI', 'MACD']].iloc[-1].to_dict()}"
141
+
142
  prediction = generate_prediction(prompt)
143
  print(f"Dolly Prediction: {prediction}")
144
 
 
151
  print("No clear trade signal from prediction.")
152
 
153
  # 5. Plot KLCI Data with Indicators
154
+ if available_columns:
155
+ plot_klci(klci_data)
156
 
157
  except Exception as e:
158
  print (f"An error occured: {e}")