Skip to content

About

Python for Fixed Income: a free course series that teaches Python from zero to people who work in fixed income, every example a bond or credit example

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

505 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python for Fixed Income

From your first line of code to your own AI agents.
Taught entirely through the work of a credit desk.

Courses Notebooks Price Python Platform Code: MIT Content: CC BY 4.0

Start here  ·  The path  ·  What you will build  ·  Coming from Excel  ·  The courses  ·  How a day works


156

notebooks, each with
worked solutions

158

Excel comparisons,
formula by formula

31

weeks, one notebook
a day

$0

to take, and no key
needed to run

Python for people who already know bonds

You know what a coupon is. You understand spread, duration, yield, and credit. You live in Excel. You have never written a line of code.

That is exactly where this series begins.

Most Python courses teach with shopping carts and movie ratings. This one teaches with the work of a credit desk. Your first variable is a bond's coupon. Your first loop totals a portfolio. Your first table is a holdings file. Your first analysis answers a question you already know how to ask.

And it keeps going. You will price bonds with code you wrote and tested against Excel. You will pull market data from an API, fit machine learning models on credit data, read real indentures with a language model, build a team of AI agents that runs a credit desk's morning brief, and put your work online as an app anyone can open.

Note

This course is educational content created in a personal capacity. Nothing here is investment advice or a recommendation to buy or sell any security. All portfolio data is synthetic.

Why this series is different

Built on the desk

Every example is a fixed income or credit example: holdings files, trade blotters, the Treasury curve, FOMC statements, 10-Ks, and bond indentures.

Excel side by side

Every new idea sits beside the Excel formula you would write today, so you are always translating something you already know.

Every number checked

You build price, yield, duration, and DV01 yourself and test them against Excel. Every exercise has a check cell that tells you when you are right.

Ready for AI

Every day ends with an AI check: code in the style of an AI answer, with one bug for you to find. You learn to use AI and to catch it when it is wrong.

Learn by doing

A desk question, a few lines of code that answer it, and one line on what the output shows. Errors are run on purpose and read line by line.

Free, start to finish

Every notebook runs in your browser on Google Colab or on your own Windows machine. No paid account and no API key needed to run any of them.

The path

Ten courses and a bonus, each one building on the last.

The path: Foundations (Courses 1 to 3), then Machine learning (4 to 6), then Language models and agents (7 and 8), then Build and ship (9, 10, and the Bonus)

What you will build

Every course ends with a capstone you can show.

Course Your capstone
1 Python Foundations A month-end review of a holdings extract: cleaned, checked against its control totals, compared with its benchmark, and written to Excel
2 Bond Math Your own bond math module, tested against Excel, and a risk report on a whole book: duration, DV01, convexity, spread, and DTS
3 Market Data and Time Series A daily market snapshot from a vendor extract you test, clean, and reconcile, written to HTML and Excel and run again for another date
4 Machine Learning Three models compared on a public file of company statements, each tested on rows it never saw
5 Advanced Machine Learning A logistic regression, a random forest, XGBoost, and LightGBM compared on a public file of company ratios where bankruptcies are rare
6 Neural Networks A neural network built in Keras and measured against LightGBM, all on an ordinary laptop CPU
7 NLP, RAG, and LLMs A covenant extraction tool, run on an indenture you have never seen, with every number checked against the text
8 Implementing Agentic AI A multi-agent credit desk that writes a morning brief from FOMC statements, an indenture, and the book's risk, with every figure traced to the tool that produced it
9 Deployment The morning brief as a public app: tested on every push, logged, costed, and deployed on free accounts
10 Implementing RAG A question-answering tool over public filings that cites the document and page behind every sentence, with its accuracy measured
Bonus Build Your Own Coding Agent A coding agent you write from an empty file, deployed to a private Hugging Face Space with your name on it

A look inside

Every result is drawn as a chart or a formatted table. These come straight from the notebooks.

Price against yield for four bonds
Course 2 · Price and yield
Duration, convexity, and the full reprice
Course 2 · Duration and convexity
Treasury curve slopes in basis points
Course 3 · Treasury curve slopes
Correlation of daily changes across Treasury tenors
Course 4 · Correlation across the curve
One company's model output split by SHAP value
Course 5 · A model output, by SHAP value
An indenture's sections as sentence embeddings
Course 7 · An indenture, as embeddings

A taste of day one

Q. QVNE pays 100 of principal in 5 years. Discounted at 5% a year, compounded twice a year, what is that payment worth today?

# ** raises a number to a power: 10 half-year periods at 2.5% each
discount_factor = 1 / (1 + 0.05 / 2) ** 10
# the present value of 100 paid in 5 years
present_value = 100 * discount_factor
print(f'The discount factor is {discount_factor:.6f}')
print(f'100 paid in 5 years is worth {present_value:.2f} today')
The discount factor is 0.781198
100 paid in 5 years is worth 78.12 today

In Excel you would type =1/(1+0.05/2)^10. The very next cell shows what happens when you type ^ in Python: it is not a power at all.

If you know Excel, you already know how to think about this

Nothing here asks you to forget Excel. Wherever Excel has a feature for the job, the new idea is introduced next to it, with the formula written out.

In Excel you would In Python you will Course
Fill a formula down a column Write the formula once, in a loop or on a whole array 1
Use VLOOKUP or INDEX and MATCH Merge two tables on a shared column 1
Build a pivot table Group by a column and summarize 1
Goal Seek a yield, or use RATE and YIELD Write a loop that solves the yield from a price 2

See all 158 comparisons, course by course.

What changes is what you get to keep. A spreadsheet holds the answer. Code holds the steps that produced it, so the same steps run again on tomorrow's file without anyone dragging a formula or repointing a range.

Start here

Run in Google Colab, with nothing to install

Tip

The fastest way in. Open the Course 1 map, pick a notebook, and click the Open in Colab badge at the top. Colab runs in your browser and needs only a Google account. Every notebook's first cell installs what it needs.

Use Colab on a personal account, with the course data only. Do not upload anything from your employer.

Run on your own Windows machine

Three steps: clone, install, open in VS Code

You need Python 3.13, VS Code with the Python and Jupyter extensions, and git. On a work machine, check your firm's policy before installing anything.

Two things to get right before Step 1.

Check What to do
Python on the PATH In the Python installer, tick Add python.exe to PATH on the first screen. If python is still not found later, use py -3.13 wherever a step says python.
Scripts allowed in PowerShell Run Set-ExecutionPolicy -Scope CurrentUser RemoteSigned once. Without it, Step 2 stops at Activate.ps1 with a message that running scripts is disabled.

Step 1. Get the course and open its folder.

mkdir $HOME\projects -Force
cd $HOME\projects
git clone https://github.com/lenamonj/python-fixed-income.git
cd python-fixed-income

No git, or not allowed to install it? On the repo's GitHub page choose Code, then Download ZIP, unzip it into projects, and cd into the unzipped folder.

Step 2. Create an environment and install everything the series needs.

python -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt

It is a large install: TensorFlow and PyTorch are in it, so allow time and a few gigabytes of disk. To install one course only, use that course folder's own requirements.txt instead.

Step 3. Open the folder in VS Code.

code .

Open course1_python_foundations\week1\day1\01_python_for_fixed_income_intro.ipynb, choose the .venv kernel in the top right, and run the first cell.

Keys and accounts

No notebook needs a key to run. Here is what you can add, course by course.
Course What you can add
1, 2, 4, 5, 6 Nothing. Course 2 uses git from its first day.
3 A free FRED API key to pull live data. Without one, every notebook still runs.
7 A free OpenRouter key, or an OpenAI key, for live model requests. Without one, week 3 replays the course's saved responses.
8 An OpenAI or OpenRouter key to run the agents live. Every run is recorded and replays without one.
9 Free GitHub, Vercel, and Hugging Face accounts and Docker Desktop to deploy for real. Create the Hugging Face account early: a free account hosts a Space only once it is 30 days old.
10 A key of your own for live answers. In Colab, the T4 GPU runtime is advised for the local-model cells and never required.
Bonus An OpenAI key for a live agent, and the Hugging Face account from Course 9 for its private Space.

Keys live in a .env file outside the course repo or in Colab's Secrets panel, never in a notebook or a commit.

How a day works

Inside a course, each day has its own folder, and each folder holds three files with the same name.

File What it is
1 NN_name_overview.pdf A short slide overview of the day's ideas. Read it first.
2 NN_name.ipynb The notebook. Work through it top to bottom.
3 NN_name_solutions.ipynb Worked answers to every exercise. Try each one yourself, then check.

Four habits run through every day.

Habit What it means
Excel side by side Wherever Excel has a function or feature for the job, it is shown next to the Python, formula included.
Errors on purpose Code that fails is run for real, and the error is read line by line.
Exercises you can check Each exercise has a check cell that tells you whether your number is right.
The AI check Each day ends with code written in the style of an AI assistant. It has one bug. You find it by checking the output against a number you worked out yourself.

Important

That last habit is the point of the series. You will use AI assistants to write code. Code that runs is not the same as code that is right, and the way to tell the difference is to know what the answer should be.

The courses

Each course has its own folder, course map, and install list. Weeks start again at 1 in every course. All ten courses and the Bonus course are ready.

Course Length What it covers
1 4 weeks Python Foundations: variables, lists, loops, and functions; files and debugging; NumPy and pandas; charts; exploratory data analysis; text; and a project
2 3 weeks Bond Math: time value of money, price and yield, day counts and accrued interest, duration, DV01, convexity, curve interpolation, spread, and DTS
3 3 weeks Market Data and Time Series: APIs and keys kept secret, market calendars, changes, volatility, z-scores, percentile ranks, slopes, butterflies, and SQL
4 3 weeks Machine Learning: regression on the spread cross-section, logistic regression, thresholds, decision trees, walk-forward validation, clustering, and PCA
5 3 weeks Advanced Machine Learning: bagging, random forests, boosting, XGBoost, LightGBM, stacking, honest tuning, rare events, and SHAP values
6 3 weeks Neural Networks: gradients by hand, dense networks in Keras, optimizers, regularization, and sequence models on the Treasury curve
7 3 weeks NLP, RAG, and LLMs: TF-IDF, embeddings, semantic search, EDGAR filings, large language models, and covenant extraction from real indentures
8 3 weeks Implementing Agentic AI: the agent loop by hand, tools, MCP, the OpenAI Agents SDK, an orchestrator with specialists, evals, and guardrails
9 3 weeks Deployment: GitHub, pull requests, CI, FastAPI, Vercel, Streamlit, Gradio, Hugging Face Spaces, Docker, and monitoring
10 3 weeks Implementing RAG: chunking, embeddings, FAISS, BM25 and hybrid search, reranking, citations, retrieval evaluation, and LLM judges
Bonus 1 notebook Build Your Own Coding Agent: a coding agent on OpenAI's Responses API, fenced tools, a chat page, and a private Space

Every model in the series describes its data. Nothing is a forecast, a rating, or a recommendation, and work on a real filing is descriptive extraction only.

The data

Every issuer, ticker, CUSIP, price, position, trade, and counterparty in the portfolio files is invented. The courses share one invented portfolio, built to behave like a real one. No real company and no real security appears in any holdings file.

The public files (Treasury yields, FOMC statements, SEC filings, and openly licensed research datasets) keep their values unchanged and their own terms. Licensed market data such as ICE BofA and Moody's series is pulled live with your own FRED key and never stored in the repo.

Every file, its source, its row count, and its terms are on the data page.

This product uses the FRED® API but is not endorsed or certified by the Federal Reserve Bank of St. Louis.

License

Code is released under the MIT License. The notebooks' written content, the slide overviews, and the videos are released under CC BY 4.0: you may share and adapt them, including commercially, as long as you give credit.

The public data files and documents keep their own terms, listed on the data page. They are not relicensed by this repo. The fonts in assets/fonts are under the SIL Open Font License, and their license files sit beside them.


Ready? Open Course 1 and run your first cell.

Created by Jeff Lenamon

About

Python for Fixed Income: a free course series that teaches Python from zero to people who work in fixed income, every example a bond or credit example

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages