Python for Traders
Never written a line of code? Start here. A friendly, hands-on path that takes a trader or investor from absolute zero to confidently working with real market data in Python - one small step at a time, in plain English, with examples you can run.
Getting Started with Python
From zero to your first script - install Python, meet your tools, and learn the absolute basics.
Why Python for Finance
Why the world's trading desks run on Python - and the surprising reason a 'slow' language is actually fast where it counts.
Installing Python & pip
Get Python onto your computer the painless way, and meet pip - the tool that installs everything else you'll use.
Your Toolkit: VS Code & Jupyter
Set up a clean, friendly place to write code - and meet Jupyter, the notebook traders love for poking at data.
Variables & Comments
Store a price, a symbol, a quantity - and leave notes for your future self. The humble building block of every program.
Numbers & Data Types
Integers, decimals, text and true/false - the basic kinds of data, and how to turn one into another.
Operators & P&L Math
Add, subtract, compare and combine - using Python as a calculator to work out profit, loss and percentage moves.
Input, Output & f-strings
Print results clearly and read input - and format rupees, dollars and percentages so they actually look right.
Working with Strings
Symbols, tickers and dates are all text. Slice them, clean them and reshape them with Python's string toolkit.
Core Programming
The building blocks every program is made of - data structures, logic, loops and functions.
Lists: Your First Data Structure
A watchlist, a week of closing prices, a basket of stocks - lists hold an ordered series you can grow, slice and sort.
Tuples
Fixed little groups of values - an OHLC bar, a row, a pair - that you don't want to change by accident.
Dictionaries
Look things up by name, not position. A live quote - symbol, price, volume - is a dictionary, the most useful structure in finance code.
Sets
A bag of unique things. Strip duplicate symbols, test membership instantly, and compare two watchlists with set maths.
Making Decisions: if / elif / else
Teach your code to choose - buy, sell or hold - with conditions and the boolean logic underneath them.
Loops: for & while
Do something to every price in a series without writing it a hundred times - the heartbeat of all data work.
Comprehensions
The elegant Python one-liner that builds a new list or dict from an old one - you'll see it everywhere.
Functions
Wrap a calculation in a name and reuse it forever. Write 'percentage_change' once, call it a thousand times.
Libraries, Files & Robust Code
Use other people's code, read and write files, handle dates, and fix errors like a pro.
Modules & Imports
Python comes with batteries included. Learn to import ready-made tools - and split your own code into tidy files.
The Standard Library Tour
A quick tour of the free toolbox that ships with Python - dates, maths, randomness and JSON, no install needed.
Installing Libraries: pip & venv
Reach beyond the standard library. Install pandas and friends with pip, and keep projects clean with virtual environments.
Errors & Debugging
Every coder hits red text. Read a traceback calmly, catch errors with try/except, and fix the usual beginner slips.
Reading & Writing Files
Save your results and load data from disk - open files safely, read lines, and write a small report.
Working with JSON
JSON is how market APIs talk. Turn a JSON string into a Python dict and back - the format you'll meet again and again.
Dates & Times
Markets run on a clock and a calendar. Parse, format and do arithmetic with dates - sessions, expiries and gaps.
Getting Unstuck
The real superpower: helping yourself. Use help(), read the docs, search well, and never be truly stuck again.
Data Analysis with NumPy & Pandas
The real workhorses of finance in Python - fast arrays, labelled tables, and charts that communicate.
NumPy Basics
The fast array that powers all of data science - and the 30x speed-up over plain Python from Chapter 1, now in your own hands.
Pandas Series
A column of numbers with labels - a price series you can do real maths on, and the gateway into pandas.
The DataFrame
A spreadsheet in Python. The table at the centre of every analysis - rows, columns and the operations you'll use daily.
Loading Market Data
Real prices, in two lines. Pull US stocks with yfinance and read a CSV, then look before you leap with head() and info().
Data Cleaning
Real data is messy. Handle the missing values (yes, the NaN yfinance leaves behind), wrong types and duplicates that quietly ruin results.
Dates & Time Series
Pandas was built for time series. Use a datetime index to resample daily bars to weekly and compute rolling averages.
Grouping & Aggregation
Answer real questions of your data - average return by month, biggest day per stock - with the group-by pattern.
Data Visualization
A chart is worth a thousand rows. Draw price lines, return histograms and clean seaborn charts that actually communicate.
Python for the Markets
Put it all together on real Indian and US market data - OHLCV, live quotes, returns and signals.
The Market Landscape
A trader's-eye map of where this data comes from - NSE and BSE, US exchanges, indices and the segments you'll meet.
Symbols, Tickers & Lot Sizes
RELIANCE, RELIANCE.NS or AAPL? Learn the symbol systems across India and the US, plus lot sizes and what a ticker really is.
Money, Timings & Holidays
Lakhs vs millions, 9:15 IST vs 9:30 ET - the everyday units and clocks of Indian and US markets, expressed in code.
Working with OHLCV Data
Open, high, low, close, volume - the five numbers behind every candle. Compute the range, body and returns from a real bar.
Fetching Data over HTTP
How programs talk to markets. Use the requests library to hit OpenAlgo's REST API and read the JSON that comes back - live, from India.
Live Quotes & Delayed Data
The difference between a live price and yesterday's close - pull live Indian quotes from OpenAlgo and delayed US data from yfinance, side by side.
What a WebSocket Is
Why live trading data streams to you instead of being asked for. A plain-words look at WebSockets - the concept, no setup required.
Returns, Signals & Performance
Everything you've learned, on one chart - turn prices into returns, a moving-average crossover into a signal, and judge it with win-rate and drawdown. Then: where to go next.
For education only - not investment advice. 40 chapters of plain Python, with real market data for context.