packages feed

hasquant-0.7.0.0: QuantLib/Instrument.chs

module QuantLib.Instrument
  (
    -- * Types
    -- ** Instrument hierarchy
    GenInstrument
  , Instrument

    -- ** Additional results
  , AdditionalResultVal(..)

    -- ** Exercises and callability
  , Exercise(..)
  , ExerciseType(..)
  , Callability(..)
  , CallabilityType(..)

    -- ** Conventions
  , PositionType(..)
  , SettlementType(..)
  , SettlementMethod(..)
  , OptionType(..)
  , BarrierType(..)
  , DoubleBarrierType(..)
  , PartialBarrierRange(..)
  , AverageType(..)
  , Seniority(..)
  , PricingModel(..)
  , PerpetualFuturesPayoffType(..)
  , PerpetualFuturesFundingType(..)

    -- * Constructors
  , asInstrument
  , perpetualFutures
  , composite

    -- * Mutators
  , setPricingEngine

    -- * Inspectors
  , npv
  , errorEstimate
  , isExpired
  , valuationDate
  , additionalResults
  ) where
import QuantLib.Internal
import QuantLib.Internal.Type hiding(ptr)
import QuantLib.Internal.Common

#include "qlTypesC2HS.h"
#include "qlEnumC2HS.h"
#include "qlEnumObjects.h"

#include "ql.h"

{#pointer *QlPricingEngine as PricingEngine foreign -> CPricingEngine nocode#}
{#pointer *QlInstrument as Instrument foreign -> CInstrument' nocode#}
{#pointer *Calendar foreign -> CCalendar nocode#}
{#pointer *DayCounter foreign -> CDayCounter nocode#}

{#enum SettlementType{} deriving(Show, Eq, Read)#}
{#enum SettlementMethod{} deriving(Show, Eq, Read)#}
{#enum BarrierType{} deriving(Show, Eq, Read)#}
{#enum DoubleBarrierType{} deriving(Show, Eq, Read)#}
{#enum PartialBarrierRange{} deriving(Show, Eq, Read)#}
{#enum AverageType{} deriving(Show, Eq, Read)#}
{#enum Seniority{} deriving(Show, Eq, Read)#}
{#enum PricingModel{} deriving(Show, Eq, Read)#}
{#enum RestructuringType{} deriving(Show, Eq, Read)#}
{#enum AtomicDefaultType{} deriving(Show, Eq, Read)#}
{#enum PerpetualFuturesPayoffType{} deriving(Show, Eq, Read)#}
{#enum PerpetualFuturesFundingType{} deriving(Show, Eq, Read)#}

-- |Constructs a perpetual future. Linear contracts settle and margin in the
-- domestic currency of the underlying FOR/DOM pair; Inverse contracts do so
-- in the foreign currency; Quanto contracts use a separate quanto currency.
-- A zero-length funding frequency selects continuous funding; otherwise
-- funding is discrete at the supplied period.
{#fun qlPerpetualFutures as perpetualFutures{fromEnumC`PerpetualFuturesPayoffType' -- ^payoffType
  ,fromEnumC`PerpetualFuturesFundingType' -- ^fundingType
  ,fromEnumQuantity`(Int,TimeUnit)'& -- ^fundingFrequency
  ,withCalendar*`Calendar' -- ^fundingCalendar
  ,withDayCounter*`DayCounter' -- ^fundingDayCounter
  ,preErrorCheck-`String'errorCheck*-}->`Instrument'peekInstrument*#}

-- |Returns the net present value of the given Instrument
{#fun qlInstrumentNPV as npv{withInstrument*`GenInstrument i',preErrorCheck-`String'errorCheck*-}->`Double'#}

-- |returns the error estimate on the NPV when available.
{#fun qlInstrumentErrorEstimate as errorEstimate{withInstrument*`GenInstrument i',preErrorCheck-`String'errorCheck*-}->`Double'#}

-- |returns whether the instrument might have value greater than zero.
{#fun qlInstrumentIsExpired as isExpired{withInstrument*`GenInstrument i',preErrorCheck-`String'errorCheck*-}->`Bool'#}

-- |returns the date the net present value refers to.
{#fun qlInstrumentValuationDate as valuationDate{withInstrument*`GenInstrument i',preErrorCheck-`String'errorCheck*-}->`Day'toDay#}

-- Re-registers QlAdditionalResult with c2hs's (per-file) pointer table as RawResultPtr,
-- so the {#fun#} below infers the right out-parameter type instead of an opaque Ptr (Ptr ()).
{#pointer *QlAdditionalResult as RawResultPtr nocode#}

-- |Returns QuantLib's `additionalResults()` map for the given Instrument, as an association list
-- keyed by the C++ result name. The map's values are populated by the pricing engine;
-- `additionalResults()` calls `calculate()` internally, so this is safe and idempotent after
-- pricing.
{#fun qlInstrumentAdditionalResults as additionalResults{withInstrument*`GenInstrument i',preArray-`[(String, AdditionalResultVal)]'&peekAdditionalResults*,preErrorCheck-`String'errorCheck*-}->`()'#}

-- |Builds a composite instrument whose NPV is the sum of the given instruments' NPVs, each scaled by its paired multiplier.
composite :: [(Instrument, Double)] -> IO Instrument
composite = (uncurry qlCompositeInstrument) . unzip

{#fun qlCompositeInstrument{withInstrumentArray*`[GenInstrument i]'& -- ^instruments
  ,withDoubleArray*`[Double]'& -- ^multipliers
  ,preErrorCheck-`String'errorCheck*-}->`Instrument'peekInstrument*#}

-- |Sets the pricing engine used to compute the instrument's results.
{#fun qlInstrumentSetPricingEngine as setPricingEngine{withInstrument*`GenInstrument i',withPricingEngine*`PricingEngine',preErrorCheck-`String'errorCheck*-}->`()'#}

-- vim: set ff=unix ts=8 sts=2 sw=2 et: