Documentation
Explore the methodology and technicalities of the platform.
1.1 Data Source
For this project, I retrieved data from the Federal Reserve Economic Database API. This is a publicly available API which allows users to build applications relating to the US economy. Getting the primary source of data from this project from a credible source allowed for data integrity to be maintained, and for me to be able to build a robust data pipeline.
https://fred.stlouisfed.org/docs/api/fred/
1.2 Raw Data
The backbone of the data used for this project were a variety of macroeconomic indicators and bond yields. Firstly, I got the yields of US Treasuries of varying maturities, ranging from 1 month to 30 years. All can be seen on the Yield Curve tab. Along with this, the following macroeconomic indicators were retrieved:
- Consumer Price Index (CPI)
- Personal Consumption Expenditures (PCE)
- Producer Price Index (PPI)
- Gross Domestic Product (GDP)
- Unemployment Rate
- Credit Spread
- Job Openings and Labour Turnover Survey (JOLTS)
- Housing Starts
1.3 Data Pipeline
Once retrieving the data from the FRED API in Python, it was cleaned and processed into the format that was needed for analysis. Spreads were derived from the yield curve as recession indicators, as well as principal components to reduce the dimensions and give trading signals from the curve. Most indicators are released on a monthly or quarterly basis, so forward fills were applied to many columns to have daily indexing on my DataFrame.
The data was stored in a cloud-based Postgres database called Supabase. This allowed me to benefit from the built-in security and infrastructure of a cloud-based solution, and allowed me to connect to my frontend through API calls.
My frontend was developed in Next.js, using React components and written in TypeScript. This connected my database through API calls to my Supabase tables.
Finally, the Python scripts were scheduled to run on a daily basis using GitHub Actions, at 6:00pm GMT. This meant that each time the Federal Reserve released new macroeconomic data, the scripts would process the data and store them in Supabase. This meant I had up-to-date financial data in a consistent format in my database, still being updated daily.
2.1 Spreads
The page shows the spreads of the yield curve, which can be extremely useful for understanding the macro environment. Breaking this down, the 2s10s spread shows the difference between the 2-year and 10-year yield, the 3m10y spread shows the difference between the 3-month and 10-year yield and the 5s30s spread shows the difference between the 5-year and 30-year yield.
The 2s10s spread is the most quoted. It captures the middle of the curve. The 2-year yield is heavily influenced by short-term Federal Reserve interest rate decisions because it has a shorter maturity, whereas the 10-year yield represents longer term expectations for things like inflation and growth. When this spread goes below 0, it can be a recession indicator.
The 3m10y spread is sometimes preferred over the 2s10s. This is because the 3-month yield follows the market expectations for Fed interest rate decisions a lot more closely than the 2-year yield, which already includes some forward looking factors like inflation and GDP growth. Similarly, when the 3m10y spread inverts below 0, it can be a recession indicator.
The 5s30s spread is a lot more forward looking than the other two. It looks deeper into future macroeconomic expectations, and is less to do with what will happen with interest rates in the short term.
2.2 Level, Slope, Curvature
The yield curve can be decomposed into three principal factors that together explain most of its variation. These factors form the basis of our regime classification framework.
Level represents the overall height of the yield curve and the direction the yields are shifting across all maturities collectively. A high level environment generally corresponds to inflation expectations, while a low level environment suggests decreased fear of inflation.
Slope captures the difference between long-term and short-term yields. A steep curve (positive slope) suggests the market expects economic expansion and/or future rate hikes, while a flat or inverted curve (negative slope) signals expectations of slowing growth or anticipated interest rate cuts.
Curvature describes the relative yields of mid-term maturities compared to short and long term yields. Curvature is most relevant for relative value positioning and butterfly trades. A high curvature can represent uncertainty for the macro environment.
2.3 Market Regime Classification
There are four types of market regime that are derived from the principal components of the yield curve, i.e. the level, slope and curvature. The four types of regime are Bull Steepening, Bull Flattening, Bear Steepening and Bear Flattening.
In market regime classification, the Bull / Bear corresponds to the prices of bonds in the market. In a bull market, bond prices are rising meaning yields are falling, whereas in a bear market, bond prices are falling so yields are rising. This is all to do with the level of the curve being positive or negative.
The Steepening / Flattening corresponds to how the short-term and long-term yields are behaving in relation to each other. Ultimately, in a steepening market the differences between these are increasing whereas in a flattening market the differences are decreasing.
3.1 Coupon Payments
We are able to calculate the valuation of bonds using the Net Present Value formula. This discounts all of the future cash flows of the bonds by the market interest rate. This is because new bonds can be issued at the market interest rate, which could make the price of the original bond relatively expensive / cheaper / par-value.
As seen on the graph where the vertical dashed line intersects the curve, if this market interest rate remains the same as the bond's initial coupon payments, then the valuation of the bond is simply its face value. This means no gain or loss has been made from holding the bond. This would be a par-value bond.
To the left of the vertical line are all of the possible premium bonds. These occur when a bond has been bought at a certain interest rate, and then the market interest rate has dropped. This means the original bond pays a better coupon-payment than any new bonds that can be issued, increasing its value.
To the right are all the discount bonds. These occur when interest rates increase after a bond has been issued. This means investors can now issue new bonds at a better coupon rate, making the original bond less valuable to investors.
3.2 Bond Maturities
Bonds of higher maturities are more sensitive to changes in interest rates. This is because if interest rates change, the holder of the bond would bear the benefits or negatives of the bond's original coupon payments for a longer period of time.
This can be seen on the graph. Bonds with higher maturities are more convex whereas bonds with lower maturities are more linear. To add to this, bonds with higher maturities have much steeper gradients, representing the larger gain or loss with a change in interest rates.
4.1 Macaulay Duration
The Macaulay Duration measures the average time to receive the value from your bond. Since all bond coupon payments are equal throughout the life of a bond, you would expect this average time to be half of the bond's maturity. However, an investor would also be receiving the face value that they paid for the bond on the final coupon payment. This brings the average time forward. These coupon payments are all discounted by the market interest rate, so they are very heavily dependent on what happens in markets.
My model assumes that the yield (or the market interest rate) remains the same as the coupon payment for the bond. This is because the data from FRED is the CMT yield for par bonds. This is a simplifying assumption.
4.2 Modified Duration
The Modified Duration is the derivative of the bond price with respect to the yield or market interest rates. Essentially, it represents how many basis points a bond's price would change, in a positive or negative direction, with a 1% change in interest rates.
Intuitively, this can be confusing because this is also measured in years. However, it represents percentage in its most useful case.