omarcevi.dev / workshops / pytorch-finance-workshop / 1 · Setup and Data

Part 1 · Setup and Data

Goal: Set up the environment, download daily THYAO.IS prices without getting stuck on rate limits, and visualise the OHLCV structure.

Key ideas:

  • What is OHLCV? Each trading day is summarised by five numbers: Open, High, Low, Close and Volume.
  • Adjusted prices (auto_adjust=True): Dividends and stock splits create artificial drops in the raw price. With auto_adjust=True, yfinance returns all historical OHLC prices adjusted for splits and dividends.
  • A fallback that always works: When 40 people in one room hit Yahoo Finance at once, a rate limit (YFRateLimitError) is likely. On an error or an empty table, load_prices automatically loads snapshot data instead.

Catch-up cell: 🔄 Catch up: Part 1 (run this if your runtime was reset)

Step-by-step code walkthrough:

After running the ⚙️ Setup cell, we load THYAO.IS by calling load_prices in TODO 1 (sec1-load-code):

notebook_cell.py
TICKER = "THYAO.IS"

# TODO 1 solution:
raw_df = load_prices(TICKER, start="2015-01-01", end="2026-11-17")

print(f"Data shape: {raw_df.shape} | Date range: {raw_df.index.min().date()} -> {raw_df.index.max().date()}")
display(raw_df.tail(5))

Then we plot the close price and the volume one above the other with plot_ohlcv:

notebook_cell.py
fig = plot_ohlcv(raw_df, ticker=TICKER)
plt.show()
THYAO.IS daily close price and trading volume
Expected output: a table of shape (3023, 5) (2015-01-01 -> 2026-11-16) and a close-price chart that climbs from single-digit lira in 2015–2016 to over 300 TL in 2026.

Troubleshooting (if this step fails):

  • Yahoo Finance rate limit (YFRateLimitError or an empty table): Nothing to do. load_prices prints ⚠️ Could not get THYAO.IS from Yahoo Finance (...). Loading the snapshot data... and loads the local or online snapshot.
  • NameError: name 'load_prices' is not defined: Your Colab runtime has probably restarted. Run the 🔄 Catch up: Part 1 cell at the top of Part 1.