Table of Contents

Class CommodityPricingHelperFunctions

Namespace
NanoQL.Experimental
Assembly
NanoQL.dll

QuantLib's CommodityPricingHelper, a class of static members: the conversion factors, a unit cost in the base currency and unit, and an energy swap's pricing periods.

[Experimental("NQL0001")]
public static class CommodityPricingHelperFunctions
Inheritance
CommodityPricingHelperFunctions
Inherited Members

Remarks

QuantLib declares a constructor it defines nowhere, so the class is never built; here it is a static class.

Methods

CalculateFxConversionFactor(Currency, Currency, Date, EvaluationContext)

The factor converting an amount in one currency into another at a date, through a direct lookup in the context's exchange rates: QuantLib's CommodityPricingHelper::calculateFxConversionFactor, whose lookup, unlike EnergyCommodity's, is direct.

public static double CalculateFxConversionFactor(Currency fromCurrency, Currency toCurrency, Date evaluationDate, EvaluationContext context)

Parameters

fromCurrency Currency

The amount's currency.

toCurrency Currency

The currency it is converted into.

evaluationDate Date

The date of the rates.

context EvaluationContext

The evaluation context, whose exchange rates are read.

Returns

double

1 between a currency and itself; otherwise the direct rate, or its reciprocal where it runs the other way.

Exceptions

ArgumentNullException

A currency or the context is null.

ArgumentException

evaluationDate is default(Date).

NanoQLException

No direct rate is held.

CalculateUnitCost(CommodityType, CommodityUnitCost, Currency, UnitOfMeasure, Date, EvaluationContext)

A unit cost as money per base unit in a base currency: QuantLib's CommodityPricingHelper::calculateUnitCost, the cost converted by the factor from the base unit to its unit (a price) and from its currency to the base currency, through a direct rate.

public static double CalculateUnitCost(CommodityType commodityType, CommodityUnitCost unitCost, Currency baseCurrency, UnitOfMeasure baseUnitOfMeasure, Date evaluationDate, EvaluationContext context)

Parameters

commodityType CommodityType

The commodity type.

unitCost CommodityUnitCost

The unit cost.

baseCurrency Currency

The base currency.

baseUnitOfMeasure UnitOfMeasure

The base unit.

evaluationDate Date

The date of the exchange rates.

context EvaluationContext

The evaluation context, whose unit conversions and exchange rates are read.

Returns

double

The cost per base unit; 0 for a zero cost.

Remarks

QuantLib converts the cost by its lookup's stored factor between the cost's unit and the base unit, which inverts a price where that factor is stored from the cost's unit: a cost of 0.1 a thousand-barrels reads 100 a barrel there and 1e-4 here; a gallon's is stored from the barrel, so 0.1 a gallon reads 4.2 a barrel in both.

Exceptions

ArgumentNullException

An argument is null.

NanoQLException

The cost's currency or unit is QuantLib's empty one, or a conversion or rate can't be found.

CalculateUomConversionFactor(CommodityType, UnitOfMeasure, UnitOfMeasure, EvaluationContext)

The value of one unit of a unit of measure in another, for a commodity type: QuantLib's CommodityPricingHelper::calculateUomConversionFactor, direction-aware.

public static double CalculateUomConversionFactor(CommodityType commodityType, UnitOfMeasure fromUnitOfMeasure, UnitOfMeasure toUnitOfMeasure, EvaluationContext context)

Parameters

commodityType CommodityType

The commodity type.

fromUnitOfMeasure UnitOfMeasure

The unit converted from.

toUnitOfMeasure UnitOfMeasure

The unit converted into.

context EvaluationContext

The evaluation context, whose unit conversions are read.

Returns

double

1 between a unit and itself; otherwise how many of the second unit one of the first is worth, the conversion's own Convert(Quantity) of a unit quantity.

Remarks

QuantLib returns the looked-up conversion's stored factor whatever its orientation, so its factor is one of the first in the second for 25 of the 30 ordered pairs of its six petroleum units and the reciprocal for five (BBL→MB, BBL→kl, BBL→KL_tk, GAL→BBL, l→BBL).

Exceptions

ArgumentNullException

An argument is null.

NanoQLException

No conversion is held.

CreatePricingPeriods(Date, Date, Quantity, EnergyCommodityDeliverySchedule, EnergyCommodityQuantityPeriodicity, PaymentTerm)

An energy swap's pricing periods between two dates: QuantLib's createPricingPeriods, a monthly period from each start, [start, start + 1M − 1], paid on the payment term's date after its end.

public static ImmutableArray<PricingPeriod> CreatePricingPeriods(Date startDate, Date endDate, Quantity quantity, EnergyCommodityDeliverySchedule deliverySchedule, EnergyCommodityQuantityPeriodicity qtyPeriodicity, PaymentTerm paymentTerm)

Parameters

startDate Date

The first period's start.

endDate Date

The date the last period starts before.

quantity Quantity

The quantity per period of the periodicity.

deliverySchedule EnergyCommodityDeliverySchedule

The delivery schedule: Monthly, each period the monthly quantity, or Daily, each the daily quantity times its days.

qtyPeriodicity EnergyCommodityQuantityPeriodicity

The quantity's periodicity: per month for a monthly schedule, per day for a daily one.

paymentTerm PaymentTerm

The payment term.

Returns

ImmutableArray<PricingPeriod>

The periods, which QuantLib appends to a list it is given; none when the start isn't before the end.

Remarks

A daily period's quantity is the daily quantity times its days, both ends counted: QuantLib's counts end − start, one day short, 300 barrels for January at 10 a day (Divergences/PricingPeriodTests.cs; FpML's PerCalendarDay, "deemed to apply once per Calendar Day").

The other schedules are refused, where QuantLib returns no period and its swaps then refuse "no pricing periods" or price as expired: its two branches read a schedule two ways, monthly as periods of its own tenor and daily as monthly periods summing its quantity, and no QuantLib case or caller says which a weekly, quarterly or yearly schedule means, while a constant, window or hourly one has no tenor. A caller builds such periods directly. A period starting on a month's last day ends the day before the same day next month (31 January to 27 February), and the last period may run past the end date, as QuantLib's.

Exceptions

ArgumentNullException

paymentTerm is null.

ArgumentException

A date is default(Date).

ArgumentOutOfRangeException

An enum argument isn't a member of its enum.

NanoQLException

The periodicity doesn't fit the schedule, or the schedule is neither monthly nor daily ("Invalid period quantity/pricing period combination.").