Manus commited on
Commit
2558aee
·
1 Parent(s): f67f12f

Feature: Integrate StockData.org as a data source. Fix: AttributeError in app.py.

Browse files
Files changed (3) hide show
  1. app.py +5 -4
  2. config.py +1 -1
  3. core/data.py +2 -0
app.py CHANGED
@@ -30,7 +30,7 @@ def update_horizon_label(timeframe):
30
  return gr.update(label=f"Horizon ({units.get(timeframe, 'days')})")
31
 
32
  def run_dashboard(data_src, ticker, file_upload, timeframe, start_date, end_date, horizon, indicators,
33
- include_sentiment, news_api_key, alpha_api_key, finnhub_api_key, twelvedata_api_key, account_size, risk_percent, model,
34
  hidden_units, n_layers, epochs, learning_rate, beta1, beta2, weight_decay, dropout,
35
  window_size, test_split, rsi_mid, macd_sens, adx_thr, sent_thr, vote_buy, vote_sell,
36
  feat_selector, feat_threshold):
@@ -41,7 +41,7 @@ def run_dashboard(data_src, ticker, file_upload, timeframe, start_date, end_date
41
 
42
  df = load_data(data_src=data_src, ticker=ticker, start=start_date, end=end_date,
43
  interval=timeframe, file_upload=file_upload, alpha_api_key=alpha_api_key,
44
- finnhub_api_key=finnhub_api_key, twelvedata_api_key=twelvedata_api_key)
45
  if df.empty:
46
  logging.error("Failed to load data")
47
  return [None] * 12 + ["Failed to load data", None, None, None, None, "Failed to load data"]
@@ -131,7 +131,7 @@ def main_interface():
131
  gr.Markdown("# Market Prediction Pro")
132
  with gr.Row():
133
  with gr.Column(scale=1):
134
- data_src = gr.Dropdown(["yahoo", "csv", "alpha_vantage", "finnhub", "twelvedata"], label="Data Source", value="yahoo")
135
  ticker = gr.Dropdown(DEFAULT_TICKERS, label="Ticker", value="AAPL")
136
  file_upload = gr.File(label="Upload CSV", visible=False)
137
  timeframe = gr.Dropdown(AVAILABLE_TIMEFRAMES, label="Timeframe", value="1d")
@@ -144,6 +144,7 @@ def main_interface():
144
  alpha_api_key = gr.Textbox("IUCYQSZIPF3QIB3Q", label="Alpha Vantage API Key (Optional)", type="password")
145
  finnhub_api_key = gr.Textbox(label="Finnhub API Key (Optional)", type="password")
146
  twelvedata_api_key = gr.Textbox(label="Twelve Data API Key (Optional)", type="password")
 
147
 
148
  gr.Markdown("### Model Parameters")
149
  model = gr.Dropdown(AVAILABLE_MODELS, label="Model", value="LSTM")
@@ -195,7 +196,7 @@ def main_interface():
195
  run_dashboard,
196
  inputs=[
197
  data_src, ticker, file_upload, timeframe, start_date, end_date, horizon, indicators,
198
- include_sentiment, news_api_key, alpha_api_key, finnhub_api_key, twelvedata_api_key, gr.Number(value=10000, visible=False), gr.Number(value=0.01, visible=False), model,
199
  hidden_units, n_layers, epochs, learning_rate, beta1, beta2, weight_decay, dropout,
200
  window_size, test_split, rsi_mid, macd_sens, adx_thr, sent_thr, vote_buy, vote_sell,
201
  feat_selector, feat_threshold
 
30
  return gr.update(label=f"Horizon ({units.get(timeframe, 'days')})")
31
 
32
  def run_dashboard(data_src, ticker, file_upload, timeframe, start_date, end_date, horizon, indicators,
33
+ include_sentiment, news_api_key, alpha_api_key, finnhub_api_key, twelvedata_api_key, stockdata_api_key, account_size, risk_percent, model,
34
  hidden_units, n_layers, epochs, learning_rate, beta1, beta2, weight_decay, dropout,
35
  window_size, test_split, rsi_mid, macd_sens, adx_thr, sent_thr, vote_buy, vote_sell,
36
  feat_selector, feat_threshold):
 
41
 
42
  df = load_data(data_src=data_src, ticker=ticker, start=start_date, end=end_date,
43
  interval=timeframe, file_upload=file_upload, alpha_api_key=alpha_api_key,
44
+ finnhub_api_key=finnhub_api_key, twelvedata_api_key=twelvedata_api_key, stockdata_api_key=stockdata_api_key)
45
  if df.empty:
46
  logging.error("Failed to load data")
47
  return [None] * 12 + ["Failed to load data", None, None, None, None, "Failed to load data"]
 
131
  gr.Markdown("# Market Prediction Pro")
132
  with gr.Row():
133
  with gr.Column(scale=1):
134
+ data_src = gr.Dropdown(["yahoo", "csv", "alpha_vantage", "finnhub", "twelvedata", "stockdata"], label="Data Source", value="yahoo")
135
  ticker = gr.Dropdown(DEFAULT_TICKERS, label="Ticker", value="AAPL")
136
  file_upload = gr.File(label="Upload CSV", visible=False)
137
  timeframe = gr.Dropdown(AVAILABLE_TIMEFRAMES, label="Timeframe", value="1d")
 
144
  alpha_api_key = gr.Textbox("IUCYQSZIPF3QIB3Q", label="Alpha Vantage API Key (Optional)", type="password")
145
  finnhub_api_key = gr.Textbox(label="Finnhub API Key (Optional)", type="password")
146
  twelvedata_api_key = gr.Textbox(label="Twelve Data API Key (Optional)", type="password")
147
+ stockdata_api_key = gr.Textbox(label="StockData.org API Key (Optional)", type="password")
148
 
149
  gr.Markdown("### Model Parameters")
150
  model = gr.Dropdown(AVAILABLE_MODELS, label="Model", value="LSTM")
 
196
  run_dashboard,
197
  inputs=[
198
  data_src, ticker, file_upload, timeframe, start_date, end_date, horizon, indicators,
199
+ include_sentiment, news_api_key, alpha_api_key, finnhub_api_key, twelvedata_api_key, stockdata_api_key, gr.Number(value=10000, visible=False), gr.Number(value=0.01, visible=False), model,
200
  hidden_units, n_layers, epochs, learning_rate, beta1, beta2, weight_decay, dropout,
201
  window_size, test_split, rsi_mid, macd_sens, adx_thr, sent_thr, vote_buy, vote_sell,
202
  feat_selector, feat_threshold
config.py CHANGED
@@ -2,7 +2,7 @@
2
  DEFAULT_TICKERS = ["BTC-USD", "ETH-USD", "AAPL", "MSFT", "TSLA", "GOOG", "META", "AMZN", "XAUUSD=X", "EURUSD=X", "SPY", "QQQ", "DIA", "^GSPC", "^DJI", "^IXIC"]
3
  AVAILABLE_MODELS = ["LSTM", "GRU", "BiLSTM", "CNN", "Transformer", "Hybrid", "MLP"]
4
  AVAILABLE_TIMEFRAMES = ["1m", "2m", "5m", "15m", "30m", "60m", "90m", "1h", "1d", "5d", "1wk", "1mo", "3mo"]
5
- AVAILABLE_DATA_SOURCES = ["yahoo", "alpha_vantage", "finnhub", "twelvedata"]
6
  AVAILABLE_INDICATORS = [
7
  "adx", "ao", "apo", "aroon", "atr", "bbands", "cci", "cg", "cmo", "copp",
8
  "dema", "dma", "donchian", "dpo", "efi", "ema", "eom", "fama", "fisher",
 
2
  DEFAULT_TICKERS = ["BTC-USD", "ETH-USD", "AAPL", "MSFT", "TSLA", "GOOG", "META", "AMZN", "XAUUSD=X", "EURUSD=X", "SPY", "QQQ", "DIA", "^GSPC", "^DJI", "^IXIC"]
3
  AVAILABLE_MODELS = ["LSTM", "GRU", "BiLSTM", "CNN", "Transformer", "Hybrid", "MLP"]
4
  AVAILABLE_TIMEFRAMES = ["1m", "2m", "5m", "15m", "30m", "60m", "90m", "1h", "1d", "5d", "1wk", "1mo", "3mo"]
5
+ AVAILABLE_DATA_SOURCES = ["yahoo", "alpha_vantage", "finnhub", "twelvedata", "stockdata"]
6
  AVAILABLE_INDICATORS = [
7
  "adx", "ao", "apo", "aroon", "atr", "bbands", "cci", "cg", "cmo", "copp",
8
  "dema", "dma", "donchian", "dpo", "efi", "ema", "eom", "fama", "fisher",
core/data.py CHANGED
@@ -265,6 +265,8 @@ def load_data(data_src='yahoo', ticker='AAPL', start='2020-01-01', end='2023-01-
265
  df = load_data_finnhub(ticker, start, end, interval, finnhub_api_key)
266
  elif data_src == 'twelvedata' and twelvedata_api_key:
267
  df = load_data_twelvedata(ticker, start, end, interval, twelvedata_api_key)
 
 
268
  # elif data_src == 'stockdata' and stockdata_api_key: # StockData.org is not free for historical data
269
  # df = load_data_stockdata(ticker, start, end, interval, stockdata_api_key)
270
 
 
265
  df = load_data_finnhub(ticker, start, end, interval, finnhub_api_key)
266
  elif data_src == 'twelvedata' and twelvedata_api_key:
267
  df = load_data_twelvedata(ticker, start, end, interval, twelvedata_api_key)
268
+ elif data_src == 'stockdata' and stockdata_api_key:
269
+ df = load_data_stockdata(ticker, start, end, interval, stockdata_api_key)
270
  # elif data_src == 'stockdata' and stockdata_api_key: # StockData.org is not free for historical data
271
  # df = load_data_stockdata(ticker, start, end, interval, stockdata_api_key)
272