Learning LibraryQuant LibraryTeens

Market data: prices as rows you can loop over

Before any strategy, you need data. Market data is just rows of prices over time — and to code, each row is a dictionary you can loop over. (Everything here is for learning, not financial advice.)

The big idea

Market data is a time-ordered series of price bars, each with values like open, high, low, and close, that you read row by row.

See it in code

1The basics

The simplest market data is just a list of closing prices, oldest first. A loop reads them in time order — which is the whole point, because markets are sequences:

python
# Closing prices, oldest first - for study, not advice.
closes = [100.0, 102.5, 101.0, 104.0]

for close in closes:
    print(close)
Run it — four prices, read in the order they happened:
100.0
102.5
101.0
104.0

That's market data at its barest: numbers in time order. But a bare price doesn't say when it happened — so next we attach a day to each one.

2A step further

enumerate hands you a counter alongside each value, so we can label every close with its day number — the price and its place in time:

python
closes = [100.0, 102.5, 101.0, 104.0]

for day, close in enumerate(closes, start=1):
    print(f"Day {day}: {close}")
Run it — now each price is tied to the day it landed on:
Day 1: 100.0
Day 2: 102.5
Day 3: 101.0
Day 4: 104.0

A bar carries two facts now — a day and a close. Real bars carry more, so it helps to bundle each row's values together instead of tracking parallel lists.

3In our world

Now bundle each day and its price into one row — a dictionary — so a bar can hold many values at once. In the lab we use frozen sample bars (fixed historical data, reproducible and purely educational); a loop walks them in time order, exactly as a real analysis would:

python
# Frozen sample bars - for study, not advice.
bars = [
    {"day": 1, "close": 100.0},
    {"day": 2, "close": 102.5},
    {"day": 3, "close": 101.0},
    {"day": 4, "close": 104.0},
]

for bar in bars:
    print(f"Day {bar['day']}: close {bar['close']}")

print("Bars loaded:", len(bars))
Run it — each day's closing price, read in order:
Day 1: close 100.0
Day 2: close 102.5
Day 3: close 101.0
Day 4: close 104.0
Bars loaded: 4

The data is just a list of dictionaries, and the loop reads it in time order — which matters, because markets are sequences. Real datasets add open, high, low, and volume per bar, but the shape is the same: rows over time.

The same idea, everywhere

Time-series data is everywhere: temperatures by day, heart rate by second, website visits by hour. The skills are shared — load rows, iterate in order, compute over a window. A price series is one example of a pattern you'll meet in science, health, and operations.

Try it yourself

Add high and low to each bar and print the daily range (high - low). Then find the highest close by looping and tracking a running maximum.

The common mistake

Ignoring order, or peeking at the future. Market data is a sequence — shuffling it destroys its meaning. And a strategy must only use data available up to the current bar; using later bars is 'lookahead bias', a classic mistake that makes a backtest look better than reality.

What it unlocks

Reading bars is the base for moving averages, trading signals, and backtesting, all built on lists and dictionaries.