Creating Term Structure of Futures Contracts Using R

The terms structure of the futures contracts for a specific asset is generated by the contracts prices at different expiration times. The contracts have different prices on each expiration date and there is an underlying relationship between them that is reflected with different shapes. The most common shapes are called normal or inverted forms. These shapes reflect the expectation of market participants from the asset.

The normal form is the most common structure of the contracts future prices at different maturities.  This shape is characterized by a positive relationship between futures prices and expiration dates, that is, the price of the futures contracts increases with its expiration time. Also this curve reveals factors such as supply and demand of the underlying assets when this is a commodity. 

In the inverted curve shape, distant future prices are lower than nearby future prices. This type of curve takes place when there are imbalances between supply and demand on a commodity. In periods of shortage in the supply of a commodity, producers go to the futures market in order to enter in a long position to secure short term prices and nearby expiration contracts go up in prices. 

The degree of the slope in the term structure, both in a normal or inverted market, is a signal about the expected future volatility of the asset. An important concept that arises from the term structure of futures contracts is the spread. This is the price difference between futures contracts from different maturities.

It is common that traders form spread positions by holding two different contracts in which they expect that the spread would narrow or widen in the future and can get profits on this prediction.  

To observe these patterns with real word data, we would get Gold futures prices data from a CSV file and explore the term structure of Gold Futures contracts. We start by reading the CSV file containing the futures contract prices of gold for the next periods, make some cleaning operations and finally plot the term structure.

# R by default assign a factor data type for dates, so we need to pass the parameter # stringsAsFactor = False, when read a csv in order to read dates as character type.

goldPrices <- read.csv("C:/Users/Nicolas/Downloads/futures-prices-intraday-07-25-2019.csv",stringsAsFactors = FALSE)

# Remove one row that have all Na values with complete.cases command

goldPrices <- goldPrices[complete.cases(goldPrices),]

# Observe the first rows of the goldPrices dataframe


This content is for paid members only.

Join our membership for lifelong unlimited access to all our data science learning content and resources.

Lesson Resources

All Users

Related Downloads