Curve Building Script
Built-In Functions
asMonths
A curve function that breaks a single contract into a list of monthly contracts, e.g. a quarter into 3 months
Syntax
Contracts = asMonths(Contract)
Result
A Contracts object
Example
c = Contract(ondate, "2021Q01", 26.85)
contracts = asMonths(c)
for tenor in contracts
print tenor.absolute + " : " + tenor.value
next
2021M01 : 26.85
2021M02 : 26.85
2021M03 : 26.85
bootstrapCurve
Creates an arbitrage free monthly curve from an input curve
Description
The bootstrap function converts quarters, seasons and years into months and performs an arbitrage-free calculation on any overlapping periods.
Syntax
bootstrapped = bootstrapCurve(Curve)
Result
A curve with monthly tenors
Example
ondate = CurveDate(Date("2020-12-14"), "REOMHENG")
curve = Curve(ondate)
curve.add(Contract(ondate, "2021M01", 26.87))
curve.add(Contract(ondate, "2021Q01", 26.85))
curve.add(Contract(ondate, "2021Q02", 26.75))
bootstrapped = bootstrapCurve(curve)
for tenor in bootstrapped.contracts
print tenor.absolute + " : " + tenor.value
next
2021M01 : 26.87
2021M02 : 26.84
2021M03 : 26.84
2021M04 : 26.75
2021M05 : 26.75
2021M06 : 26.75
You can see in the example that 2021M02 and 2021M03 are calculated using the formula:
((2021Q01 * 3) - 2021M01) / 2
extendCurve
Extends a curve by a required number of years by using the value of the last maturity
Syntax
extended = extendCurve(curve, years)
The years parameter represents the number of years to extend the curve by. For example, if a curve ends in May 2022 and you specify 2 for years, the curve will be extends to December 2024.
Example
function agricultural(input)
// Agricultural curve forward filled and extended to end of 3 years
filled = forwardFillCurve(input)
extended = extendCurve(filled, 3)
agricultural = shape(extended)
end
forwardFillCurve
Fills any gaps in a curve by using the value from a previous maturity
Syntax
filled = forwardFillCurve(curve)
Result
The function checks for any gaps in the maturities of a curve and forward fills using the value of the maturity immediately before it.
Example
ondate = CurveDate(Date("2020-10-30"), "REOMHENG")
curve = Curve(ondate)
curve.add(Contract(ondate, "2020M11", 26.87))
curve.add(Contract(ondate, "2020M12", 26.85))
curve.add(Contract(ondate, "2021M01", 26.75))
curve.add(Contract(ondate, "2021M03", 26.62))
curve.add(Contract(ondate, "2021M04", 26.55))
filled = forwardFillCurve(curve)
for tenor in filled.contracts
other = curve\[tenor.tenor\]
if other
print tenor.tenor + " = " + tenor.value + " was " + other.value
else
print tenor.tenor + " = " + tenor.value
end
next
This produces the following output:
M00 = 26.870000 was 26.870000
M01 = 26.870000 was 26.850000
M02 = 26.750000 was 26.750000
M03 = 26.750000
M04 = 26.620000 was 26.620000
M05 = 26.550000 was 26.550000
shape
A curve function that shapes a monthly curve
Syntax
Curve = shape(Curve)
Result
A curve that is shaped using the a normalised shape based on the first 12 months of the input curve. It then shapes the rest of the curve in blocks of 12 months retaining the correct average values.
Example
ondate = CurveDate(Date("2020-10-30"), "REOMHENG")
curve = Curve(ondate)
curve.currency = "EUR"
curve.units = "MWH"
curve.add(Contract(ondate, "2020M11", 26.87))
curve.add(Contract(ondate, "2020M12", 26.85))
curve.add(Contract(ondate, "2021M01", 26.75))
curve.add(Contract(ondate, "2021M02", 26.65))
curve.add(Contract(ondate, "2021M03", 26.62))
curve.add(Contract(ondate, "2021M04", 26.55))
curve.add(Contract(ondate, "2021M05", 26.68))
curve.add(Contract(ondate, "2021M06", 26.89))
curve.add(Contract(ondate, "2021M07", 27.05))
curve.add(Contract(ondate, "2021M08", 27.15))
curve.add(Contract(ondate, "2021M09", 27.02))
curve.add(Contract(ondate, "2021M10", 26.85))
curve.add(Contract(ondate, "2021Q04", 26.92))
curve.add(Contract(ondate, "2022Y", 27.12))
curve.add(Contract(ondate, "2023Y", 27.20))
bootstrapped = bootstrapCurve(curve)
shaped = shape(bootstrapped)
for tenor in shaped.contracts
print tenor.absolute + " : " + tenor.value
next
2020M11 : 26.870000
2020M12 : 26.850000
2021M01 : 26.750000
2021M02 : 26.650000
2021M03 : 26.620000
2021M04 : 26.550000
2021M05 : 26.680000
2021M06 : 26.890000
2021M07 : 27.050000
2021M08 : 27.150000
2021M09 : 27.020000
2021M10 : 26.850000
2021M11 : 26.955000
2021M12 : 26.955000
2022M01 : 27.025839
2022M02 : 26.924628
2022M03 : 26.894362
2022M04 : 26.823741
2022M05 : 26.954893
2022M06 : 27.167080
2022M07 : 27.328824
2022M08 : 27.429710
2022M09 : 27.298558
2022M10 : 27.126726
2022M11 : 27.232819
2022M12 : 27.232819
2023M01 : 27.105562
2023M02 : 27.004051
2023M03 : 26.973696
2023M04 : 26.902867
2023M05 : 27.034406
2023M06 : 27.247219
2023M07 : 27.409440
2023M08 : 27.510624
2023M09 : 27.379085
2023M10 : 27.206746
2023M11 : 27.313152
2023M12 : 27.313152
This is the bootstrapped curve:
And here is the shaped curve:
SmartCurve Functions
#CurveScript
is the default script used for expressions in Smart Curves.
bootstrap
bootstrap is a shortcut version of bootstrapCurve which creates an arbitrage-free monthly curve from an input curve containing any number of:
- Months
- Quarters
- Seasons
- Years
Syntax
bootstrap(BASE)
bootstrapAndShape
This function first bootstraps an input curve and then shapes it using the default shaping algorithm.
Syntax
bootstrapAndShape(BASE)
multiplyByFactor
This function multiplies an input curve by a fixed factor
Syntax
multiplyByFactor(BASE, factor)
divideByFactor
This function divides an input curve by a fixed factor
Syntax
divideByFactor(BASE, factor)
addPremium
This function adds a fixed premium to an input curve
Syntax
addPremium(BASE, premium)
discount
This function subtracts a fixed discount from an input curve
Syntax
discount(BASE, discount)
flatCurve
This function creates a monthly curve with the same value for every tenor. It takes 2 parameters:
- Months - the number of months you want the curve to be
- Value - the value you want to assign every tenor
Syntax
flatCurve(12, 25.2)
interpolate
The function fills in any missing tenors in the input curve using the specified method, which can be one of:
- FORWARD
- BACKWARD
- LINEAR
- CUBIC
Syntax
interpolate(BASE, 'LINEAR')