| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
QuantLib.Math
Description
Numeric helpers and matrix/vector value types.
RealMatrix stores dense numeric grids; boxed Matrix supports small or object-valued data.
Synopsis
- data Matrix a
- data RealMatrix
- type RealVector = Vector Double
- data NonEmptyVector a
- data TimeGrid
- data RoundingType
- data Rounding
- = NoRounding
- | Rounding !Int !RoundingType !Int
- data EndCriteriaType
- data EndCriteria = EndCriteria !Word !Word !Double !Double !Double
- data OptimizationMethod
- data Constraint
- data Interpolation
- data Interpolation2D
- data Approximation
- data PolynomialType
- data ComplexLogFormula
- data SalvagingAlgorithm
- data BinomialTree
- data HistogramAlgorithm
- = HistogramNone
- | Sturges
- | FD
- | Scott
- data CmsMarketCalibrationType
- data RngTrait
- data StatisticsTrait
- data SobolDirectionIntegers
- = Unit
- | Jaeckel
- | SobolLevitan
- | SobolLevitanLemieux
- | JoeKuoD5
- | JoeKuoD6
- | JoeKuoD7
- | Kuo
- | Kuo2
- | Kuo3
- data BoundaryConditionSide
- = BoundaryNone
- | Upper
- | Lower
- data FdmSchemeType
- data FdmScheme
- boxedRealMatrix :: Word -> Word -> [Double] -> Either String (Matrix Double)
- realMatrixFromVector :: Word -> Word -> RealVector -> Either String RealMatrix
- objectMatrix :: Word -> Word -> [a] -> Either String (Matrix a)
- singletonNonEmptyVector :: Storable a => a -> NonEmptyVector a
- consNonEmptyVector :: Storable a => a -> Vector a -> NonEmptyVector a
- nonEmptyVector :: Storable a => Vector a -> Maybe (NonEmptyVector a)
- timeGrid :: Double -> Word -> IO TimeGrid
- timeGridFromVector :: NonEmptyVector Double -> IO TimeGrid
- timeGridFromVectorWithSteps :: NonEmptyVector Double -> Word -> IO TimeGrid
- applyRounding :: Rounding -> Double -> Double
- optimize :: (RealVector -> Double) -> RealVector -> Maybe Constraint -> OptimizationMethod -> EndCriteria -> IO (RealVector, Double, EndCriteriaType)
- symmetricSchurDecomposition :: Matrix Double -> IO ([Double], Matrix Double)
- pseudoSqrt :: Matrix Double -> SalvagingAlgorithm -> IO (Matrix Double)
- rankReducedSqrt :: Matrix Double -> Word -> Double -> SalvagingAlgorithm -> IO (Matrix Double)
- choleskyDecomposition :: Matrix Double -> Bool -> IO (Matrix Double)
- choleskySolveFor :: Matrix Double -> [Double] -> IO [Double]
- riskStatisticsMean :: RealVector -> IO Double
- riskStatisticsStandardDeviation :: RealVector -> IO Double
- riskStatisticsVariance :: RealVector -> IO Double
- riskStatisticsSkewness :: RealVector -> IO Double
- riskStatisticsKurtosis :: RealVector -> IO Double
- riskStatisticsMin :: RealVector -> IO Double
- riskStatisticsMax :: RealVector -> IO Double
- riskStatisticsSemiVariance :: RealVector -> IO Double
- riskStatisticsSemiDeviation :: RealVector -> IO Double
- riskStatisticsDownsideVariance :: RealVector -> IO Double
- riskStatisticsDownsideDeviation :: RealVector -> IO Double
- riskStatisticsPercentile :: RealVector -> Double -> IO Double
- riskStatisticsGaussianPercentile :: RealVector -> Double -> IO Double
- riskStatisticsValueAtRisk :: RealVector -> Double -> IO Double
- riskStatisticsGaussianValueAtRisk :: RealVector -> Double -> IO Double
- riskStatisticsExpectedShortfall :: RealVector -> Double -> IO Double
- riskStatisticsGaussianExpectedShortfall :: RealVector -> Double -> IO Double
- riskStatisticsPotentialUpside :: RealVector -> Double -> IO Double
- riskStatisticsGaussianPotentialUpside :: RealVector -> Double -> IO Double
- riskStatisticsRegret :: RealVector -> Double -> IO Double
- riskStatisticsShortfall :: RealVector -> Double -> IO Double
- riskStatisticsAverageShortfall :: RealVector -> Double -> IO Double
- matrixRows :: Matrix a -> Word
- matrixColumns :: Matrix a -> Word
- matrixData :: Matrix a -> [a]
- realMatrixRows :: RealMatrix -> Word
- realMatrixColumns :: RealMatrix -> Word
- realMatrixData :: RealMatrix -> RealVector
- nonEmptyVectorToVector :: NonEmptyVector a -> Vector a
- timeAt :: TimeGrid -> Word -> IO Double
- size :: TimeGrid -> Word
- points :: TimeGrid -> IO RealVector
Types
Matrices, vectors and grids
data RealMatrix Source #
Row-major numeric matrix backed by contiguous storage. Use this for
large dense grids such as regression and volatility-surface data; small
process/correlation matrices remain boxed Matrix values; object
matrices retain Matrix because their elements need continuation-based FFI
marshalling rather than a raw contiguous pointer.
This representation interoperates directly with hmatrix without making
hasquant depend on it: Numeric.LinearAlgebra.reshape cols
realMatrixData makes a row-major hmatrix matrix view with no element copy.
The reverse conversion through flatten is zero-copy only for a contiguous
row-major hmatrix matrix; BLAS-produced or sliced matrices can require a
reorder/copy.
Instances
| Show RealMatrix Source # | |
Defined in QuantLib.Internal Methods showsPrec :: Int -> RealMatrix -> ShowS # show :: RealMatrix -> String # showList :: [RealMatrix] -> ShowS # | |
| Eq RealMatrix Source # | |
Defined in QuantLib.Internal | |
type RealVector = Vector Double Source #
Contiguous numeric data for APIs whose natural size is hundreds or thousands
of values. The public element type stays Double; C's double representation
is used only at the FFI boundary.
data NonEmptyVector a Source #
A storable vector known not to be empty. The constructor is deliberately
hidden; build one with singletonNonEmptyVector, consNonEmptyVector, or
nonEmptyVector.
Rounding and optimization
data RoundingType Source #
Instances
| Enum RoundingType Source # | |
Defined in QuantLib.Internal.Common Methods succ :: RoundingType -> RoundingType # pred :: RoundingType -> RoundingType # toEnum :: Int -> RoundingType # fromEnum :: RoundingType -> Int # enumFrom :: RoundingType -> [RoundingType] # enumFromThen :: RoundingType -> RoundingType -> [RoundingType] # enumFromTo :: RoundingType -> RoundingType -> [RoundingType] # enumFromThenTo :: RoundingType -> RoundingType -> RoundingType -> [RoundingType] # | |
| Read RoundingType Source # | |
Defined in QuantLib.Internal.Common Methods readsPrec :: Int -> ReadS RoundingType # readList :: ReadS [RoundingType] # | |
| Show RoundingType Source # | |
Defined in QuantLib.Internal.Common Methods showsPrec :: Int -> RoundingType -> ShowS # show :: RoundingType -> String # showList :: [RoundingType] -> ShowS # | |
| Eq RoundingType Source # | |
Defined in QuantLib.Internal.Common | |
Constructors
| NoRounding | |
| Rounding | |
Fields
| |
data EndCriteriaType Source #
Constructors
| EndNone | |
| MaxIterations | |
| StationaryPoint | |
| StationaryFunctionValue | |
| StationaryFunctionAccuracy | |
| ZeroGradientNorm | |
| Unknown |
Instances
data EndCriteria Source #
data OptimizationMethod Source #
data Constraint Source #
Constructors
| Boundary | |
| Composite | |
Fields
| |
| NoConstraint | |
| PositiveConstraint | |
Interpolation and numerical traits
data Interpolation Source #
Constructors
| BackwardFlat | |
| ForwardFlat | |
| Linear | |
| LogLinear | |
| Cubic !Approximation | |
| LogCubic !Approximation | |
| Abcd |
Instances
| Show Interpolation Source # | |
Defined in QuantLib.Internal.Common Methods showsPrec :: Int -> Interpolation -> ShowS # show :: Interpolation -> String # showList :: [Interpolation] -> ShowS # | |
| Eq Interpolation Source # | |
Defined in QuantLib.Internal.Common Methods (==) :: Interpolation -> Interpolation -> Bool # (/=) :: Interpolation -> Interpolation -> Bool # | |
data Interpolation2D Source #
Instances
data Approximation Source #
Constructors
| NaturalSpline !Bool | |
| Parabolic !Bool | |
| Kruger | |
| FritschButland |
Instances
| Read Approximation Source # | |
Defined in QuantLib.Internal.Common Methods readsPrec :: Int -> ReadS Approximation # readList :: ReadS [Approximation] # | |
| Show Approximation Source # | |
Defined in QuantLib.Internal.Common Methods showsPrec :: Int -> Approximation -> ShowS # show :: Approximation -> String # showList :: [Approximation] -> ShowS # | |
| Eq Approximation Source # | |
Defined in QuantLib.Internal.Common Methods (==) :: Approximation -> Approximation -> Bool # (/=) :: Approximation -> Approximation -> Bool # | |
data PolynomialType Source #
Constructors
| Monomial | |
| Laguerre | |
| Hermite | |
| Hyperbolic | |
| Legendre | |
| Chebyshev | |
| Chebyshev2nd |
Instances
| Enum PolynomialType Source # | |
Defined in QuantLib.Math Methods succ :: PolynomialType -> PolynomialType # pred :: PolynomialType -> PolynomialType # toEnum :: Int -> PolynomialType # fromEnum :: PolynomialType -> Int # enumFrom :: PolynomialType -> [PolynomialType] # enumFromThen :: PolynomialType -> PolynomialType -> [PolynomialType] # enumFromTo :: PolynomialType -> PolynomialType -> [PolynomialType] # enumFromThenTo :: PolynomialType -> PolynomialType -> PolynomialType -> [PolynomialType] # | |
| Read PolynomialType Source # | |
Defined in QuantLib.Math Methods readsPrec :: Int -> ReadS PolynomialType # readList :: ReadS [PolynomialType] # | |
| Show PolynomialType Source # | |
Defined in QuantLib.Math Methods showsPrec :: Int -> PolynomialType -> ShowS # show :: PolynomialType -> String # showList :: [PolynomialType] -> ShowS # | |
| Eq PolynomialType Source # | |
Defined in QuantLib.Math Methods (==) :: PolynomialType -> PolynomialType -> Bool # (/=) :: PolynomialType -> PolynomialType -> Bool # | |
data ComplexLogFormula Source #
Constructors
| Gatheral | |
| BranchCorrection | |
| AndersenPiterbarg | |
| AndersenPiterbargOptCV | |
| AsymptoticChF | |
| AngledContour | |
| AngledContourNoCV | |
| OptimalCV |
Instances
data SalvagingAlgorithm Source #
Algorithm used to salvage a matrix that is not positive semi-definite before taking its
pseudo square root. Higham only works for correlation matrices.
Constructors
| SalvagingNone | |
| Spectral | |
| Hypersphere | |
| LowerDiagonal | |
| Higham | |
| Principal |
Instances
data BinomialTree Source #
Constructors
Instances
| Enum BinomialTree Source # | |
Defined in QuantLib.Math Methods succ :: BinomialTree -> BinomialTree # pred :: BinomialTree -> BinomialTree # toEnum :: Int -> BinomialTree # fromEnum :: BinomialTree -> Int # enumFrom :: BinomialTree -> [BinomialTree] # enumFromThen :: BinomialTree -> BinomialTree -> [BinomialTree] # enumFromTo :: BinomialTree -> BinomialTree -> [BinomialTree] # enumFromThenTo :: BinomialTree -> BinomialTree -> BinomialTree -> [BinomialTree] # | |
| Read BinomialTree Source # | |
Defined in QuantLib.Math Methods readsPrec :: Int -> ReadS BinomialTree # readList :: ReadS [BinomialTree] # | |
| Show BinomialTree Source # | |
Defined in QuantLib.Math Methods showsPrec :: Int -> BinomialTree -> ShowS # show :: BinomialTree -> String # showList :: [BinomialTree] -> ShowS # | |
| Eq BinomialTree Source # | |
Defined in QuantLib.Math | |
data HistogramAlgorithm Source #
Constructors
| HistogramNone | |
| Sturges | |
| FD | |
| Scott |
Instances
data CmsMarketCalibrationType Source #
Constructors
| OnSpread | |
| OnPrice | |
| OnForwardCmsPrice |
Instances
Random sequences and statistics
Constructors
| PseudoRandom | |
| PoissonPseudoRandom | |
| LowDiscrepancy | |
| Ziggurat |
Instances
| Enum RngTrait Source # | |
| Read RngTrait Source # | |
| Show RngTrait Source # | |
| Eq RngTrait Source # | |
data StatisticsTrait Source #
Instances
data SobolDirectionIntegers Source #
Constructors
| Unit | |
| Jaeckel | |
| SobolLevitan | |
| SobolLevitanLemieux | |
| JoeKuoD5 | |
| JoeKuoD6 | |
| JoeKuoD7 | |
| Kuo | |
| Kuo2 | |
| Kuo3 |
Instances
Finite-difference schemes
data BoundaryConditionSide Source #
Constructors
| BoundaryNone | |
| Upper | |
| Lower |
Instances
data FdmSchemeType Source #
Constructors
| HundsdorferType | |
| DouglasType | |
| CraigSneydType | |
| ModifiedCraigSneydType | |
| ImplicitEulerType | |
| ExplicitEulerType | |
| MethodOfLinesType | |
| TrBDF2Type | |
| CrankNicolsonType |
Instances
| Enum FdmSchemeType Source # | |
Defined in QuantLib.Internal.Common Methods succ :: FdmSchemeType -> FdmSchemeType # pred :: FdmSchemeType -> FdmSchemeType # toEnum :: Int -> FdmSchemeType # fromEnum :: FdmSchemeType -> Int # enumFrom :: FdmSchemeType -> [FdmSchemeType] # enumFromThen :: FdmSchemeType -> FdmSchemeType -> [FdmSchemeType] # enumFromTo :: FdmSchemeType -> FdmSchemeType -> [FdmSchemeType] # enumFromThenTo :: FdmSchemeType -> FdmSchemeType -> FdmSchemeType -> [FdmSchemeType] # | |
| Read FdmSchemeType Source # | |
Defined in QuantLib.Internal.Common Methods readsPrec :: Int -> ReadS FdmSchemeType # readList :: ReadS [FdmSchemeType] # | |
| Show FdmSchemeType Source # | |
Defined in QuantLib.Internal.Common Methods showsPrec :: Int -> FdmSchemeType -> ShowS # show :: FdmSchemeType -> String # showList :: [FdmSchemeType] -> ShowS # | |
| Eq FdmSchemeType Source # | |
Defined in QuantLib.Internal.Common Methods (==) :: FdmSchemeType -> FdmSchemeType -> Bool # (/=) :: FdmSchemeType -> FdmSchemeType -> Bool # | |
Constructors
| FdmScheme | |
Fields
| |
| CraigSneyd | |
| Douglas | |
| ExplicitEuler | |
| Hundsdorfer | |
| ImplicitEuler | |
| ModifiedCraigSneyd | |
| ModifiedHundsdorfer | |
| MethodOfLines | |
Constructors
Matrices and vectors
boxedRealMatrix :: Word -> Word -> [Double] -> Either String (Matrix Double) Source #
Construct a list-backed numeric matrix for small-dimensional APIs such as process
correlation and diffusion matrices. Returns a boxed Matrix Double, not a
RealMatrix -- despite the shared RealMatrix spelling this is not the pair of
realMatrixFromVector, which is the constructor for the contiguous RealMatrix type.
Reach for this one when the dimensions are small and fixed (a correlation or diffusion
matrix), and for realMatrixFromVector for large dense numerical grids such as
volatility surfaces and multi-asset LSM data.
realMatrixFromVector :: Word -> Word -> RealVector -> Either String RealMatrix Source #
Construct a row-major numeric matrix backed by contiguous storage. This is the
constructor for RealMatrix; for a small correlation/diffusion matrix use
boxedRealMatrix, which yields a boxed Matrix Double instead.
singletonNonEmptyVector :: Storable a => a -> NonEmptyVector a Source #
consNonEmptyVector :: Storable a => a -> Vector a -> NonEmptyVector a Source #
nonEmptyVector :: Storable a => Vector a -> Maybe (NonEmptyVector a) Source #
Time grids
Arguments
| :: NonEmptyVector Double | mandatoryTimes |
| -> IO TimeGrid |
Time grid with mandatory time points. Mandatory points are guaranteed to belong to the grid. No additional points are added.
timeGridFromVectorWithSteps Source #
Arguments
| :: NonEmptyVector Double | mandatoryTimes |
| -> Word | steps |
| -> IO TimeGrid |
Time grid with mandatory time points. Mandatory points are guaranteed to belong to the grid. Additional points are then added with regular spacing between pairs of mandatory times in order to reach the desired number of steps.
Inspectors
Rounding and optimization
rounds a value to the precision and rule carried by the given Rounding
Arguments
| :: (RealVector -> Double) | cost function |
| -> RealVector | initial guess |
| -> Maybe Constraint | |
| -> OptimizationMethod | |
| -> EndCriteria | |
| -> IO (RealVector, Double, EndCriteriaType) |
Minimizes an arbitrary Haskell-defined cost function via QuantLib's general-purpose
Problem/OptimizationMethod machinery -- unlike calibrate, which drives a
CalibratedModel's own built-in calibration error against bound
CalibrationHelpers, this takes any 'RealVector -> Double' objective. The cost
function crosses back into Haskell once per outer optimizer iteration over the whole parameter
vector; see withCostFunction.
Matrix decompositions
symmetricSchurDecomposition Source #
Arguments
| :: Matrix Double | symmetric matrix |
| -> IO ([Double], Matrix Double) | eigenvalues, eigenvectors as columns |
Eigenvalues and eigenvectors of a real symmetric matrix, computed by the symmetric threshold
Jacobi algorithm. The eigenvalues come back in decreasing order, and the eigenvectors are the
columns of the returned matrix: column i belongs to the i-th eigenvalue.
Pseudo square root S of a real symmetric matrix M, i.e. the matrix with S*transpose S == M.
When M is not positive semi-definite the given SalvagingAlgorithm approximates it; with
SalvagingNone a non-positive-semi-definite input throws instead.
Arguments
| :: Matrix Double | symmetric matrix |
| -> Word | maxRank |
| -> Double | componentRetainedPercentage |
| -> SalvagingAlgorithm | |
| -> IO (Matrix Double) |
Rank-reduced pseudo square root of a real symmetric matrix: the result has rank at most
maxRank. If maxRank reaches the matrix size, the given percentage of the eigenvalues' sum
is retained instead.
choleskyDecomposition Source #
Cholesky factor L of a symmetric positive-definite matrix M, i.e. the lower-triangular
matrix with L*transpose L == M. Pass True for flexible to accept a merely positive
semi-definite (rank-deficient) input, whose factor is completed with zeroes rather than
producing nan.
Solves M*x == b given the Cholesky factor L of M -- the first argument is the factor
returned by choleskyDecomposition, not M itself.
Risk statistics
Arguments
| :: RealVector | sample |
| -> IO Double |
Mean of a caller-supplied sample. Each riskStatistics* call evaluates a fresh sample.
riskStatisticsStandardDeviation Source #
Arguments
| :: RealVector | sample |
| -> IO Double |
Standard deviation of the sample (square root of riskStatisticsVariance).
riskStatisticsVariance Source #
Arguments
| :: RealVector | sample |
| -> IO Double |
Variance of the sample, N/(N-1)-corrected.
riskStatisticsSkewness Source #
Arguments
| :: RealVector | sample |
| -> IO Double |
Skewness of the sample; 0 for a gaussian distribution.
riskStatisticsKurtosis Source #
Arguments
| :: RealVector | sample |
| -> IO Double |
Excess kurtosis of the sample; 0 for a gaussian distribution.
Arguments
| :: RealVector | sample |
| -> IO Double |
Minimum sample value. Throws if the sample is empty.
Arguments
| :: RealVector | sample |
| -> IO Double |
Maximum sample value. Throws if the sample is empty.
riskStatisticsSemiVariance Source #
Arguments
| :: RealVector | sample |
| -> IO Double |
Variance of the sample values falling below the sample mean (Markowitz semi-variance). Throws if fewer than two sample values fall below the mean.
riskStatisticsSemiDeviation Source #
Arguments
| :: RealVector | sample |
| -> IO Double |
Square root of riskStatisticsSemiVariance.
riskStatisticsDownsideVariance Source #
Arguments
| :: RealVector | sample |
| -> IO Double |
Variance of the sample values falling below zero. Throws if fewer than two sample values fall below zero.
riskStatisticsDownsideDeviation Source #
Arguments
| :: RealVector | sample |
| -> IO Double |
Square root of riskStatisticsDownsideVariance.
riskStatisticsPercentile Source #
Arguments
| :: RealVector | sample |
| -> Double | y |
| -> IO Double |
Empirical y-th percentile of the sample; y must lie in (0.0, 1.0].
riskStatisticsGaussianPercentile Source #
Arguments
| :: RealVector | sample |
| -> Double | y |
| -> IO Double |
y-th percentile assuming the sample is gaussian (mean/standard deviation matched); y
must lie in (0.0, 1.0).
riskStatisticsValueAtRisk Source #
Arguments
| :: RealVector | sample |
| -> Double | centile |
| -> IO Double |
Empirical value-at-risk at the given centile, which must lie in [0.9, 1.0) — a loss
(non-negative), the negative of the empirical (1-centile)-th percentile floored at zero.
riskStatisticsGaussianValueAtRisk Source #
Arguments
| :: RealVector | sample |
| -> Double | centile |
| -> IO Double |
Value-at-risk at the given centile assuming the sample is gaussian; centile must lie in
[0.9, 1.0).
riskStatisticsExpectedShortfall Source #
Arguments
| :: RealVector | sample |
| -> Double | centile |
| -> IO Double |
Empirical expected shortfall (conditional value-at-risk) at the given centile, which must
lie in [0.9, 1.0): the average of the sample values below the value-at-risk threshold.
Throws if the sample is empty, or if no sample value falls below the threshold.
riskStatisticsGaussianExpectedShortfall Source #
Arguments
| :: RealVector | sample |
| -> Double | centile |
| -> IO Double |
Expected shortfall at the given centile assuming the sample is gaussian; centile must
lie in [0.9, 1.0).
riskStatisticsPotentialUpside Source #
Arguments
| :: RealVector | sample |
| -> Double | centile |
| -> IO Double |
Empirical potential upside (the reciprocal notion of value-at-risk, floored at zero) at the
given centile, which must lie in [0.9, 1.0).
riskStatisticsGaussianPotentialUpside Source #
Arguments
| :: RealVector | sample |
| -> Double | centile |
| -> IO Double |
Potential upside at the given centile assuming the sample is gaussian; centile must lie
in [0.9, 1.0).
Arguments
| :: RealVector | sample |
| -> Double | target |
| -> IO Double |
Variance of the sample values falling below target (Dembo/Freeman regret). Throws if
fewer than two sample values fall below target.
riskStatisticsShortfall Source #
Arguments
| :: RealVector | sample |
| -> Double | target |
| -> IO Double |
Probability (fraction of the sample, by count) of falling below target. Throws if the
sample is empty.
riskStatisticsAverageShortfall Source #
Arguments
| :: RealVector | sample |
| -> Double | target |
| -> IO Double |
Average shortfall below target, i.e. the mean of target - x over sample values x
below target. Throws if no sample value falls below target.
Matrices and vectors
matrixRows :: Matrix a -> Word Source #
matrixColumns :: Matrix a -> Word Source #
matrixData :: Matrix a -> [a] Source #
realMatrixRows :: RealMatrix -> Word Source #
realMatrixColumns :: RealMatrix -> Word Source #
nonEmptyVectorToVector :: NonEmptyVector a -> Vector a Source #
Time grids
returns the time at the given index of the grid