| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
QuantLib.Commodity
Synopsis
- data CommodityType
- data UnitOfMeasure
- data UnitOfMeasureType
- = Mass
- | Volume
- | Energy
- | QuantityUnit
- data PaymentTerm
- data PaymentTermEventType
- type Quantity = (CommodityType, UnitOfMeasure, Double)
- type CommodityUnitCost = (Double, Currency, UnitOfMeasure)
- type DateInterval = (Day, Day)
- data PricingPeriod
- type PricingPeriods = [PricingPeriod]
- data UnitOfMeasureConversion
- data UnitOfMeasureConversionType
- commodityType :: String -> String -> IO CommodityType
- nullCommodityType :: IO CommodityType
- unitOfMeasure :: String -> String -> UnitOfMeasureType -> IO UnitOfMeasure
- lotUnitOfMeasure :: IO UnitOfMeasure
- barrelUnitOfMeasure :: IO UnitOfMeasure
- mtUnitOfMeasure :: IO UnitOfMeasure
- mbUnitOfMeasure :: IO UnitOfMeasure
- gallonUnitOfMeasure :: IO UnitOfMeasure
- litreUnitOfMeasure :: IO UnitOfMeasure
- kilolitreUnitOfMeasure :: IO UnitOfMeasure
- tokyoKilolitreUnitOfMeasure :: IO UnitOfMeasure
- paymentTerm :: String -> PaymentTermEventType -> Int -> Calendar -> IO PaymentTerm
- pricingPeriod :: Day -> Day -> Day -> Quantity -> PricingPeriod
- unitOfMeasureConversion :: CommodityType -> UnitOfMeasure -> UnitOfMeasure -> Double -> IO UnitOfMeasureConversion
- addUomConversion :: UnitOfMeasureConversion -> IO ()
- clearUomConversions :: IO ()
- setCommoditySettingsCurrency :: Currency -> IO ()
- setCommoditySettingsUnitOfMeasure :: UnitOfMeasure -> IO ()
- roundedQuantity :: Quantity -> Quantity
- closeQuantity :: Quantity -> Quantity -> Int -> IO Bool
- closeEnoughQuantity :: Quantity -> Quantity -> Int -> IO Bool
- isDateBetween :: DateInterval -> Day -> Bool -> Bool -> Bool
- intersection :: DateInterval -> DateInterval -> Maybe DateInterval
- convertQuantity :: UnitOfMeasureConversion -> Quantity -> IO Quantity
- chainUnitOfMeasureConversion :: UnitOfMeasureConversion -> UnitOfMeasureConversion -> IO UnitOfMeasureConversion
- commodityTypeCode :: CommodityType -> String
- commodityTypeName :: CommodityType -> String
- commodityTypeEmpty :: CommodityType -> Bool
- unitOfMeasureName :: UnitOfMeasure -> String
- unitOfMeasureCode :: UnitOfMeasure -> String
- unitOfMeasureType :: UnitOfMeasure -> UnitOfMeasureType
- unitOfMeasureEmpty :: UnitOfMeasure -> Bool
- paymentTermName :: PaymentTerm -> String
- paymentTermEventType :: PaymentTerm -> PaymentTermEventType
- paymentTermOffsetDays :: PaymentTerm -> Int
- paymentTermCalendar :: PaymentTerm -> IO Calendar
- paymentTermEmpty :: PaymentTerm -> Bool
- paymentTermGetPaymentDate :: PaymentTerm -> Day -> IO Day
- pricingPeriodStartDate :: PricingPeriod -> Day
- pricingPeriodEndDate :: PricingPeriod -> Day
- pricingPeriodPaymentDate :: PricingPeriod -> Day
- pricingPeriodQuantity :: PricingPeriod -> Quantity
- unitOfMeasureConversionSource :: UnitOfMeasureConversion -> IO UnitOfMeasure
- unitOfMeasureConversionTarget :: UnitOfMeasureConversion -> IO UnitOfMeasure
- unitOfMeasureConversionCommodityType :: UnitOfMeasureConversion -> IO CommodityType
- unitOfMeasureConversionType :: UnitOfMeasureConversion -> UnitOfMeasureConversionType
- unitOfMeasureConversionFactor :: UnitOfMeasureConversion -> Double
- unitOfMeasureConversionCode :: UnitOfMeasureConversion -> String
- lookupUomConversion :: CommodityType -> UnitOfMeasure -> UnitOfMeasure -> UnitOfMeasureConversionType -> IO UnitOfMeasureConversion
- commoditySettingsCurrency :: IO Currency
- commoditySettingsUnitOfMeasure :: IO UnitOfMeasure
Types
Commodity types
data CommodityType Source #
Instances
| Show CommodityType Source # | |
Defined in QuantLib.Internal.Type Methods showsPrec :: Int -> CommodityType -> ShowS # show :: CommodityType -> String # showList :: [CommodityType] -> ShowS # | |
| Eq CommodityType Source # | |
Defined in QuantLib.Internal.Type Methods (==) :: CommodityType -> CommodityType -> Bool # (/=) :: CommodityType -> CommodityType -> Bool # | |
Units of measure
data UnitOfMeasure Source #
Instances
| Show UnitOfMeasure Source # | |
Defined in QuantLib.Internal.Type Methods showsPrec :: Int -> UnitOfMeasure -> ShowS # show :: UnitOfMeasure -> String # showList :: [UnitOfMeasure] -> ShowS # | |
| Eq UnitOfMeasure Source # | |
Defined in QuantLib.Internal.Type Methods (==) :: UnitOfMeasure -> UnitOfMeasure -> Bool # (/=) :: UnitOfMeasure -> UnitOfMeasure -> Bool # | |
data UnitOfMeasureType Source #
Constructors
| Mass | |
| Volume | |
| Energy | |
| QuantityUnit |
Instances
Payment terms
data PaymentTerm Source #
Instances
| Show PaymentTerm Source # | |
Defined in QuantLib.Internal.Type Methods showsPrec :: Int -> PaymentTerm -> ShowS # show :: PaymentTerm -> String # showList :: [PaymentTerm] -> ShowS # | |
| Eq PaymentTerm Source # | |
Defined in QuantLib.Internal.Type | |
data PaymentTermEventType Source #
Constructors
| TradeDate | |
| PricingDate |
Instances
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 #
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
| Show PricingPeriod Source # | |
Defined in QuantLib.Commodity Methods showsPrec :: Int -> PricingPeriod -> ShowS # show :: PricingPeriod -> String # showList :: [PricingPeriod] -> ShowS # | |
| Eq PricingPeriod Source # | |
Defined in QuantLib.Commodity Methods (==) :: PricingPeriod -> PricingPeriod -> Bool # (/=) :: PricingPeriod -> PricingPeriod -> Bool # | |
type PricingPeriods = [PricingPeriod] Source #
Unit conversions
data UnitOfMeasureConversion Source #
Instances
| Show UnitOfMeasureConversion Source # | |
Defined in QuantLib.Internal.Type Methods showsPrec :: Int -> UnitOfMeasureConversion -> ShowS # show :: UnitOfMeasureConversion -> String # showList :: [UnitOfMeasureConversion] -> ShowS # | |
| Eq UnitOfMeasureConversion Source # | |
Defined in QuantLib.Internal.Type Methods (==) :: UnitOfMeasureConversion -> UnitOfMeasureConversion -> Bool # (/=) :: UnitOfMeasureConversion -> UnitOfMeasureConversion -> Bool # | |
data UnitOfMeasureConversionType Source #
Constructors
| UomDirect | |
| UomDerived |
Instances
Constructors
Commodity metadata
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).
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).
gallonUnitOfMeasure :: IO UnitOfMeasure Source #
US gallons.
litreUnitOfMeasure :: IO UnitOfMeasure Source #
Litres.
kilolitreUnitOfMeasure :: IO UnitOfMeasure Source #
Kilolitres.
tokyoKilolitreUnitOfMeasure :: IO UnitOfMeasure Source #
Tokyo kilolitres.
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.
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
unitOfMeasureConversionSource :: UnitOfMeasureConversion -> IO UnitOfMeasure Source #
The source unit of measure.
unitOfMeasureConversionTarget :: UnitOfMeasureConversion -> IO UnitOfMeasure Source #
The target unit of measure.
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".
Arguments
| :: CommodityType | |
| -> UnitOfMeasure | source |
| -> UnitOfMeasure | target |
| -> UnitOfMeasureConversionType | |
| -> IO UnitOfMeasureConversion |
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).