therickglenn commited on
Commit
fde3666
·
verified ·
1 Parent(s): 8fde4ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -30
app.py CHANGED
@@ -127,21 +127,21 @@ def download_data(tickers, start_date, end_date, interval, output_dir):
127
  """
128
  downloaded = []
129
  os.makedirs(output_dir, exist_ok=True)
130
- for ticker in tickers:
131
- st.info(f"Downloading data for {ticker}...")
 
132
  try:
133
  stock = yf.Ticker(ticker)
134
  data = stock.history(
135
  start=start_date, end=end_date, interval=interval)
136
- if data.empty:
137
- st.warning(f"No data returned for {ticker}. Skipping.")
138
- continue
139
- output_file = os.path.join(output_dir, f"{ticker}.csv")
140
- data.to_csv(output_file)
141
- downloaded.append(ticker)
142
- st.success(f"Saved data for {ticker} to {output_file}")
143
- except Exception as e:
144
- st.error(f"Error downloading data for {ticker}: {e}")
145
  return downloaded
146
 
147
  # -----------------------------
@@ -197,22 +197,41 @@ def main():
197
  st.header("Controls")
198
 
199
  # Exclude the "test" group
200
- available_groups = [grp for grp in market_config.get(
201
- 'groups', {}).keys() if grp.lower() != "test"]
202
- # Default to "all" if available, else first available group.
203
- default_group = "all" if "all" in available_groups else available_groups[0]
204
- selected_groups = st.multiselect(
205
- "Select Asset Groups", available_groups, default=[default_group])
206
-
207
- # Build the union of tickers from the selected groups
208
- all_tickers = []
209
- for group in selected_groups:
210
- group_tickers = market_config['groups'][group]
211
- all_tickers.extend(group_tickers)
212
- all_tickers = sorted(set(all_tickers))
213
-
214
- # Select tickers from the combined list
215
- selected_tickers = st.multiselect("Select Tickers", all_tickers)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
 
217
  # Date Range Selection
218
  default_end = date.today()
@@ -475,7 +494,8 @@ def main():
475
  if show_var:
476
  var = predictor.calculate_var(
477
  combined_data[ticker])
478
- st.write(f"Value at Risk (95%) for {ticker}: {var:.2%}")
 
479
  if show_patterns or show_breakouts:
480
  ticker_data = load_ticker_data(output_dir, ticker)
481
  if ticker_data is not None:
@@ -525,8 +545,8 @@ def main():
525
  - Data is downloaded automatically.
526
 
527
  3. **Configure Predictives & Risk Tools** 🤖📊
528
- - Our predictive models combine historical data with real-time market signals to forecast trends—helping you anticipate price movements and spot emerging opportunities.
529
- - Our risk analysis tools compute key metrics like Value at Risk (VaR) and perform stress tests to evaluate potential losses, giving you critical insights into risk exposure.
530
  - Configure these tools to complement your overall technical analysis.
531
 
532
  4. **Enhance Your Analysis with Indicators** ⚙️
 
127
  """
128
  downloaded = []
129
  os.makedirs(output_dir, exist_ok=True)
130
+
131
+ progress_bar = st.progress(0)
132
+ for i, ticker in enumerate(tickers):
133
  try:
134
  stock = yf.Ticker(ticker)
135
  data = stock.history(
136
  start=start_date, end=end_date, interval=interval)
137
+ if not data.empty:
138
+ output_file = os.path.join(output_dir, f"{ticker}.csv")
139
+ data.to_csv(output_file)
140
+ downloaded.append(ticker)
141
+ except Exception:
142
+ pass
143
+ progress_bar.progress((i + 1) / len(tickers))
144
+ progress_bar.empty()
 
145
  return downloaded
146
 
147
  # -----------------------------
 
197
  st.header("Controls")
198
 
199
  # Exclude the "test" group
200
+ # Direct Ticker Input
201
+ ticker_input = st.text_input('Enter Ticker Symbol (e.g., AAPL):')
202
+
203
+ # Optional Asset Group Selection
204
+ use_groups = st.checkbox('Or select from predefined groups')
205
+
206
+ selected_tickers = []
207
+
208
+ if ticker_input:
209
+ selected_tickers.append(ticker_input.upper().strip())
210
+
211
+ if use_groups:
212
+
213
+ available_groups = [grp for grp in market_config.get(
214
+ 'groups', {}).keys() if grp.lower() != "test"]
215
+
216
+ selected_groups = st.multiselect(
217
+ "Select Asset Groups", available_groups)
218
+
219
+ # Build the union of tickers from the selected groups
220
+
221
+ group_tickers = []
222
+
223
+ for group in selected_groups:
224
+
225
+ group_tickers.extend(market_config['groups'][group])
226
+
227
+ group_tickers = sorted(set(group_tickers))
228
+
229
+ if group_tickers:
230
+
231
+ group_selected = st.multiselect(
232
+ "Select Additional Tickers from Groups:", group_tickers)
233
+
234
+ selected_tickers.extend(group_selected)
235
 
236
  # Date Range Selection
237
  default_end = date.today()
 
494
  if show_var:
495
  var = predictor.calculate_var(
496
  combined_data[ticker])
497
+ st.write(
498
+ f"Value at Risk (95%) for {ticker}: {var:.2%}")
499
  if show_patterns or show_breakouts:
500
  ticker_data = load_ticker_data(output_dir, ticker)
501
  if ticker_data is not None:
 
545
  - Data is downloaded automatically.
546
 
547
  3. **Configure Predictives & Risk Tools** 🤖📊
548
+ - Predictive models combine historical data with real-time market signals to forecast trends—helping anticipate price movements and spot emerging opportunities.
549
+ - Risk analysis tools compute key metrics like Value at Risk (VaR) and perform stress tests to evaluate potential losses, giving critical insights into risk exposure.
550
  - Configure these tools to complement your overall technical analysis.
551
 
552
  4. **Enhance Your Analysis with Indicators** ⚙️