How do I download prices with yfinance?

Request daily stock prices for a date range with yfinance, select one closing price column per ticker with xs, and choose between the close and the dividend-adjusted close.

After this lesson, you can request daily prices for two stocks and turn the answer into a table with one row per trading day and one closing price column per stock.

How do I request prices through the last day I want?

yf.download(tickers, start="2026-03-02", end="2026-03-05") returns the trading days from 2 to 4 March, because start includes its date and end leaves out its date. Weekends and exchange holidays add no rows.

auto_adjust=False keeps Yahoo Finance’s Close and Adj Close as separate fields, and group_by="column" with multi_level_index=True gives every column two labels, the field and the ticker. The site uses yfinance for the SPY benchmark in the dividend yield backtest.

The following box, which does not run on this page, requests AAPL and MSFT.

import yfinance as yf

prices = yf.download(["AAPL", "MSFT"], start="2026-03-02", end="2026-03-05", auto_adjust=False, group_by="column", multi_level_index=True)

How do I keep the close of every ticker?

Each column of the answer has two labels, a field such as Close and a ticker such as AAA, called a MultiIndex, and prices.xs("Close", axis=1, level=0) keeps the Close column of every ticker and drops the field label. AAA closed at 100 dollars on 2 March.

The made-up answer has the layout of a yfinance download for AAA and BBB on three days, with six fields per ticker, prices in dollars per share and volumes in shares. axis=1 searches the columns, and level 0 holds the fields. A missing close stays missing in the result.

Code: the made-up answer
import pandas as pd

prices = pd.DataFrame(
    [[98, 50, 100, 50, 101, 51, 99, 49, 100, 49, 800, 600],
     [98, 51, 98, 51, 99, 52, 97, 50, 98, 50, 900, 700],
     [99, 52, 99, 52, 100, 53, 98, 51, 98, 51, 750, 650]],
    index=pd.DatetimeIndex(["2026-03-02", "2026-03-03", "2026-03-04"], name="Date"),
    columns=pd.MultiIndex.from_product([["Adj Close", "Close", "High", "Low", "Open", "Volume"], ["AAA", "BBB"]], names=["Price", "Ticker"]),
)

The following box shows the column labels and selects the closes.

print(prices.shape, prices.columns[2])
close = prices.xs("Close", axis=1, level=0)
print(close)
(3, 12) ('Close', 'AAA')
Ticker      AAA  BBB
Date                
2026-03-02  100   50
2026-03-03   98   51
2026-03-04   99   52

Which close should I use when a stock pays a dividend?

Adj Close lowers the prices before a dividend by the dividend’s share of the price, so a return from Adj Close includes the dividend. AAA pays 2 dollars per share on 3 March, its Close falls from 100 to 98, and its Adj Close stays at 98, because the adjusted price of 2 March is 100 × 0.98 = 98.

With auto_adjust=True, yfinance puts the adjusted series in Close and scales Open, High and Low by the same ratio. Adding the dividend to a return from Adj Close counts it twice. Yahoo’s Close already reflects stock splits.

The following box puts AAA’s two closes side by side.

adjusted = prices.xs("Adj Close", axis=1, level=0)
print(pd.DataFrame({"close": close["AAA"], "adj_close": adjusted["AAA"]}))
            close  adj_close
Date                        
2026-03-02    100         98
2026-03-03     98         98
2026-03-04     99         99

Your turn

Print BBB’s adjusted close on 3 and 4 March. You should see 51 and 52.

.loc selects the dates by label.

print(adjusted.loc[["2026-03-03", "2026-03-04"], "BBB"])
Date
2026-03-03    51
2026-03-04    52
Name: BBB, dtype: int64