Arrechenash commited on
Commit
1ffdfdb
·
1 Parent(s): 334125b

feat: Add more filters to the dashboard

Browse files

Adds the ability to filter by:

- Minimum open price
- Minimum volume
- Minimum relative volume

Files changed (1) hide show
  1. src/streamlit_app.py +30 -7
src/streamlit_app.py CHANGED
@@ -1,35 +1,52 @@
1
  import os
2
- import streamlit as st
3
  import duckdb
 
4
 
5
  st.set_page_config(page_title="Stocks Dashboard", layout="wide")
6
 
7
  url = "hf://datasets/Arrechenash/stocks@~parquet/**/*.parquet"
8
-
9
  if os.getenv("APP_ENV") == "development":
10
  url = "stocks.parquet"
11
 
12
  st.title("Stocks Dashboard")
13
 
 
14
  @st.cache_data
15
  def load_symbols():
16
- df = duckdb.query(f"SELECT DISTINCT symbol FROM read_parquet('{url}') ORDER BY symbol").to_df()
17
- return df['symbol'].tolist()
 
 
 
18
 
19
  symbol_options = load_symbols()
20
 
21
- col1, col2, col3, col4 = st.columns(4)
22
 
23
  with col1:
24
- selected_date = st.date_input("Select date (optional)", value=None, key="date", label_visibility="visible")
 
 
25
 
26
  with col2:
27
  selected_symbols = st.multiselect("Select symbol(s) (optional):", symbol_options)
28
 
29
  with col3:
30
- min_gap_pct = st.number_input("Min gap % (optional):", value=None, format="%.2f")
31
 
32
  with col4:
 
 
 
 
 
 
 
 
 
 
 
33
  min_run_pct = st.number_input("Min run % (optional):", value=None, format="%.2f")
34
 
35
  filters = []
@@ -38,6 +55,12 @@ if selected_date:
38
  if selected_symbols:
39
  symbols = "', '".join(selected_symbols)
40
  filters.append(f"symbol IN ('{symbols}')")
 
 
 
 
 
 
41
  if min_gap_pct is not None:
42
  filters.append(f"gap_pct >= {min_gap_pct}")
43
  if min_run_pct is not None:
 
1
  import os
2
+
3
  import duckdb
4
+ import streamlit as st
5
 
6
  st.set_page_config(page_title="Stocks Dashboard", layout="wide")
7
 
8
  url = "hf://datasets/Arrechenash/stocks@~parquet/**/*.parquet"
 
9
  if os.getenv("APP_ENV") == "development":
10
  url = "stocks.parquet"
11
 
12
  st.title("Stocks Dashboard")
13
 
14
+
15
  @st.cache_data
16
  def load_symbols():
17
+ df = duckdb.query(
18
+ f"SELECT DISTINCT symbol FROM read_parquet('{url}') ORDER BY symbol"
19
+ ).to_df()
20
+ return df["symbol"].tolist()
21
+
22
 
23
  symbol_options = load_symbols()
24
 
25
+ col1, col2, col3, col4, col5, col6, col7 = st.columns(7)
26
 
27
  with col1:
28
+ selected_date = st.date_input(
29
+ "Select date (optional)", value=None, key="date", label_visibility="visible"
30
+ )
31
 
32
  with col2:
33
  selected_symbols = st.multiselect("Select symbol(s) (optional):", symbol_options)
34
 
35
  with col3:
36
+ min_open = st.number_input("Min open price (optional):", value=1.0, format="%.2f")
37
 
38
  with col4:
39
+ min_vol = st.number_input("Min volume (optional):", value=10_000.0, format="%.2f")
40
+
41
+ with col5:
42
+ min_relvol = st.number_input(
43
+ "Min relative volume (optional):", value=5.0, format="%.2f"
44
+ )
45
+
46
+ with col6:
47
+ min_gap_pct = st.number_input("Min gap % (optional):", value=None, format="%.2f")
48
+
49
+ with col7:
50
  min_run_pct = st.number_input("Min run % (optional):", value=None, format="%.2f")
51
 
52
  filters = []
 
55
  if selected_symbols:
56
  symbols = "', '".join(selected_symbols)
57
  filters.append(f"symbol IN ('{symbols}')")
58
+ if min_open is not None:
59
+ filters.append(f"open >= {min_open}")
60
+ if min_vol is not None:
61
+ filters.append(f"volume >= {min_vol}")
62
+ if min_relvol is not None:
63
+ filters.append(f"relative_volume >= {min_relvol}")
64
  if min_gap_pct is not None:
65
  filters.append(f"gap_pct >= {min_gap_pct}")
66
  if min_run_pct is not None: