# 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.valuenext``
``2021M01 : 26.852021M02 : 26.852021M03 : 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.valuenext``
``2021M01 : 26.872021M02 : 26.842021M03 : 26.842021M04 : 26.752021M05 : 26.752021M06 : 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    endnext``

This produces the following output:

``M00 = 26.870000 was 26.870000M01 = 26.870000 was 26.850000M02 = 26.750000 was 26.750000M03 = 26.750000M04 = 26.620000 was 26.620000M05 = 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.valuenext``
``2020M11 : 26.8700002020M12 : 26.8500002021M01 : 26.7500002021M02 : 26.6500002021M03 : 26.6200002021M04 : 26.5500002021M05 : 26.6800002021M06 : 26.8900002021M07 : 27.0500002021M08 : 27.1500002021M09 : 27.0200002021M10 : 26.8500002021M11 : 26.9550002021M12 : 26.9550002022M01 : 27.0258392022M02 : 26.9246282022M03 : 26.8943622022M04 : 26.8237412022M05 : 26.9548932022M06 : 27.1670802022M07 : 27.3288242022M08 : 27.4297102022M09 : 27.2985582022M10 : 27.1267262022M11 : 27.2328192022M12 : 27.2328192023M01 : 27.1055622023M02 : 27.0040512023M03 : 26.9736962023M04 : 26.9028672023M05 : 27.0344062023M06 : 27.2472192023M07 : 27.4094402023M08 : 27.5106242023M09 : 27.3790852023M10 : 27.2067462023M11 : 27.3131522023M12 : 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)``

#### 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')``