wnstnb commited on
Commit
4bbaf7b
ยท
1 Parent(s): cf3cfd9

added auto mode

Browse files
Files changed (2) hide show
  1. app.py +39 -16
  2. troubleshoot_day_model.ipynb +47 -0
app.py CHANGED
@@ -47,45 +47,66 @@ def get_time_emojis(_times, _pst_now):
47
  pst_now_time = pst_now.time()
48
  us_holidays = get_us_holidays()
49
  emojis = []
 
50
 
51
  for t in _times:
52
  time_obj = convert_to_datetime(t, _pst_now)
53
 
54
  # Check if the time is less than or equal to the current time in PST
55
  if time_obj.time() <= pst_now_time:
 
56
  emoji = "โœ…"
 
57
  else:
58
  # Check if it's a business day or a holiday
59
  if is_business_day(time_obj) or time_obj.date() in us_holidays:
 
60
  emoji = "โ›”"
61
  else:
 
62
  emoji = "โœ…"
63
 
64
  emojis.append(emoji)
65
 
66
- return emojis
67
 
68
  # Example usage:
69
  times_list = ['06:30', '07:00', '07:30', '08:00', '08:30', '09:00', '09:30', '10:00', '10:30', '11:00', '11:30', '12:00', '12:30']
70
- emojis_list = get_time_emojis(times_list, pst_now)
71
-
72
 
73
  st.title('๐ŸŽฎ Gameday Model for $SPX')
74
  st.markdown('**PLEASE NOTE:** Model should be run at or after market open. Documentation on the model and its features [can be found here.](https://huggingface.co/spaces/boomsss/gamedayspx/blob/main/README.md)')
75
- with st.form("choose_model"):
76
 
77
- col1, col2 = st.columns(2)
78
-
79
- with col1:
80
- option = st.select_slider(
81
- f"""Slide the scale based on PST, then run.""",
82
- times_list,
83
- format_func=lambda x: f"{emojis_list[times_list.index(x)]} {x}"
84
- )
85
 
86
- with col2:
 
 
 
 
87
  submitted = st.form_submit_button('๐Ÿƒ๐Ÿฝโ€โ™‚๏ธ Run',use_container_width=True)
88
- cleared = st.form_submit_button('๐Ÿงน Clear All',use_container_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
90
  if cleared:
91
  st.cache_data.clear()
@@ -313,6 +334,8 @@ with st.form("choose_model"):
313
 
314
  prev_close = data.loc[final_row,'Close']
315
  curr_close = data['Close'].iloc[-1]
 
 
316
 
317
  # confidence, success, nn = st.columns(3)
318
 
@@ -342,13 +365,13 @@ with st.form("choose_model"):
342
 
343
  targets = pd.DataFrame(
344
  index=[
345
- f'Curr ({(curr_close / prev_close) - 1:.2%})',
346
  f'Low ({lo})',
347
  f'Mid ({mid})',
348
  f'High ({hi})'
349
  ],
350
  data=[
351
- [f"{curr_close:.0f}"],
352
  [f"{(1+float(lo.strip('%'))/100) * prev_close:.0f}"],
353
  [f"{(1+float(mid.strip('%'))/100) * prev_close:.0f}"],
354
  [f"{(1+float(hi.strip('%'))/100) * prev_close :.0f}"]
 
47
  pst_now_time = pst_now.time()
48
  us_holidays = get_us_holidays()
49
  emojis = []
50
+ idxs = []
51
 
52
  for t in _times:
53
  time_obj = convert_to_datetime(t, _pst_now)
54
 
55
  # Check if the time is less than or equal to the current time in PST
56
  if time_obj.time() <= pst_now_time:
57
+ idxs.append(True)
58
  emoji = "โœ…"
59
+
60
  else:
61
  # Check if it's a business day or a holiday
62
  if is_business_day(time_obj) or time_obj.date() in us_holidays:
63
+ idxs.append(False)
64
  emoji = "โ›”"
65
  else:
66
+ idxs.append(True)
67
  emoji = "โœ…"
68
 
69
  emojis.append(emoji)
70
 
71
+ return emojis, idxs
72
 
73
  # Example usage:
74
  times_list = ['06:30', '07:00', '07:30', '08:00', '08:30', '09:00', '09:30', '10:00', '10:30', '11:00', '11:30', '12:00', '12:30']
75
+ emojis_list, idxs = get_time_emojis(times_list, pst_now)
76
+ idx_use = len(idxs) - 1 - idxs[::-1].index(True)
77
 
78
  st.title('๐ŸŽฎ Gameday Model for $SPX')
79
  st.markdown('**PLEASE NOTE:** Model should be run at or after market open. Documentation on the model and its features [can be found here.](https://huggingface.co/spaces/boomsss/gamedayspx/blob/main/README.md)')
 
80
 
81
+ if "mode" not in st.session_state:
82
+ st.session_state.mode = "Auto"
 
 
 
 
 
 
83
 
84
+ with st.form("choose_model"):
85
+ t1, t2 = st.columns(2)
86
+ with t1:
87
+ mode = st.radio('Choose mode', options=['Auto','Manual'], horizontal=True)
88
+ with t2:
89
  submitted = st.form_submit_button('๐Ÿƒ๐Ÿฝโ€โ™‚๏ธ Run',use_container_width=True)
90
+ sub1, sub2 = st.columns(2)
91
+ with sub1:
92
+ change_mode = st.form_submit_button('๐Ÿ‘Š๐Ÿฝ Change Mode',use_container_width=True)
93
+ with sub2:
94
+ cleared = st.form_submit_button('๐Ÿงน Clear',use_container_width=True)
95
+
96
+ option = st.select_slider(
97
+ f"""Change mode to Manual, and select time ๐Ÿ‘‰๐Ÿฝ Run.""",
98
+ times_list,
99
+ format_func=lambda x: f"{emojis_list[times_list.index(x)]} {x}",
100
+ disabled = mode == 'Auto'
101
+ )
102
+
103
+ if mode == 'Auto':
104
+ option = times_list[idx_use]
105
+ else:
106
+ option = option
107
+
108
+ if change_mode:
109
+ st.write(f'Changed to {mode}')
110
 
111
  if cleared:
112
  st.cache_data.clear()
 
334
 
335
  prev_close = data.loc[final_row,'Close']
336
  curr_close = data['Close'].iloc[-1]
337
+ curr_open = data['Open'].iloc[-1]
338
+ curr_close30 = curr_open if option == '06:30' else data['CurrentClose30'].iloc[-2]
339
 
340
  # confidence, success, nn = st.columns(3)
341
 
 
365
 
366
  targets = pd.DataFrame(
367
  index=[
368
+ f'Close @ {option} ({(curr_close30 / prev_close) - 1:.2%})',
369
  f'Low ({lo})',
370
  f'Mid ({mid})',
371
  f'High ({hi})'
372
  ],
373
  data=[
374
+ [f"{curr_close30:.0f}"],
375
  [f"{(1+float(lo.strip('%'))/100) * prev_close:.0f}"],
376
  [f"{(1+float(mid.strip('%'))/100) * prev_close:.0f}"],
377
  [f"{(1+float(hi.strip('%'))/100) * prev_close :.0f}"]
troubleshoot_day_model.ipynb CHANGED
@@ -67,6 +67,53 @@
67
  "data['H2BreakTouchPct'] = data['L2Break'].expanding().sum() / data['L2Touch'].expanding().sum()"
68
  ]
69
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  {
71
  "cell_type": "code",
72
  "execution_count": 37,
 
67
  "data['H2BreakTouchPct'] = data['L2Break'].expanding().sum() / data['L2Touch'].expanding().sum()"
68
  ]
69
  },
70
+ {
71
+ "cell_type": "code",
72
+ "execution_count": 4,
73
+ "metadata": {},
74
+ "outputs": [],
75
+ "source": [
76
+ "l = [True, True, True, False, False,False,False,False]"
77
+ ]
78
+ },
79
+ {
80
+ "cell_type": "code",
81
+ "execution_count": 7,
82
+ "metadata": {},
83
+ "outputs": [],
84
+ "source": [
85
+ "place = len(l) - 1 - l[::-1].index(True)"
86
+ ]
87
+ },
88
+ {
89
+ "cell_type": "code",
90
+ "execution_count": 8,
91
+ "metadata": {},
92
+ "outputs": [],
93
+ "source": [
94
+ "z = ['a','b','c','d','e']"
95
+ ]
96
+ },
97
+ {
98
+ "cell_type": "code",
99
+ "execution_count": 9,
100
+ "metadata": {},
101
+ "outputs": [
102
+ {
103
+ "data": {
104
+ "text/plain": [
105
+ "'c'"
106
+ ]
107
+ },
108
+ "execution_count": 9,
109
+ "metadata": {},
110
+ "output_type": "execute_result"
111
+ }
112
+ ],
113
+ "source": [
114
+ "z[place]"
115
+ ]
116
+ },
117
  {
118
  "cell_type": "code",
119
  "execution_count": 37,