ymo2017 commited on
Commit
bdbbbd7
·
verified ·
1 Parent(s): cae75a7

Upload folder using huggingface_hub

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitignore +0 -3
  2. Dockerfile +0 -3
  3. dashboard/api.py +53 -23
  4. dashboard/static/app.js +50 -6
  5. data/AAPL_20y_prices.csv +0 -0
  6. data/AGG_20y_prices.csv +0 -0
  7. data/AMZN_20y_prices.csv +0 -0
  8. data/BIL_20y_prices.csv +0 -0
  9. data/BND_20y_prices.csv +0 -0
  10. data/CIEN_20y_prices.csv +0 -0
  11. data/CNQ_20y_prices.csv +0 -0
  12. data/COHR_20y_prices.csv +0 -0
  13. data/DBC_20y_prices.csv +0 -0
  14. data/EEM_20y_prices.csv +0 -0
  15. data/EFA_20y_prices.csv +0 -0
  16. data/EWL_20y_prices.csv +0 -0
  17. data/EWT_20y_prices.csv +0 -0
  18. data/EWW_20y_prices.csv +0 -0
  19. data/EWY_20y_prices.csv +0 -0
  20. data/EWZ_20y_prices.csv +0 -0
  21. data/E_20y_prices.csv +0 -0
  22. data/GLD_20y_prices.csv +0 -0
  23. data/GOOGL_20y_prices.csv +0 -0
  24. data/GOOG_20y_prices.csv +0 -0
  25. data/HYG_20y_prices.csv +0 -0
  26. data/IEF_20y_prices.csv +0 -0
  27. data/IWM_20y_prices.csv +0 -0
  28. data/IYF_20y_prices.csv +0 -0
  29. data/LQD_20y_prices.csv +0 -0
  30. data/MCHI_20y_prices.csv +0 -0
  31. data/META_20y_prices.csv +0 -0
  32. data/MSFT_20y_prices.csv +0 -0
  33. data/NVDA_20y_prices.csv +0 -0
  34. data/QQQ_20y_prices.csv +0 -0
  35. data/QYLD_20y_prices.csv +0 -0
  36. data/SHY_20y_prices.csv +0 -0
  37. data/SLV_20y_prices.csv +0 -0
  38. data/SMH_20y_prices.csv +0 -0
  39. data/SPY_20y_prices.csv +0 -0
  40. data/SQQQ_20y_prices.csv +0 -0
  41. data/TLT_20y_prices.csv +0 -0
  42. data/TSLA_20y_prices.csv +0 -0
  43. data/TSM_20y_prices.csv +0 -0
  44. data/USO_20y_prices.csv +0 -0
  45. data/VCR_20y_prices.csv +0 -0
  46. data/VLO_20y_prices.csv +0 -0
  47. data/VNQ_20y_prices.csv +0 -0
  48. data/XBI_20y_prices.csv +0 -0
  49. data/XLE_20y_prices.csv +0 -0
  50. data/XLF_20y_prices.csv +0 -0
.gitignore CHANGED
@@ -32,7 +32,4 @@ tmp/
32
  .Trashes
33
  ehthumbs.db
34
  Thumbs.db
35
- *.pyc
36
- logs/
37
- data/*.csv
38
  .env
 
32
  .Trashes
33
  ehthumbs.db
34
  Thumbs.db
 
 
 
35
  .env
Dockerfile CHANGED
@@ -11,9 +11,6 @@ RUN pip install --no-cache-dir -r requirements.txt
11
  # Copy application files and necessary subdirectories
12
  COPY . .
13
 
14
- # Download the ETF market data inside the container (since it's in .gitignore)
15
- RUN python download_etf_data.py
16
-
17
  # Expose Hugging Face Space default port
18
  EXPOSE 7860
19
 
 
11
  # Copy application files and necessary subdirectories
12
  COPY . .
13
 
 
 
 
14
  # Expose Hugging Face Space default port
15
  EXPOSE 7860
16
 
dashboard/api.py CHANGED
@@ -3,7 +3,8 @@ import io
3
  import contextlib
4
  import json
5
  import re
6
- from fastapi import FastAPI
 
7
  from fastapi.staticfiles import StaticFiles
8
  from fastapi.responses import HTMLResponse
9
  import markdown
@@ -19,6 +20,13 @@ app = FastAPI(title="Jumper Trading Dashboard")
19
  # Mount static files
20
  app.mount("/static", StaticFiles(directory="dashboard/static"), name="static")
21
 
 
 
 
 
 
 
 
22
  @app.get("/", response_class=HTMLResponse)
23
  async def read_index():
24
  with open("dashboard/static/index.html", "r") as f:
@@ -35,7 +43,6 @@ async def get_events():
35
  with open(events_path, "r") as f:
36
  lines = f.readlines()
37
 
38
- # Find table start
39
  table_started = False
40
  headers = []
41
 
@@ -46,7 +53,6 @@ async def get_events():
46
 
47
  if line.startswith("|") and not table_started:
48
  if "Date" in line and "Event" in line:
49
- # Header row
50
  headers = [h.strip() for h in line.split("|") if h.strip()]
51
  table_started = True
52
  continue
@@ -57,11 +63,9 @@ async def get_events():
57
  if line.startswith("|") and table_started:
58
  cells = [c.strip() for c in line.split("|")]
59
  if len(cells) > 2:
60
- cells = cells[1:-1] # Remove empty first/last from split
61
-
62
  if len(cells) == len(headers):
63
  event_dict = dict(zip(headers, cells))
64
- # Clean up some markdown artifacts from values
65
  for k, v in event_dict.items():
66
  v = v.replace("**", "").replace("🍁", "🔴").replace("🌲", "🟢")
67
  event_dict[k] = v.strip()
@@ -70,17 +74,14 @@ async def get_events():
70
  return {"events": events}
71
 
72
  @app.get("/api/live")
73
- async def get_live_data():
74
  """Run the live signals logic and return structured JSON."""
75
- # We will temporarily hijack stdout to run get_live_signals.main()
76
- # to avoid modifying the complex main file, then parse the output.
77
- # Alternatively, we could refactor it.
78
 
79
- # Actually, let's do a direct calculation reusing the lib logic,
80
- # or just parse the output of get_live_signals.py for now.
81
 
82
  f = io.StringIO()
83
- # Mock sys.argv to run main without args
84
  old_argv = sys.argv
85
  sys.argv = ["get_live_signals.py"]
86
 
@@ -94,18 +95,20 @@ async def get_live_data():
94
  sys.argv = old_argv
95
  output = f.getvalue()
96
 
97
- # Parse the output table into JSON
98
  lines = output.split('\n')
99
 
100
- prices = []
101
  history = []
102
  policies = []
 
103
  scores = []
104
 
105
  parsing_mode = None
106
 
 
 
107
  def strip_ansi(s):
108
- return re.sub(r'\x1b\[[0-9;]*m', '', s).strip()
109
 
110
  try:
111
  for i, line in enumerate(lines):
@@ -125,22 +128,30 @@ async def get_live_data():
125
  continue
126
  elif "------------------------------------------" in clean_line or "---" in clean_line:
127
  if parsing_mode == "policies" and "ID |" not in clean_line:
128
- pass # Ignore separator
 
 
 
 
 
129
  continue
130
 
131
- if parsing_mode == "momentum" and "|" in clean_line and "Ticker" not in clean_line:
132
  parts = [p.strip() for p in clean_line.split("|") if p.strip()]
133
- if len(parts) >= 3:
 
 
 
 
134
  history.append({
135
  "ticker": parts[0],
136
  "data": parts[1:]
137
  })
138
 
139
  elif parsing_mode == "policies" and "|" in clean_line:
140
- # ID | IS_C | OS_V | RV | VROC | LABEL | UNIV | UP || CL | P | T2
141
- if "ID" in clean_line and "IS_C" in clean_line: continue # header
142
  parts = [p.strip() for p in clean_line.split("|")]
143
- parts = [p for p in parts if p] # Remove empty from ||
144
  if len(parts) >= 11:
145
  policies.append({
146
  "id": parts[0],
@@ -155,11 +166,30 @@ async def get_live_data():
155
  "p1": parts[9],
156
  "t2": parts[10]
157
  })
 
 
 
 
 
 
 
 
 
 
158
  except Exception as e:
159
  print(f"Error parsing live data: {e}")
160
 
161
- return {
 
162
  "history": history,
163
  "policies": policies,
 
 
164
  "raw_output": output
165
  }
 
 
 
 
 
 
 
3
  import contextlib
4
  import json
5
  import re
6
+ import time
7
+ from fastapi import FastAPI, Query
8
  from fastapi.staticfiles import StaticFiles
9
  from fastapi.responses import HTMLResponse
10
  import markdown
 
20
  # Mount static files
21
  app.mount("/static", StaticFiles(directory="dashboard/static"), name="static")
22
 
23
+ # Caching for live endpoint (since it takes a long time and uses yfinance)
24
+ CACHE = {
25
+ "live_data": None,
26
+ "live_time": 0
27
+ }
28
+ CACHE_TTL = 300 # 5 minutes default cache
29
+
30
  @app.get("/", response_class=HTMLResponse)
31
  async def read_index():
32
  with open("dashboard/static/index.html", "r") as f:
 
43
  with open(events_path, "r") as f:
44
  lines = f.readlines()
45
 
 
46
  table_started = False
47
  headers = []
48
 
 
53
 
54
  if line.startswith("|") and not table_started:
55
  if "Date" in line and "Event" in line:
 
56
  headers = [h.strip() for h in line.split("|") if h.strip()]
57
  table_started = True
58
  continue
 
63
  if line.startswith("|") and table_started:
64
  cells = [c.strip() for c in line.split("|")]
65
  if len(cells) > 2:
66
+ cells = cells[1:-1]
 
67
  if len(cells) == len(headers):
68
  event_dict = dict(zip(headers, cells))
 
69
  for k, v in event_dict.items():
70
  v = v.replace("**", "").replace("🍁", "🔴").replace("🌲", "🟢")
71
  event_dict[k] = v.strip()
 
74
  return {"events": events}
75
 
76
  @app.get("/api/live")
77
+ async def get_live_data(refresh: bool = False):
78
  """Run the live signals logic and return structured JSON."""
79
+ global CACHE
 
 
80
 
81
+ if not refresh and CACHE["live_data"] and (time.time() - CACHE["live_time"] < CACHE_TTL):
82
+ return CACHE["live_data"]
83
 
84
  f = io.StringIO()
 
85
  old_argv = sys.argv
86
  sys.argv = ["get_live_signals.py"]
87
 
 
95
  sys.argv = old_argv
96
  output = f.getvalue()
97
 
 
98
  lines = output.split('\n')
99
 
100
+ history_headers = []
101
  history = []
102
  policies = []
103
+ scores_headers = []
104
  scores = []
105
 
106
  parsing_mode = None
107
 
108
+ # regex to strip ANSI escape codes safely
109
+ ansi_escape = re.compile(r'\x1b\[.*?m')
110
  def strip_ansi(s):
111
+ return ansi_escape.sub('', s).strip()
112
 
113
  try:
114
  for i, line in enumerate(lines):
 
128
  continue
129
  elif "------------------------------------------" in clean_line or "---" in clean_line:
130
  if parsing_mode == "policies" and "ID |" not in clean_line:
131
+ pass
132
+ # also ignore separator for markdown tables
133
+ if parsing_mode == "scores" and "|:--" in clean_line:
134
+ continue
135
+ if parsing_mode == "momentum" and "|:--" in clean_line:
136
+ continue
137
  continue
138
 
139
+ if parsing_mode == "momentum" and "|" in clean_line:
140
  parts = [p.strip() for p in clean_line.split("|") if p.strip()]
141
+ if not parts: continue
142
+ # Catch the header row implicitly
143
+ if "Ticker" in clean_line and "LIVE" in clean_line:
144
+ history_headers = parts
145
+ elif history_headers and len(parts) >= 3:
146
  history.append({
147
  "ticker": parts[0],
148
  "data": parts[1:]
149
  })
150
 
151
  elif parsing_mode == "policies" and "|" in clean_line:
152
+ if "ID" in clean_line and "IS_C" in clean_line: continue
 
153
  parts = [p.strip() for p in clean_line.split("|")]
154
+ parts = [p for p in parts if p]
155
  if len(parts) >= 11:
156
  policies.append({
157
  "id": parts[0],
 
166
  "p1": parts[9],
167
  "t2": parts[10]
168
  })
169
+
170
+ elif parsing_mode == "scores" and "|" in clean_line:
171
+ parts = [p.strip() for p in clean_line.split("|") if p.strip()]
172
+ if not parts: continue
173
+ if "Metric" in parts[0] or (not scores_headers and len(parts) > 1):
174
+ scores_headers = parts
175
+ elif scores_headers and len(parts) == len(scores_headers):
176
+ row_data = dict(zip(scores_headers, parts))
177
+ scores.append(row_data)
178
+
179
  except Exception as e:
180
  print(f"Error parsing live data: {e}")
181
 
182
+ result = {
183
+ "history_headers": history_headers,
184
  "history": history,
185
  "policies": policies,
186
+ "scores_headers": scores_headers,
187
+ "scores": scores,
188
  "raw_output": output
189
  }
190
+
191
+ # Save to global cache
192
+ CACHE["live_data"] = result
193
+ CACHE["live_time"] = time.time()
194
+
195
+ return result
dashboard/static/app.js CHANGED
@@ -15,7 +15,7 @@ document.addEventListener('DOMContentLoaded', () => {
15
 
16
  // Event Listeners
17
  refreshBtn.addEventListener('click', () => {
18
- if (!isRefreshing) fetchData();
19
  });
20
 
21
  searchInput.addEventListener('input', (e) => {
@@ -27,13 +27,15 @@ document.addEventListener('DOMContentLoaded', () => {
27
  });
28
 
29
  // API calls
30
- async function fetchData() {
31
  setLoading(true);
32
  try {
 
 
33
  // Fetch concurrently
34
  const [eventsRes, liveRes] = await Promise.all([
35
  fetch('/api/events'),
36
- fetch('/api/live')
37
  ]);
38
 
39
  const eventsData = await eventsRes.json();
@@ -65,7 +67,13 @@ document.addEventListener('DOMContentLoaded', () => {
65
  if (data.history && data.history.length > 0) {
66
  html += `<h3 style="margin-bottom: 1rem; color: #fff;">5-Day Price Momentum</h3>`;
67
  html += `<div style="overflow-x: auto; margin-bottom: 2rem;"><table><thead><tr>`;
68
- html += `<th>Ticker</th><th>LIVE / LATEST</th><th>||</th><th>D-1</th><th>D-2</th><th>D-3</th><th>D-4</th><th>D-5</th><th>5D Total</th>`;
 
 
 
 
 
 
69
  html += `</tr></thead><tbody>`;
70
 
71
  data.history.forEach(row => {
@@ -89,7 +97,7 @@ document.addEventListener('DOMContentLoaded', () => {
89
 
90
  if (data.policies && data.policies.length > 0) {
91
  html += `<h3 style="margin-bottom: 1rem; color: #fff;">Live Policy Weights</h3>`;
92
- html += `<div style="overflow-x: auto;"><table><thead><tr>`;
93
  html += `<th>ID</th><th>CAGR</th><th>VOL</th><th>RV</th><th>VROC</th><th>Label</th><th>Universe</th><th>Upcoming (T+1)</th><th>||</th><th>Closed (T)</th><th>T-1</th><th>T-2</th>`;
94
  html += `</tr></thead><tbody>`;
95
 
@@ -112,7 +120,43 @@ document.addEventListener('DOMContentLoaded', () => {
112
  html += `</tbody></table></div>`;
113
  }
114
 
115
- // Fallback to raw output if parsing failed or array is empty
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  if ((!data.policies || data.policies.length === 0) && data.raw_output) {
117
  html += `<pre>${data.raw_output}</pre>`;
118
  }
 
15
 
16
  // Event Listeners
17
  refreshBtn.addEventListener('click', () => {
18
+ if (!isRefreshing) fetchData(true);
19
  });
20
 
21
  searchInput.addEventListener('input', (e) => {
 
27
  });
28
 
29
  // API calls
30
+ async function fetchData(forceRefresh = false) {
31
  setLoading(true);
32
  try {
33
+ const liveUrl = forceRefresh ? '/api/live?refresh=1' : '/api/live';
34
+
35
  // Fetch concurrently
36
  const [eventsRes, liveRes] = await Promise.all([
37
  fetch('/api/events'),
38
+ fetch(liveUrl)
39
  ]);
40
 
41
  const eventsData = await eventsRes.json();
 
67
  if (data.history && data.history.length > 0) {
68
  html += `<h3 style="margin-bottom: 1rem; color: #fff;">5-Day Price Momentum</h3>`;
69
  html += `<div style="overflow-x: auto; margin-bottom: 2rem;"><table><thead><tr>`;
70
+
71
+ // Dynamically render headers if we have them
72
+ if (data.history_headers && data.history_headers.length > 0) {
73
+ data.history_headers.forEach(h => html += `<th>${h}</th>`);
74
+ } else {
75
+ html += `<th>Ticker</th><th>LIVE / LATEST</th><th>||</th><th>D-1</th><th>D-2</th><th>D-3</th><th>D-4</th><th>D-5</th><th>5D Total</th>`;
76
+ }
77
  html += `</tr></thead><tbody>`;
78
 
79
  data.history.forEach(row => {
 
97
 
98
  if (data.policies && data.policies.length > 0) {
99
  html += `<h3 style="margin-bottom: 1rem; color: #fff;">Live Policy Weights</h3>`;
100
+ html += `<div style="overflow-x: auto; margin-bottom: 2rem;"><table><thead><tr>`;
101
  html += `<th>ID</th><th>CAGR</th><th>VOL</th><th>RV</th><th>VROC</th><th>Label</th><th>Universe</th><th>Upcoming (T+1)</th><th>||</th><th>Closed (T)</th><th>T-1</th><th>T-2</th>`;
102
  html += `</tr></thead><tbody>`;
103
 
 
120
  html += `</tbody></table></div>`;
121
  }
122
 
123
+ if (data.scores && data.scores.length > 0) {
124
+ html += `<h3 style="margin-bottom: 1rem; color: #fff;">Live Scores (Scaled 1K)</h3>`;
125
+ html += `<div style="overflow-x: auto; margin-bottom: 2rem;"><table><thead><tr>`;
126
+
127
+ // Render Score Headers
128
+ if (data.scores_headers && data.scores_headers.length > 0) {
129
+ data.scores_headers.forEach(h => html += `<th>${h}</th>`);
130
+ }
131
+ html += `</tr></thead><tbody>`;
132
+
133
+ data.scores.forEach(row => {
134
+ // Ignore header row if it slipped into data
135
+ if (row["Metric"] === "Metric") return;
136
+
137
+ html += `<tr>`;
138
+ // Iterate through headers to ensure order
139
+ data.scores_headers.forEach(h => {
140
+ let cellVal = row[h] || "";
141
+ let cssClass = "";
142
+ if (h === "Metric") cssClass = "cell-bold cell-muted";
143
+
144
+ // Simple logic for coloring based on text content (backend provides some visual cues but HTML renders text)
145
+ if (cellVal.startsWith("-")) cssClass = "cell-red";
146
+ // If it's a numeric positive value that might be highlighted, we could check for bold or just leave as is since backend stripped ANSI.
147
+ // Let's at least highlight positive numbers slightly
148
+ if (!isNaN(parseFloat(cellVal)) && parseFloat(cellVal) > 0 && h !== "Metric") {
149
+ cssClass = "cell-green";
150
+ }
151
+
152
+ html += `<td class="${cssClass}">${cellVal}</td>`;
153
+ });
154
+ html += `</tr>`;
155
+ });
156
+ html += `</tbody></table></div>`;
157
+ }
158
+
159
+ // Fallback to raw output if parsing failed entirely
160
  if ((!data.policies || data.policies.length === 0) && data.raw_output) {
161
  html += `<pre>${data.raw_output}</pre>`;
162
  }
data/AAPL_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/AGG_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/AMZN_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/BIL_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/BND_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/CIEN_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/CNQ_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/COHR_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/DBC_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/EEM_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/EFA_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/EWL_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/EWT_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/EWW_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/EWY_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/EWZ_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/E_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/GLD_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/GOOGL_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/GOOG_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/HYG_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/IEF_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/IWM_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/IYF_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/LQD_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/MCHI_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/META_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/MSFT_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/NVDA_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/QQQ_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/QYLD_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/SHY_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/SLV_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/SMH_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/SPY_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/SQQQ_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/TLT_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/TSLA_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/TSM_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/USO_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/VCR_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/VLO_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/VNQ_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/XBI_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/XLE_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/XLF_20y_prices.csv ADDED
The diff for this file is too large to render. See raw diff