How to Download Your First Market Data with Python

Download your first U.S. stock market data with FinanceDataReader

You do not need to copy stock prices into Excel by hand. A few lines of Python can bring real market data directly into your program.

In the previous lesson, you learned the map: FinanceDataReader gets the data, and pandas holds it as a table. Now you will run that idea for the first time.

This is the second step in Phase 1. We will keep it deliberately small: one stock, one date range, one table.

What you will finish: your Python file will download real Apple price data and print it in the VS Code terminal.

1. What Are We Trying to Build?

In Phase 0, you prepared the tools. Now those tools will start working together.

Market data on the internet
        ↓
FinanceDataReader
        ↓
pandas DataFrame
        ↓
Your Python program
        ↓
VS Code terminal

FinanceDataReader gets the market data. The result arrives as a pandas DataFrame, which is a table made of rows and columns.

You installed both FinanceDataReader and pandas in Phase 0. Today, you will use them for real.

2. Create a New Python File

Open your alphesta-lab folder in Visual Studio Code.

Create a new file named:

first_market_data.py

Keep your earlier files. Your folder can now look like this:

alphesta-lab/
├── hello_alphesta.py
├── check_packages.py
└── first_market_data.py

3. Import FinanceDataReader

Type:

import FinanceDataReader as fdr

You already met this package in Phase 0. FinanceDataReader is the package name, and fdr is the shorter name we will use inside the code.

4. Choose One Market Symbol

We will begin with Apple.

symbol = "AAPL"

AAPL is Apple's ticker symbol. A ticker symbol is a short code used to identify a security in the market.

Think of it as the name Python uses when asking for a particular stock.

Apple
  ↓
AAPL

5. Choose a Fixed Date Range

Add:

start_date = "2025-01-02"
end_date = "2025-01-10"

We use a fixed historical period instead of “today” because fixed dates make an experiment easier to repeat later.

The date format is:

YYYY-MM-DD

2025-01-02
│    │  │
year month day

6. Ask FinanceDataReader for the Data

Now add the most important line in this lesson:

df = fdr.DataReader(symbol, start_date, end_date)

Read it from the inside out:

fdr.DataReader(
    symbol,
    start_date,
    end_date
)

You are telling FinanceDataReader: “Give me the market data for this symbol between these dates.”

The returned table is stored in a variable named df. The name df is commonly used as a short name for DataFrame.

7. Print the First Five Rows

Add:

print(df.head())

head() means: show the first five rows of the table.

Your complete file is now:

import FinanceDataReader as fdr

symbol = "AAPL"
start_date = "2025-01-02"
end_date = "2025-01-10"

df = fdr.DataReader(symbol, start_date, end_date)

print(df.head())

8. Run the File

Save the file with Ctrl + S. Then select Run Python File.

The terminal should print a small table. It will look roughly like this:

              Open    High     Low   Close    Volume
Date
2025-01-02    ...     ...      ...    ...       ...
2025-01-03    ...     ...      ...    ...       ...
2025-01-06    ...     ...      ...    ...       ...
...

The exact numbers are real market values returned by the data source. Columns can vary slightly by data source or package version.

Do not try to understand every column yet. For this lesson, the important result is simple: real dates and real market numbers have entered your Python program.

9. Why Are Some Calendar Dates Missing?

You asked for data from January 2 to January 10, but you may not see every calendar date.

That is normal. Stock markets do not trade every day. Weekends and market holidays usually do not produce a daily price row.

Calendar days
2025-01-02
2025-01-03
2025-01-04  ← weekend
2025-01-05  ← weekend
2025-01-06
...

Market-data rows
2025-01-02
2025-01-03
2025-01-06
...

This is your first reminder that market data is not just a table of numbers. The market calendar is part of the data.

10. Change One Input Yourself

Now make one small experiment.

Change:

symbol = "AAPL"

to:

symbol = "MSFT"

Save and run the same file again.

You changed only one input. The structure of the program stayed the same, but Python requested data for Microsoft instead of Apple.

Same code
   +
different symbol
   ↓
different market data

This is the Alphesta learning loop again:

Understand → Run → Change → Observe.

Check Your Result

You have completed this lesson if:

  • first_market_data.py exists in alphesta-lab.
  • You can explain what AAPL represents.
  • You understand what the start and end dates control.
  • fdr.DataReader() returns a market-data table.
  • df.head() prints the first five rows.
  • You changed AAPL to MSFT and observed a different result.

One Common Problem: No Data Appears

First, check the three inputs:

symbol
start_date
end_date

A mistyped ticker or an invalid date range can return no useful rows. Also confirm that your computer is connected to the internet because FinanceDataReader retrieves data from online sources.

If you see ModuleNotFoundError instead, return to the Phase 0 package-installation lesson and confirm that FinanceDataReader is installed in the Python interpreter selected by VS Code.

What You Just Built

AAPL
+
2025-01-02
+
2025-01-10
        ↓
fdr.DataReader(...)
        ↓
df
        ↓
real market data

This small table is the foundation for almost everything that follows: indicators, charts, trading rules, and backtests all begin with market data.

In the next lesson, we will slow down and read this table properly: Open, High, Low, Close, Volume, the Date index, rows, and columns.



Official reference: FinanceDataReader. FinanceDataReader is an open-source financial data reader and supports market-price data for assets including U.S. stocks such as AAPL.