hasquant
Safe HaskellNone
LanguageHaskell2010

QuantLib.Commodity

Synopsis

Types

Commodity types

Units of measure

data UnitOfMeasureType Source #

Constructors

Mass 
Volume 
Energy 
QuantityUnit 

Payment terms

data PaymentTerm Source #

Instances

Instances details
Show PaymentTerm Source # 
Instance details

Defined in QuantLib.Internal.Type

Eq PaymentTerm Source # 
Instance details

Defined in QuantLib.Internal.Type

data PaymentTermEventType Source #

Constructors

TradeDate 
PricingDate 

Instances

Instances details
Bounded PaymentTermEventType Source # 
Instance details

Defined in QuantLib.Internal.Common

Enum PaymentTermEventType Source # 
Instance details

Defined in QuantLib.Internal.Common

Read PaymentTermEventType Source # 
Instance details

Defined in QuantLib.Internal.Common

Show PaymentTermEventType Source # 
Instance details

Defined in QuantLib.Internal.Common

Eq PaymentTermEventType Source # 
Instance details

Defined in QuantLib.Internal.Common

Quantities and costs

type Quantity = (CommodityType, UnitOfMeasure, Double) Source #

An amount of a commodity: a CommodityType, a UnitOfMeasure, and a plain amount. Marshalled as a flat triple rather than a wrapper type (per the Money-as-tuple convention) -- and, unlike CommodityUnitCost below, its three inspectors are just tuple projections, so they need no binding at all. c2hs's & tuple-splitter only ever consumes two C arguments (confirmed against its source, not just by trial), so every function below that takes or returns a Quantity marshals it as three flat CommodityType/UnitOfMeasure/Double arguments instead of one combined tuple.

type CommodityUnitCost = (Double, Currency, UnitOfMeasure) Source #

A commodity's unit cost: a cash amount (a (Double, Currency) pair, standing in for QuantLib's Money) per UnitOfMeasure. A plain tuple, like Quantity -- it carries no calculation of its own upstream.

Date intervals and pricing periods

type DateInterval = (Day, Day) Source #

A date range, inclusive of both ends. No C++ call is needed for either operation below -- Day (from Data.Time.Calendar) already has the Ord instance QuantLib's own comparisons rely on, so both are plain Haskell functions rather than shim calls.

data PricingPeriod Source #

A DateInterval over which a fixed Quantity is priced, paid on pricingPeriodPaymentDate. Named fields keep the value readable across energy-swap APIs.

Instances

Instances details
Show PricingPeriod Source # 
Instance details

Defined in QuantLib.Commodity

Eq PricingPeriod Source # 
Instance details

Defined in QuantLib.Commodity

Unit conversions

data UnitOfMeasureConversionType Source #

Constructors

UomDirect 
UomDerived 

Instances

Instances details
Enum UnitOfMeasureConversionType Source # 
Instance details

Defined in QuantLib.Commodity

Read UnitOfMeasureConversionType Source # 
Instance details

Defined in QuantLib.Commodity

Show UnitOfMeasureConversionType Source # 
Instance details

Defined in QuantLib.Commodity

Eq UnitOfMeasureConversionType Source # 
Instance details

Defined in QuantLib.Commodity

Constructors

Commodity metadata

commodityType Source #

Arguments

:: String

code

-> String

name

-> IO CommodityType 

Construct a custom commodity type identified by its code (e.g. "HO") and descriptive name (e.g. "Heating Oil"). QuantLib has no fixed enum of commodity types -- every instance is user-registered by code, the same way a custom customCurrency is.

nullCommodityType :: IO CommodityType Source #

The fixed placeholder commodity type QuantLib itself uses where no real commodity type applies (e.g. in unit-of-measure-only conversions).

unitOfMeasure Source #

Arguments

:: String

name

-> String

code

-> UnitOfMeasureType 
-> IO UnitOfMeasure 

Construct a custom unit of measure from its descriptive name (e.g. "Barrels"), code (e.g. "BBL"), and type (massvolumeenergy/quantity).

lotUnitOfMeasure :: IO UnitOfMeasure Source #

The lot, a dimensionless 'UnitOfMeasure::Quantity' unit.

barrelUnitOfMeasure :: IO UnitOfMeasure Source #

Barrels (BBL), the base petroleum volume unit.

mtUnitOfMeasure :: IO UnitOfMeasure Source #

Metric tonnes (MT).

mbUnitOfMeasure :: IO UnitOfMeasure Source #

Thousand barrels (MB).

paymentTerm Source #

Arguments

:: String

name

-> PaymentTermEventType 
-> Int

offsetDays

-> Calendar 
-> IO PaymentTerm 

Construct a payment term: a named offset (in calendar-adjusted days) from either the trade date or the pricing-period end date.

pricingPeriod :: Day -> Day -> Day -> Quantity -> PricingPeriod Source #

Construct a PricingPeriod, enforcing upstream's DateInterval invariant that the end date is not before the start date.

unitOfMeasureConversion Source #

Arguments

:: CommodityType 
-> UnitOfMeasure

source

-> UnitOfMeasure

target

-> Double

conversionFactor

-> IO UnitOfMeasureConversion 

Construct a conversion factor between two units of measure for a given commodity type: a unit of source is worth conversionFactor units of target.

Mutators

Conversion repository

addUomConversion :: UnitOfMeasureConversion -> IO () Source #

Register a conversion with the global unit-of-measure conversion repository, replacing any existing conversion between the same commodity type and pair of units.

clearUomConversions :: IO () Source #

Reset the unit-of-measure conversion repository back to its built-in set of known petroleum conversion factors, discarding anything added via addUomConversion.

Global commodity settings

setCommoditySettingsCurrency :: Currency -> IO () Source #

Set the global commodity currency setting.

setCommoditySettingsUnitOfMeasure :: UnitOfMeasure -> IO () Source #

Set the global commodity unit-of-measure setting.

Inspectors

Quantity, period and conversion calculations

roundedQuantity :: Quantity -> Quantity Source #

Round a quantity's amount per its unit of measure's rounding convention. The commodity type and unit of measure are unaffected by rounding, so they're carried straight through in Haskell rather than round-tripped through the C++ call.

closeQuantity :: Quantity -> Quantity -> Int -> IO Bool Source #

Whether two quantities are close to within n ULPs (default 42 upstream), after converting the second to the first's unit of measure if their units differ (which throws unless a conversion is reachable -- see lookupUomConversion).

closeEnoughQuantity :: Quantity -> Quantity -> Int -> IO Bool Source #

As closeQuantity, but using QuantLib's relative (rather than absolute) closeness test.

isDateBetween Source #

Arguments

:: DateInterval 
-> Day

date

-> Bool

includeFirst

-> Bool

includeLast

-> Bool 

Whether a date falls within the interval, optionally excluding either end.

intersection :: DateInterval -> DateInterval -> Maybe DateInterval Source #

The overlap of two date intervals, or Nothing if they don't overlap at all (upstream returns a default-constructed, both-dates-null DateInterval in this case; a Maybe is the natural Haskell equivalent).

convertQuantity :: UnitOfMeasureConversion -> Quantity -> IO Quantity Source #

Apply the conversion factor to a quantity, converting it from the conversion's source to its target unit of measure (or vice versa). Throws if the quantity's unit of measure is on neither side of the conversion.

chainUnitOfMeasureConversion :: UnitOfMeasureConversion -> UnitOfMeasureConversion -> IO UnitOfMeasureConversion Source #

Combine two conversions sharing a common unit of measure into a derived conversion between their other two units. Throws if the conversions don't share a common unit.

Commodity metadata

commodityTypeCode :: CommodityType -> String Source #

The commodity code, e.g. "HO".

commodityTypeName :: CommodityType -> String Source #

The descriptive name, e.g. "Heating Oil".

commodityTypeEmpty :: CommodityType -> Bool Source #

Whether this is a usable instance (as opposed to one built via a default constructor).

unitOfMeasureName :: UnitOfMeasure -> String Source #

The descriptive name, e.g. "Barrels".

unitOfMeasureCode :: UnitOfMeasure -> String Source #

The code, e.g. "BBL", "MT".

unitOfMeasureType :: UnitOfMeasure -> UnitOfMeasureType Source #

The unit's type (massvolumeenergy/quantity).

unitOfMeasureEmpty :: UnitOfMeasure -> Bool Source #

Whether this is a usable instance (as opposed to one built via a default constructor).

paymentTermName :: PaymentTerm -> String Source #

The payment term's name, e.g. "Pricing end + 5 days".

paymentTermEventType :: PaymentTerm -> PaymentTermEventType Source #

Whether the offset is measured from the trade date or the pricing date.

paymentTermOffsetDays :: PaymentTerm -> Int Source #

The number of (calendar-adjusted) offset days.

paymentTermCalendar :: PaymentTerm -> IO Calendar Source #

The calendar used to adjust the payment date.

paymentTermEmpty :: PaymentTerm -> Bool Source #

Whether this is a usable instance (as opposed to one built via a default constructor).

paymentTermGetPaymentDate :: PaymentTerm -> Day -> IO Day Source #

Applies the term's offset (and calendar adjustment) to a trade or pricing-period-end date to get the actual payment date.

Pricing periods and conversions

unitOfMeasureConversionCommodityType :: UnitOfMeasureConversion -> IO CommodityType Source #

The commodity type this conversion applies to.

unitOfMeasureConversionType :: UnitOfMeasureConversion -> UnitOfMeasureConversionType Source #

Whether the conversion was given directly, or derived by chaining two other conversions.

unitOfMeasureConversionFactor :: UnitOfMeasureConversion -> Double Source #

The conversion factor: a unit of the source is worth this many units of the target.

unitOfMeasureConversionCode :: UnitOfMeasureConversion -> String Source #

A code identifying the conversion, e.g. "Heating OilMTBBL".

lookupUomConversion Source #

Look up a (possibly derived, via triangulation) conversion between two units of measure for a given commodity type. Throws if none can be found. Pre-populated with a set of known petroleum conversion factors even before any addUomConversion call.

Global commodity settings

commoditySettingsCurrency :: IO Currency Source #

The global commodity currency setting (defaults to USD).

commoditySettingsUnitOfMeasure :: IO UnitOfMeasure Source #

The global commodity unit-of-measure setting (defaults to barrels).