Geek7 commited on
Commit
3abff25
·
verified ·
1 Parent(s): 90fc592

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -13
app.py CHANGED
@@ -6,11 +6,15 @@ from datetime import datetime, timedelta
6
  import pytz
7
 
8
 
9
- # Function to fetch historical stock data using yfinance
10
- def fetch_stock_data(ticker, start_date, end_date):
11
- stock_data = yf.download(ticker, start=start_date, end=end_date)
 
 
12
  return stock_data
13
 
 
 
14
  # Function to detect head and shoulder patterns
15
  def detect_head_shoulder(df, window=3):
16
  roll_window = window
@@ -204,19 +208,20 @@ def main():
204
  start_date = st.date_input('Start Date', pd.to_datetime('2020-01-01'))
205
  end_date = st.date_input('End Date', pd.to_datetime('2022-01-01'))
206
 
207
- preferred_timezone = st.timezone_input('Select Preferred Timezone', pytz.UTC)
 
 
 
 
208
 
209
- start_datetime = st.time_input('Select Start Time', datetime(2022, 1, 1, 0, 0))
210
- end_datetime = st.time_input('Select End Time', datetime(2022, 1, 1, 23, 59))
211
 
212
- start_datetime = datetime.combine(start_date, start_datetime.time())
213
- end_datetime = datetime.combine(end_date, end_datetime.time())
214
 
215
- start_datetime = preferred_timezone.localize(start_datetime)
216
- end_datetime = preferred_timezone.localize(end_datetime)
217
-
218
  if st.button('Detect Patterns'):
219
- stock_data = fetch_stock_data(ticker, start_date, end_date)
220
  stock_data = detect_head_shoulder(stock_data)
221
  stock_data = detect_multiple_tops_bottoms(stock_data)
222
  stock_data = calculate_support_resistance(stock_data)
@@ -230,4 +235,5 @@ def main():
230
  st.write(stock_data)
231
 
232
  if __name__ == "__main__":
233
- main()
 
 
6
  import pytz
7
 
8
 
9
+
10
+
11
+ # Function to fetch stock data
12
+ def fetch_stock_data(ticker, start_datetime, end_datetime):
13
+ stock_data = yf.download(ticker, start=start_datetime, end=end_datetime)
14
  return stock_data
15
 
16
+
17
+
18
  # Function to detect head and shoulder patterns
19
  def detect_head_shoulder(df, window=3):
20
  roll_window = window
 
208
  start_date = st.date_input('Start Date', pd.to_datetime('2020-01-01'))
209
  end_date = st.date_input('End Date', pd.to_datetime('2022-01-01'))
210
 
211
+ st.info("Select Preferred Timezone:")
212
+ preferred_timezone = st.selectbox('Timezone', list(pytz.all_timezones))
213
+
214
+ start_time = st.time_input('Select Start Time', datetime(2022, 1, 1, 0, 0))
215
+ end_time = st.time_input('Select End Time', datetime(2022, 1, 1, 23, 59))
216
 
217
+ start_datetime = datetime.combine(start_date, start_time)
218
+ end_datetime = datetime.combine(end_date, end_time)
219
 
220
+ start_datetime = pytz.timezone(preferred_timezone).localize(start_datetime)
221
+ end_datetime = pytz.timezone(preferred_timezone).localize(end_datetime)
222
 
 
 
 
223
  if st.button('Detect Patterns'):
224
+ stock_data = fetch_stock_data(ticker, start_datetime, end_datetime)
225
  stock_data = detect_head_shoulder(stock_data)
226
  stock_data = detect_multiple_tops_bottoms(stock_data)
227
  stock_data = calculate_support_resistance(stock_data)
 
235
  st.write(stock_data)
236
 
237
  if __name__ == "__main__":
238
+ main()
239
+