Geek7 commited on
Commit
34c23a9
·
verified ·
1 Parent(s): da17162

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py CHANGED
@@ -71,5 +71,68 @@ def main():
71
  rsi_signals = strategic_signals.get_rsi_signals()
72
  st.write(rsi_signals)
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  if __name__ == "__main__":
75
  main()
 
71
  rsi_signals = strategic_signals.get_rsi_signals()
72
  st.write(rsi_signals)
73
 
74
+ if __name__ == "__main__":
75
+ main()
76
+
77
+
78
+
79
+ def fetch_alpha_vantage_data(api_key, symbol):
80
+ url = f'https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol={symbol}&interval=5min&apikey={api_key}'
81
+ response = requests.get(url)
82
+ alpha_vantage_data = response.json()
83
+ return alpha_vantage_data
84
+
85
+ def calculate_indicators(data):
86
+ # Convert all columns to numeric
87
+ data = data.apply(pd.to_numeric, errors='coerce')
88
+
89
+ # Example: Simple condition for doji and inside
90
+ data['Doji'] = abs(data['close'] - data['open']) <= 0.01 * (data['high'] - data['low'])
91
+ data['Inside'] = (data['high'] < data['high'].shift(1)) & (data['low'] > data['low'].shift(1))
92
+ return data
93
+
94
+ def main():
95
+ st.title("AI Stock Trend Predictor")
96
+
97
+ # User input for stock symbol
98
+ symbol = st.text_input("Enter Stock Symbol (e.g., IBM):")
99
+
100
+ if not symbol:
101
+ st.warning("Please enter a valid stock symbol.")
102
+ st.stop()
103
+
104
+ # Use the hard-coded API key
105
+ api_key = API_KEY
106
+
107
+ # Fetch Alpha Vantage data
108
+ alpha_vantage_data = fetch_alpha_vantage_data(api_key, symbol)
109
+
110
+ # Extract relevant data from Alpha Vantage response
111
+ alpha_vantage_time_series = alpha_vantage_data.get('Time Series (5min)', {})
112
+ df = pd.DataFrame(alpha_vantage_time_series).T
113
+ df.index = pd.to_datetime(df.index)
114
+ df = df.dropna(axis=0)
115
+
116
+ # Rename columns
117
+ df = df.rename(columns={'1. open': 'open', '2. high': 'high', '3. low': 'low', '4. close': 'close', '5. volume': 'volume'})
118
+
119
+ # Calculate indicators
120
+ df = calculate_indicators(df)
121
+
122
+ # Create predictor
123
+ my_market_predictor = Pandas_Market_Predictor(df)
124
+
125
+ # Predict Trend
126
+ indicators = ["Doji", "Inside"]
127
+ trend = my_market_predictor.Trend_Detection(indicators, 10)
128
+
129
+ # Display results
130
+ st.subheader("Predicted Trend:")
131
+ st.write("Buy Trend :", trend['BUY'])
132
+ st.write("Sell Trend :", trend['SELL'])
133
+
134
+ # Delete the DataFrame to release memory
135
+ del df
136
+
137
  if __name__ == "__main__":
138
  main()