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:
| Name | Description | Type |
|---|---|---|
| ondate | The CurveDate for this contract | CurveDate |
| tenor | The relative tenor of this contract | Scalar(String) |
| value | The value of this contract | Scalar |
| absolute | The absolute tenor name | Scalar(String) |
| relative | The relative tenor name | Scalar(String) |
| periodCodeType | The period code type, e.g. Month | Scalar(String) |
| expiry | The expiry or last trading date | Date |
| start | The start date of delivery of this contract | Date |
| end | The end date of delivery of this contract | Date |
| * | Any other dynamic property you want to add | Any |
| scalarValue | Get the value of this contract including the configured precision | String |
| status | The status information for this contract | Status |
Methods​
| Name | Description | Return Type |
|---|---|---|
| generateNext() | Generate a contract with the same type that is after this one | Contract |
| immediatelyAfter() | Get the contract with the same type that is immediately after this one or null if there isn't one | Contract |
| immediatelyBefore() | Get the contract with the same type that is immediately before this one or null if there isn't one | Contract |
| isImmediatelyAfter(other) | A test to see if the supplied contract is immediately after this one | Boolean |
| isImmediatelyBefore(other) | A test to see if the supplied contract is immediately before this one | Boolean |
| isOverlapping(other) | A test to see if the this contract is overlapping the supplied contract | Boolean |
| isWithin(other) | A test to see if the this contract is entirely within the supplied contract | Boolean |
| next() | Get the contract with the same type that is after this one or null if there isn't one | Contract |
| overlaps() | Gets a list of contracts that are overlapping with this contract | Contracts |
| previous() | Get the contract with the same type that is before this one or null if there isn't one | Contract |
| within() | Gets a list of contracts that are within this contract | Contracts |