Skip to main content

Contract

A contract is a single future period in time that represents a tradable future contract or a forecasted value on a curve

Introduction​

A contract, when used with commodity forward curves, is a structure that defines a delivery period for that contract and and associated information such as price and last trading day.

Construction​

To create a new contract, you need to use the contract construction function as shown below:

contract = Contract(CurveDate, PeriodCode, value)

The 3 parameters are as follows:

  • CurveDate - this is the CurveDate for this contract, it usually is the same as the curve that this contract is attached to, but can be different if you want to calculate expiry dates differently
  • PeriodCode - this is a string representation of the delivery period code, in either absolute or relative format.
  • Value - This is the price/value for the contract

Example creation of a contract:

// Create a curve
eombus = ExpiryCalendar(BusinessCalendar())
eombus.addRule("go to the end of the previous month")
ondate = CurveDate(Date("2020-10-13"), eombus)
curve = Curve(ondate)

// Create a contract
contract = Contract(ondate, "2020M11", 25.67)

// Add it to the curve
curve.add(contract)

This is what that contract looks like in JSON:

{
"tenor": "M01",
"value": 25.67,
"ondate": {
"curveDate": "2020-10-13",
"expiryCalendar": "eombus"
},
"properties": {
"absolute": "2020M11",
"end": "2020-11-30T00:00:00",
"expiry": "2020-10-31T00:00:00",
"relative": "M01",
"start": "2020-11-01T00:00:00"
}
}

You can see in the above example that there are a few properties automatically created and are described in the next section

Properties​

A contract has the following properties:

NameDescriptionType
ondateThe CurveDate for this contractCurveDate
tenorThe relative tenor of this contractScalar(String)
valueThe value of this contractScalar
absoluteThe absolute tenor nameScalar(String)
relativeThe relative tenor nameScalar(String)
periodCodeTypeThe period code type, e.g. MonthScalar(String)
expiryThe expiry or last trading dateDate
startThe start date of delivery of this contractDate
endThe end date of delivery of this contractDate
*Any other dynamic property you want to addAny
scalarValueGet the value of this contract including the configured precisionString
statusThe status information for this contractStatus

Methods​

NameDescriptionReturn Type
generateNext()Generate a contract with the same type that is after this oneContract
immediatelyAfter()Get the contract with the same type that is immediately after this one or null if there isn't oneContract
immediatelyBefore()Get the contract with the same type that is immediately before this one or null if there isn't oneContract
isImmediatelyAfter(other)A test to see if the supplied contract is immediately after this oneBoolean
isImmediatelyBefore(other)A test to see if the supplied contract is immediately before this oneBoolean
isOverlapping(other)A test to see if the this contract is overlapping the supplied contractBoolean
isWithin(other)A test to see if the this contract is entirely within the supplied contractBoolean
next()Get the contract with the same type that is after this one or null if there isn't oneContract
overlaps()Gets a list of contracts that are overlapping with this contractContracts
previous()Get the contract with the same type that is before this one or null if there isn't oneContract
within()Gets a list of contracts that are within this contractContracts