ykjung commited on
Commit
b1a801d
ยท
1 Parent(s): 86f67c9

feat: update fetch_ticker_data to accept period parameter and enhance pipeline with period input

Browse files
Files changed (3) hide show
  1. README.md +6 -3
  2. __pycache__/app.cpython-313.pyc +0 -0
  3. app.py +18 -8
README.md CHANGED
@@ -56,11 +56,11 @@ UI ์—ฐ๊ฒฐ:
56
 
57
  UI ์—ฐ๊ฒฐ:
58
 
59
- - `start_btn.click(fn=run_pipeline, inputs=[hf_token_input, all_dataset_input, recent_dataset_input, batch_size_input], outputs=[output_log])`
60
 
61
  ์‹คํ–‰ ํ•จ์ˆ˜:
62
 
63
- - `run_pipeline(hf_token, all_dataset_name, recent_dataset_name, batch_size, progress=gr.Progress())`
64
 
65
  ์‚ฌ์ „ ์กฐ๊ฑด:
66
 
@@ -74,7 +74,7 @@ UI ์—ฐ๊ฒฐ:
74
  - ์ „์ฒด ๋Œ€์ƒ ํ‹ฐ์ปค ๊ฐœ์ˆ˜ ๊ณ„์‚ฐ
75
  2. **ํ‹ฐ์ปค๋ณ„ ๊ฐ€๊ฒฉ ๋ฐ์ดํ„ฐ ์ˆ˜์ง‘**
76
  - ๊ฐ ํ‹ฐ์ปค์— ๋Œ€ํ•ด `fetch_ticker_data(ticker)` ์‹คํ–‰
77
- - `yf.Ticker(ticker).history(period="max", interval="1d")` ํ˜ธ์ถœ
78
  - ์ปฌ๋Ÿผ ์ •๋ฆฌ: `Ticker`, `Date`, `Open`, `High`, `Low`, `Close`, `Volume`
79
  - ์ˆซ์ž ์ปฌ๋Ÿผ ๋ฐ˜์˜ฌ๋ฆผ(์†Œ์ˆ˜์  4์ž๋ฆฌ)
80
  - ์žฅ์ค‘ ๋ฏธํ™•์ • ์ข…๊ฐ€ ์ œ์™ธ ๋กœ์ง ์ ์šฉ
@@ -155,6 +155,9 @@ UI ์—ฐ๊ฒฐ:
155
  - ์˜ˆ: `username/us-stocks-daily-30d`
156
  - `๋กœ๊ทธ ์ถœ๋ ฅ ๋ฐฐ์น˜ ํฌ๊ธฐ`
157
  - ๋ช‡ ๊ฐœ ํ‹ฐ์ปค๋งˆ๋‹ค ์ค‘๊ฐ„ ์ง„ํ–‰ ๋กœ๊ทธ๋ฅผ ๋‚จ๊ธธ์ง€ ์„ค์ •
 
 
 
158
 
159
  ---
160
 
 
56
 
57
  UI ์—ฐ๊ฒฐ:
58
 
59
+ - `start_btn.click(fn=run_pipeline, inputs=[hf_token_input, all_dataset_input, recent_dataset_input, batch_size_input, period_input], outputs=[output_log])`
60
 
61
  ์‹คํ–‰ ํ•จ์ˆ˜:
62
 
63
+ - `run_pipeline(hf_token, all_dataset_name, recent_dataset_name, batch_size, period, progress=gr.Progress())`
64
 
65
  ์‚ฌ์ „ ์กฐ๊ฑด:
66
 
 
74
  - ์ „์ฒด ๋Œ€์ƒ ํ‹ฐ์ปค ๊ฐœ์ˆ˜ ๊ณ„์‚ฐ
75
  2. **ํ‹ฐ์ปค๋ณ„ ๊ฐ€๊ฒฉ ๋ฐ์ดํ„ฐ ์ˆ˜์ง‘**
76
  - ๊ฐ ํ‹ฐ์ปค์— ๋Œ€ํ•ด `fetch_ticker_data(ticker)` ์‹คํ–‰
77
+ - `yf.Ticker(ticker).history(period=period, interval="1d")` ํ˜ธ์ถœ
78
  - ์ปฌ๋Ÿผ ์ •๋ฆฌ: `Ticker`, `Date`, `Open`, `High`, `Low`, `Close`, `Volume`
79
  - ์ˆซ์ž ์ปฌ๋Ÿผ ๋ฐ˜์˜ฌ๋ฆผ(์†Œ์ˆ˜์  4์ž๋ฆฌ)
80
  - ์žฅ์ค‘ ๋ฏธํ™•์ • ์ข…๊ฐ€ ์ œ์™ธ ๋กœ์ง ์ ์šฉ
 
155
  - ์˜ˆ: `username/us-stocks-daily-30d`
156
  - `๋กœ๊ทธ ์ถœ๋ ฅ ๋ฐฐ์น˜ ํฌ๊ธฐ`
157
  - ๋ช‡ ๊ฐœ ํ‹ฐ์ปค๋งˆ๋‹ค ์ค‘๊ฐ„ ์ง„ํ–‰ ๋กœ๊ทธ๋ฅผ ๋‚จ๊ธธ์ง€ ์„ค์ •
158
+ - `์กฐํšŒ ๊ธฐ๊ฐ„ (Yahoo period)`
159
+ - ์˜ˆ: `max`, `10y`, `5y`, `2y`, `1y`, `6mo`, `3mo`, `1mo`
160
+ - ํŒŒ์ดํ”„๋ผ์ธ ์‹คํ–‰ ์‹œ๊ฐ„์„ ์ค„์ด๊ณ  ์‹ถ๋‹ค๋ฉด `max` ๋Œ€์‹  ๋” ์งง์€ ๊ธฐ๊ฐ„์„ ์„ ํƒ
161
 
162
  ---
163
 
__pycache__/app.cpython-313.pyc CHANGED
Binary files a/__pycache__/app.cpython-313.pyc and b/__pycache__/app.cpython-313.pyc differ
 
app.py CHANGED
@@ -313,17 +313,17 @@ def get_all_us_tickers():
313
  return [], [], []
314
 
315
 
316
- def fetch_ticker_data(ticker, max_retries=3):
317
  """
318
- ๊ฐœ๋ณ„ ํ‹ฐ์ปค์˜ ์ „์ฒด๊ธฐ๊ฐ„ ์ผ๋ณ„ ๋ฐ์ดํ„ฐ๋ฅผ ์•ผํ›„ ํŒŒ์ด๋‚ธ์Šค์—์„œ ์กฐํšŒ
319
- - period="max" : ๊ฐ€๋Šฅํ•œ ์ „์ฒด ๊ธฐ๊ฐ„
320
  - interval="1d" : ์ผ๋ณ„ ๋ฐ์ดํ„ฐ
321
  """
322
  for attempt in range(max_retries):
323
  try:
324
  stock = yf.Ticker(ticker)
325
- # ์ „์ฒด๊ธฐ๊ฐ„, ์ผ๋ณ„ ๋ฐ์ดํ„ฐ ์กฐํšŒ
326
- hist = stock.history(period="max", interval="1d")
327
 
328
  if hist.empty:
329
  logger.warning(f"[{ticker}] ๋ฐ์ดํ„ฐ ์—†์Œ (๋นˆ ๊ฒฐ๊ณผ)")
@@ -432,6 +432,7 @@ def run_pipeline(
432
  all_dataset_name,
433
  recent_dataset_name,
434
  batch_size,
 
435
  progress=gr.Progress()
436
  ):
437
  """
@@ -466,6 +467,7 @@ def run_pipeline(
466
  # ========== 2๋‹จ๊ณ„: ์•ผํ›„ ํŒŒ์ด๋‚ธ์Šค ๋ฐ์ดํ„ฐ ์ˆ˜์ง‘ ==========
467
  logs.append(f"\n๐Ÿ“ฅ [2๋‹จ๊ณ„] ์•ผํ›„ ํŒŒ์ด๋‚ธ์Šค ๋ฐ์ดํ„ฐ ์ˆ˜์ง‘ ์‹œ์ž‘ (์ด {len(all_tickers)}๊ฐœ ํ‹ฐ์ปค)")
468
  logs.append(f" - ๋ฐฐ์น˜ ํฌ๊ธฐ: {batch_size}")
 
469
  logs.append(f" โš ๏ธ ๋ฐ˜๋ณต๋ฌธ์ด๋ผ ์˜ค๋ž˜ ๊ฑธ๋ฆฝ๋‹ˆ๋‹ค. ์ „์ฒด ํ‹ฐ์ปค ์ˆ˜์— ๋”ฐ๋ผ ์ˆ˜ ์‹œ๊ฐ„ ์†Œ์š”๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.")
470
 
471
  all_data_frames = []
@@ -478,7 +480,7 @@ def run_pipeline(
478
  progress_pct = (i + 1) / total
479
  progress(progress_pct, desc=f"์ˆ˜์ง‘ ์ค‘: {ticker} ({i + 1}/{total})")
480
 
481
- ticker_df = fetch_ticker_data(ticker)
482
 
483
  if ticker_df is not None and not ticker_df.empty:
484
  all_data_frames.append(ticker_df)
@@ -564,7 +566,7 @@ with gr.Blocks(
564
 
565
  ### ํŒŒ์ดํ”„๋ผ์ธ ํ๋ฆ„
566
  1. ๐Ÿ” ๋‚˜์Šค๋‹ฅ & ๋‰ด์š•์ฆ๊ถŒ๊ฑฐ๋ž˜์†Œ ์ „์ฒด ํ‹ฐ์ปค ๋ชฉ๋ก ์ˆ˜์ง‘
567
- 2. ๐Ÿ“ฅ ํ‹ฐ์ปค๋ณ„ ์•ผํ›„ ํŒŒ์ด๋‚ธ์Šค ์ผ๋ณ„ ๋ฐ์ดํ„ฐ ์กฐํšŒ (์ „์ฒด๊ธฐ๊ฐ„, `period="max"`)
568
  3. ๐Ÿ“ฆ **all ๋ฐ์ดํ„ฐ์…‹** ์ƒ์„ฑ (์ „์ฒด๊ธฐ๊ฐ„ ๋ฐ์ดํ„ฐ)
569
  4. ๐Ÿ—“๏ธ ํ‹ฐ์ปค๋ณ„ ์ตœ๊ทผ 30์ผ ํ•„ํ„ฐ๋ง โ†’ **30์ผ ๋ฐ์ดํ„ฐ์…‹** ์ƒ์„ฑ
570
  5. ๐Ÿš€ ํ—ˆ๊น…ํŽ˜์ด์Šค ํ—ˆ๋ธŒ์— ์—…๋กœ๋“œ
@@ -607,6 +609,13 @@ with gr.Blocks(
607
  info="๋ช‡ ๊ฐœ ํ‹ฐ์ปค๋งˆ๋‹ค ๋กœ๊ทธ๋ฅผ ์ถœ๋ ฅํ• ์ง€ ์„ค์ •"
608
  )
609
 
 
 
 
 
 
 
 
610
  with gr.Row():
611
  preview_btn = gr.Button("๐Ÿ‘€ ํ‹ฐ์ปค ๋ชฉ๋ก ๋ฏธ๋ฆฌ๋ณด๊ธฐ", variant="secondary")
612
  start_btn = gr.Button("๐Ÿš€ ํŒŒ์ดํ”„๋ผ์ธ ์‹œ์ž‘", variant="primary")
@@ -634,7 +643,8 @@ with gr.Blocks(
634
  hf_token_input,
635
  all_dataset_input,
636
  recent_dataset_input,
637
- batch_size_input
 
638
  ],
639
  outputs=[output_log]
640
  )
 
313
  return [], [], []
314
 
315
 
316
+ def fetch_ticker_data(ticker, period="max", max_retries=3):
317
  """
318
+ ๊ฐœ๋ณ„ ํ‹ฐ์ปค์˜ ๊ธฐ๊ฐ„๋ณ„ ์ผ๋ณ„ ๋ฐ์ดํ„ฐ๋ฅผ ์•ผํ›„ ํŒŒ์ด๋‚ธ์Šค์—์„œ ์กฐํšŒ
319
+ - period: yfinance history ๊ธฐ๊ฐ„ ํŒŒ๋ผ๋ฏธํ„ฐ (์˜ˆ: max, 10y, 5y, 1y, 6mo, 3mo)
320
  - interval="1d" : ์ผ๋ณ„ ๋ฐ์ดํ„ฐ
321
  """
322
  for attempt in range(max_retries):
323
  try:
324
  stock = yf.Ticker(ticker)
325
+ # ๊ธฐ๊ฐ„๋ณ„, ์ผ๋ณ„ ๋ฐ์ดํ„ฐ ์กฐํšŒ
326
+ hist = stock.history(period=period, interval="1d")
327
 
328
  if hist.empty:
329
  logger.warning(f"[{ticker}] ๋ฐ์ดํ„ฐ ์—†์Œ (๋นˆ ๊ฒฐ๊ณผ)")
 
432
  all_dataset_name,
433
  recent_dataset_name,
434
  batch_size,
435
+ period,
436
  progress=gr.Progress()
437
  ):
438
  """
 
467
  # ========== 2๋‹จ๊ณ„: ์•ผํ›„ ํŒŒ์ด๋‚ธ์Šค ๋ฐ์ดํ„ฐ ์ˆ˜์ง‘ ==========
468
  logs.append(f"\n๐Ÿ“ฅ [2๋‹จ๊ณ„] ์•ผํ›„ ํŒŒ์ด๋‚ธ์Šค ๋ฐ์ดํ„ฐ ์ˆ˜์ง‘ ์‹œ์ž‘ (์ด {len(all_tickers)}๊ฐœ ํ‹ฐ์ปค)")
469
  logs.append(f" - ๋ฐฐ์น˜ ํฌ๊ธฐ: {batch_size}")
470
+ logs.append(f" - ์กฐํšŒ ๊ธฐ๊ฐ„(period): {period}")
471
  logs.append(f" โš ๏ธ ๋ฐ˜๋ณต๋ฌธ์ด๋ผ ์˜ค๋ž˜ ๊ฑธ๋ฆฝ๋‹ˆ๋‹ค. ์ „์ฒด ํ‹ฐ์ปค ์ˆ˜์— ๋”ฐ๋ผ ์ˆ˜ ์‹œ๊ฐ„ ์†Œ์š”๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.")
472
 
473
  all_data_frames = []
 
480
  progress_pct = (i + 1) / total
481
  progress(progress_pct, desc=f"์ˆ˜์ง‘ ์ค‘: {ticker} ({i + 1}/{total})")
482
 
483
+ ticker_df = fetch_ticker_data(ticker, period=period)
484
 
485
  if ticker_df is not None and not ticker_df.empty:
486
  all_data_frames.append(ticker_df)
 
566
 
567
  ### ํŒŒ์ดํ”„๋ผ์ธ ํ๋ฆ„
568
  1. ๐Ÿ” ๋‚˜์Šค๋‹ฅ & ๋‰ด์š•์ฆ๊ถŒ๊ฑฐ๋ž˜์†Œ ์ „์ฒด ํ‹ฐ์ปค ๋ชฉ๋ก ์ˆ˜์ง‘
569
+ 2. ๐Ÿ“ฅ ํ‹ฐ์ปค๋ณ„ ์•ผํ›„ ํŒŒ์ด๋‚ธ์Šค ์ผ๋ณ„ ๋ฐ์ดํ„ฐ ์กฐํšŒ (`period` ์„ค์ • ๊ฐ€๋Šฅ)
570
  3. ๐Ÿ“ฆ **all ๋ฐ์ดํ„ฐ์…‹** ์ƒ์„ฑ (์ „์ฒด๊ธฐ๊ฐ„ ๋ฐ์ดํ„ฐ)
571
  4. ๐Ÿ—“๏ธ ํ‹ฐ์ปค๋ณ„ ์ตœ๊ทผ 30์ผ ํ•„ํ„ฐ๋ง โ†’ **30์ผ ๋ฐ์ดํ„ฐ์…‹** ์ƒ์„ฑ
572
  5. ๐Ÿš€ ํ—ˆ๊น…ํŽ˜์ด์Šค ํ—ˆ๋ธŒ์— ์—…๋กœ๋“œ
 
609
  info="๋ช‡ ๊ฐœ ํ‹ฐ์ปค๋งˆ๋‹ค ๋กœ๊ทธ๋ฅผ ์ถœ๋ ฅํ• ์ง€ ์„ค์ •"
610
  )
611
 
612
+ period_input = gr.Dropdown(
613
+ label="์กฐํšŒ ๊ธฐ๊ฐ„ (Yahoo period)",
614
+ choices=["max", "10y", "5y", "2y", "1y", "6mo", "3mo", "1mo"],
615
+ value="max",
616
+ info="์ „์ฒด ์ˆ˜์ง‘ ์‹œ๊ฐ„์ด ๊ธธ๋ฉด 10y/5y ๋“ฑ์œผ๋กœ ์ค„์—ฌ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."
617
+ )
618
+
619
  with gr.Row():
620
  preview_btn = gr.Button("๐Ÿ‘€ ํ‹ฐ์ปค ๋ชฉ๋ก ๋ฏธ๋ฆฌ๋ณด๊ธฐ", variant="secondary")
621
  start_btn = gr.Button("๐Ÿš€ ํŒŒ์ดํ”„๋ผ์ธ ์‹œ์ž‘", variant="primary")
 
643
  hf_token_input,
644
  all_dataset_input,
645
  recent_dataset_input,
646
+ batch_size_input,
647
+ period_input
648
  ],
649
  outputs=[output_log]
650
  )