Class EnergyCommodity
- Namespace
- NanoQL.Experimental
- Assembly
- NanoQL.dll
The base of energy commodity instruments: the swaps and the future, priced without an engine.
[Experimental("NQL0001")]
public abstract class EnergyCommodity : Commodity
- Inheritance
-
EnergyCommodity
- Derived
- Inherited Members
Remarks
An extension point. Each instrument values in the context's base currency and unit,
CommoditySettings, QuantLib's CommoditySettings, converting its prices and
quantities with the context's UnitOfMeasureConversions and
ExchangeRates.
A unit conversion factor here is the value of one unit of the first unit in the second, the conversion's own
Convert(Quantity) of a unit quantity, whichever way the conversion is stored; a quantity
converts to the base unit by the factor from its unit to the base, and a price, money per unit, by the factor from
the base to its unit. QuantLib's factor is the stored conversion's whatever its orientation, and its call sites
multiply a quantity by the factor from the base to its unit and a price by the factor from its unit to the base, so
one of the two is inverted: a payer vanilla swap on 1,000 gallons a month at a 0.5 spread prices 882,000 there, 42²
times its value, 500, here; on the base unit every factor is 1 and the prices are QuantLib's
(Divergences/EnergyUnitConversionTests.cs).
Constructors
EnergyCommodity(CommodityType, IReadOnlyDictionary<string, object>?)
Initializes a new instance of the EnergyCommodity class.
protected EnergyCommodity(CommodityType commodityType, IReadOnlyDictionary<string, object>? secondaryCosts)
Parameters
commodityTypeCommodityTypeThe commodity type.
secondaryCostsIReadOnlyDictionary<string, object>The secondary costs by name; null for none.
Exceptions
- ArgumentNullException
commodityTypeis null.
Properties
CommodityType
Gets the commodity type: the one the instrument was built with, or an energy swap's first period's.
public virtual CommodityType CommodityType { get; }
Property Value
Quantity
Gets the quantity the instrument delivers.
public abstract Quantity Quantity { get; }
Property Value
Methods
CalculateFxConversionFactor(Currency, Currency, Date, EvaluationContext)
The factor converting an amount in one currency into another at a date, through a derived lookup in the context's
exchange rates: QuantLib's EnergyCommodity::calculateFxConversionFactor.
protected static double CalculateFxConversionFactor(Currency fromCurrency, Currency toCurrency, Date evaluationDate, EvaluationContext context)
Parameters
fromCurrencyCurrencyThe amount's currency.
toCurrencyCurrencyThe currency it is converted into.
evaluationDateDateThe date of the rates.
contextEvaluationContextThe evaluation context, whose exchange rates are read.
Returns
- double
1 between a currency and itself; otherwise the rate, or its reciprocal where the rate found runs the other way.
Exceptions
- ArgumentNullException
A currency or the context is null.
- NanoQLException
No rate is held.
CalculateSecondaryCostAmounts(CommodityType, double, Date, EvaluationContext)
The secondary costs' amounts in the base currency: QuantLib's calculateSecondaryCostAmounts, a unit cost
per base unit times the quantity, a fixed amount converted.
protected ImmutableSortedDictionary<string, Money> CalculateSecondaryCostAmounts(CommodityType commodityType, double totalQuantityValue, Date evaluationDate, EvaluationContext context)
Parameters
commodityTypeCommodityTypeThe commodity type.
totalQuantityValuedoubleThe quantity a unit cost applies to, in the base unit.
evaluationDateDateThe date of the exchange rates.
contextEvaluationContextThe evaluation context.
Returns
- ImmutableSortedDictionary<string, Money>
The amounts by name; empty without secondary costs.
Exceptions
- ArgumentNullException
An argument is null.
- NanoQLException
A cost can't be converted ("error calculating secondary costs: …").
CalculateUnitCost(CommodityType, CommodityUnitCost, Date, EvaluationContext)
A unit cost as money per base unit in the base currency: QuantLib's EnergyCommodity::calculateUnitCost,
the cost converted by the factor from the base unit to its unit (a price) and from its currency to the base
currency.
protected static double CalculateUnitCost(CommodityType commodityType, CommodityUnitCost unitCost, Date evaluationDate, EvaluationContext context)
Parameters
commodityTypeCommodityTypeThe commodity type.
unitCostCommodityUnitCostThe unit cost.
evaluationDateDateThe date of the exchange rates.
contextEvaluationContextThe evaluation context, whose commodity settings, unit conversions and exchange rates are read.
Returns
- double
The cost per base unit; 0 for a zero cost.
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
EnergyCommodity::calculateUomConversionFactor, direction-aware.
protected static double CalculateUomConversionFactor(CommodityType commodityType, UnitOfMeasure fromUnitOfMeasure, UnitOfMeasure toUnitOfMeasure, EvaluationContext context)
Parameters
commodityTypeCommodityTypeThe commodity type.
fromUnitOfMeasureUnitOfMeasureThe unit converted from.
toUnitOfMeasureUnitOfMeasureThe unit converted into.
contextEvaluationContextThe 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.
Exceptions
- ArgumentNullException
An argument is null.
- NanoQLException
No conversion is held.