Treasury Spot-Futures#
Last updated: Mar 10, 2026, 3:43:25āÆPM
Table of Contents#
Pipeline Charts š
Pipeline Dataframes š
Pipeline Specs#
Pipeline Name |
Treasury Spot-Futures |
|---|---|
Pipeline ID |
|
Lead Pipeline Developer |
George Lord, Max Zhalilo |
Contributors |
George Lord, Max Zhalilo |
Git Repo URL |
|
Pipeline Web Page |
|
Date of Last Code Update |
2026-03-10 15:41:21 |
OS Compatibility |
|
Linked Dataframes |
About this project#
This project reproduces the Treasury spot-futures spread construction used in the appendix of \textit{Segmented Arbitrage} by Emil Siriwardane, Adi Sunderam, and Jonathan Wallen (2023) link In this repository, spreads are computed as implied repo minus interpolated OIS (in basis points) for five tenor labels using Bloomberg futures/OIS inputs and CRSP/WRDS bond inputs.
Quick Start#
The quickest way to run code in this repo is to use the following steps.
You must have TexLive (or another LaTeX distribution) installed on your computer and available in your path. You can do this by downloading and installing it from here (windows and mac installers).
First, create a virtual environment and activate it:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
Then install the python dependencies:
pip install -r requirements.txt
Also install the required TeX dependencies (Linux):
sudo apt-get install -y texlive-full
Note: Before you can run the project tasks, you may need to refer to āSetting Environment Variablesā to set your WRDS_USERNAME if you do not have the CRSP or bloomberg data in data_manual/.
Finally, run the project tasks:
doit
Other commands#
Unit Tests and Doc Tests#
You can run all the unit tests just by running the following from the repo root:
pytest
You can run the unit test, including doctests, with the following command:
pytest --doctest-modules
You can build the documentation with:
rm ./src/.pytest_cache/README.md
jupyter-book build -W ./
Use del instead of rm on Windows
Setting Environment Variables#
You can export your environment variables
from your .env files like so, if you wish. This can be done easily in a Linux or Mac terminal with the following command:
set -a # automatically export all variables
source .env
set +a
On Windows (PowerShell):
Get-Content .env | ForEach-Object { if ($_ -match '^([^=]+)=(.*)$') { [Environment]::SetEnvironmentVariable($matches[1], $matches[2], 'Process') } }
Formatting#
This project uses Ruff for linting and formatting Python code.
# Auto-fix linting issues (e.g., unused imports, undefined names)
ruff check . --fix
# Format code (consistent style, spacing, line length)
ruff format .
# Sort imports, then fix linting issues, then format
ruff format . && ruff check --select I --fix . && ruff check --fix .
ruff check --fixapplies safe auto-fixes for linting violationsruff formatformats code similar to Black--select Itargets only import sorting rules (isort-compatible)
General Directory Structure#
The
assetsfolder is used for things like hand-drawn figures or other pictures that were not generated from code. These things cannot be easily recreated if they are deleted.The
_outputfolder, on the other hand, contains dataframes and figures that are generated from code. The entire folder should be able to be deleted, because the code can be run again, which would again generate all of the contents.The
data_manualis for data that cannot be easily recreated. This data should be version controlled. Anything in the_datafolder or in the_outputfolder should be able to be recreated by running the code and can safely be deleted.Iām using the
doitPython module as a task runner. It works likemakeand the associatedMakefiles. To rerun the code, installdoit(https://pydoit.org/) and execute the commanddoitfrom thesrcdirectory. Note that doit is very flexible and can be used to run code commands from the command prompt, thus making it suitable for projects that use scripts written in multiple different programming languages.Iām using the
.envfile as a container for absolute paths that are private to each collaborator in the project. You can also use it for private credentials, if needed. It should not be tracked in Git.
Data and Output Storage#
Iāll often use a separate folder for storing data. Any data in the data folder can be deleted and recreated by rerunning the PyDoit command (the pulls are in the dodo.py file). Any data that cannot be automatically recreated should be stored in the ādata_manualā folder. Because of the risk of manually-created data getting changed or lost, I prefer to keep it under version control if I can. Thus, data in the ā_dataā folder is excluded from Git (see the .gitignore file), while the ādata_manualā folder is tracked by Git.
Output is stored in the ā_outputā directory. This includes dataframes, charts, and rendered notebooks. When the output is small enough, Iāll keep this under version control. I like this because I can keep track of how dataframes change as my analysis progresses, for example.
Of course, the _data directory and _output directory can be kept elsewhere on the
machine. To make this easy, I always include the ability to customize these
locations by defining the path to these directories in environment variables,
which I intend to be defined in the .env file, though they can also simply be
defined on the command line or elsewhere. The settings.py is responsible for
loading these environment variables and doing some preprocessing on them.
The settings.py file is the entry point for all other scripts to these
definitions. That is, all code that references these variables and others are
loaded by importing config.
Naming Conventions#
pull_vsload_: Files or functions that pull data from an external data source are prepended with āpull_ā, as in āpull_fred.pyā. Functions that load data that has been cached in the ādataā folder are prepended with āloadā. For example, inside of thepull_CRSP_Compustat.pyfile there is both apull_compustatfunction and aload_compustatfunction. The first pulls from the web, whereas the other loads cached data from the ā_dataā directory.
Dependencies and Virtual Environments#
Working with pip requirements#
This project uses pip with a virtual environment. Install requirements with:
pip install -r requirements.txt
To update the requirements file after adding new packages:
pip freeze > requirements.txt