-- GENERATED by C->Haskell Compiler, version 0.28.8 Switcheroo, 25 November 2017 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "./QuantLib/Method.chs" #-}
-- |Monte Carlo path generation ('pathGenerator'\/'sobolPathGenerator'\/'next'\/'asset') plus
-- 'lsmRegress', a standalone Longstaff-Schwartz early-exercise regression primitive.
--
-- === Custom early exercise with a Haskell payoff
--
-- 'lsmRegress' lets a Haskell-defined payoff drive early exercise, something no bound pricing
-- engine offers: every early-exercise engine in "QuantLib.PricingEngine" (e.g.
-- @mcAmericanEngine@) computes its payoff entirely on the C++ side against a bound @Payoff@.
-- 'lsmRegress' is pure regression -- it never sees a payoff at all, so it works for any
-- underlying-state-dependent early-exercise payoff, not just a vanilla put\/call. The pattern,
-- worked in full in @test\/example\/QuantLib\/Example\/AmericanLSM.hs@:
--
-- 1. Draw two path sets with 'pathGenerator': a /calibration/ set used only to fit each date's
--    regression, and a separate /pricing/ set evaluated against the frozen fit. Splitting the
--    sets avoids the in-sample bias a single-pass fit-and-price would have (the same reason
--    @mcAmericanEngine@ exposes its own @nCalibrationSamples@ parameter). Use a fixed nonzero
--    seed for each -- seed @0@ means \"seed from entropy\" for 'PseudoRandom'.
-- 2. Read out the state at every exercise date, across all paths, with 'asset' (or 'assetAt'),
--    and transpose ('Data.List.transpose') into one state list per exercise date.
-- 3. Walk exercise dates *strictly backward*. At each date:
--
--     * discount both the calibration and pricing cashflow vectors by the one-step discount
--       factor (@discount(t[i+1]) \/ discount(t[i])@ from the underlying yield curve);
--     * compute the Haskell payoff at this date for every path in both sets;
--     * restrict the regression's fit inputs to *in-the-money calibration paths only*
--       (@fitStates@\/@fitTargets@ below);
--     * call 'lsmRegress' twice against that one fit -- once evaluating at the calibration
--       states (to keep the backward recursion's own targets self-consistent), once at the
--       pricing states (the actual out-of-sample continuation-value estimate);
--     * exercise wherever @payoff > continuationValue@ (@max(exercise, continuation)@), on each
--       path set independently.
--
-- 4. The pricing set's cashflows, discounted all the way back and averaged, are the estimated
--    price. Never evaluate the fit on the calibration set's own state for the reported price --
--    that reintroduces the in-sample bias step 1 split the paths to avoid.
--
-- A rough sketch (see the full example for discounting, ITM filtering, and the backward
-- recursion itself):
--
-- > step df calibS priceS calibCF priceCF = do
-- >   let calibTargets = map (* df) calibCF  -- discount to this date
-- >       (fitStates, fitTargets) = -- ITM calibration paths only
-- >         unzip $ filter (inTheMoney . fst) $ zip calibS calibTargets
-- >   contCalib <- lsmRegress Monomial order fitStates fitTargets calibS
-- >   contPrice <- lsmRegress Monomial order fitStates fitTargets priceS
-- >   -- exercise wherever payoff > continuation, on each path set
-- >   ...
--
-- Validated in the example against both @mcAmericanEngine@ pricing the equivalent bound vanilla
-- option (same process\/grid\/seed) and the published Longstaff-Schwartz (2001) reference value
-- for the same benchmark fixture.
--
-- The same pattern extends to a Haskell-defined /basket/ payoff (several correlated underlyings)
-- via 'lsmRegressMulti' \/ 'lsmBasisSize' in place of 'lsmRegress': read each exercise date's state
-- for every underlying (still with 'asset'\/'assetAt', once per underlying) into a 'Matrix' of one
-- row per path, and guard the ITM-fit-size check with 'lsmBasisSize' instead of the basis order --
-- the multi-asset basis has combinatorially many more terms than the scalar case.
--
-- To keep a fit and evaluate it later, split the combined call: 'lsmFit' returns the basis
-- coefficients and 'lsmEvaluate' applies them to new states. Both pick the basis by the state
-- matrix's column count -- the scalar basis of 'lsmRegress' at one column, the basis of
-- 'lsmRegressMulti' at several -- and share the combined calls' native code, so within one build
-- fitting then evaluating gives the combined call's values bit for bit. Across builds the bits are
-- not promised: 'lsmEvaluatorIdentity' names the basis revision, QuantLib version, compiler and
-- architecture, so a stored fit can be refused elsewhere. It is necessary, not sufficient: a
-- library rebuilt under the same version string keeps it.
--
-- Both Chebyshev types are QuantLib's weighted bases, undefined outside (-1, 1): with a state there
-- the least-squares solve of every regression above does not return. Scale the states into that
-- interval or choose another 'PolynomialType'.
--
-- @test\/example\/QuantLib\/Example\/HaskellLSM.hs@ benchmarks 'lsmRegress' against the same
-- backward induction with the per-date regression reimplemented from scratch in plain Haskell
-- (QuantLib used only for path generation) -- a worked illustration of why this module exposes
-- the regression as a batched primitive instead of leaving callers to reinvent it.
--
-- === Finite-difference PDE solving
--
-- This module also binds a full-grid finite-difference (FDM) driver, built up across two related
-- issues (custom step-condition\/operator hooks, then custom inner-value calculators) and spread
-- across several functions with no single overview until now. Worked in full in
-- @test\/example\/QuantLib\/Example\/Fdm.hs@ -- every snippet below is a trimmed extract from that
-- file; read it end to end for the full picture (discounting, fixtures, imports).
--
-- In one sentence, for anyone new to FDM pricing: instead of an integral (Monte Carlo) or a
-- closed-form formula (an @analytic*Engine@), you discretize the underlying's state space (e.g.
-- log-spot) into a grid of points, put the option's payoff on the grid at maturity, and step it
-- /backward/ to today, solving a small local linear system at each timestep. Reach for it when you
-- need American\/Bermudan-style early exercise (a plain Monte Carlo run can't do backward induction
-- the way a grid can) or a process\/payoff with no closed-form price. If a bound @analytic*Engine@
-- or @mc*Engine@ already covers your case (see "QuantLib.PricingEngine"), prefer that instead --
-- it's simpler, and this module's own examples validate their FDM results against exactly those
-- engines.
--
-- ==== Walkthrough: which function do I actually want?
--
-- Start here rather than at the reference list below -- picking the right entry point up front
-- avoids reading five functions' haddock only to discover a sixth was the one you needed.
--
-- [@\"I have a grid already, just roll it back\"@] 'fdmRollback'. Supply the grid as a plain
--   @[Double]@ (one value per state, at maturity) plus three Haskell closures describing the PDE
--   operator, and get the same grid rolled back to today -- no mesher, no
--   'FdmInnerValueCalculator', the simplest possible entry point:
--
--   > let grid0 = map (\x -> max (exp x - strike) 0) xs   -- payoff at maturity, one value per grid point
--   > fdmEuro <- fdmRollback 1 applyFn applyDirFn solveFn Nothing [] Douglas grid0 tMat 0 nSteps 0
--
-- [@\"...and I need early exercise\"@] the same 'fdmRollback' call, plus a /step condition/: a
--   @t -> [Double] -> [Double]@ closure called once per outer timestep with the whole current grid,
--   returning it clamped to whatever the early-exercise rule requires:
--
--   > let stepCond _t u = zipWith max u grid0   -- American: value can never fall below intrinsic
--   > fdmAmerican <- fdmRollback 1 applyFn applyDirFn solveFn (Just stepCond) stepTimes Douglas grid0 tMat 0 nSteps 0
--
-- [@\"I'd rather not hand-build the initial grid myself\"@] 'fdmSolve' -- 'fdmRollback''s sibling.
--   Same operator\/step-condition\/scheme machinery, but the initial condition comes from an
--   'FdmMesher' plus an 'FdmInnerValueCalculator' evaluated at each node, instead of a grid you
--   assembled by hand. Worth it once the mesher is doing real work (e.g. concentrating points near
--   a strike or barrier) rather than just wrapping a list you already had:
--
--   > mesh1d <- predefined1dMesher xs
--   > mesher <- fdmMesherComposite [mesh1d]
--   > let ivFn _t loc = case loc of [x] -> intrinsicAt x; _ -> error "expected a 1D location"
--   > withCustomFdmInnerValueCalculator mesher ivFn ivFn $ \calc ->
--   >   fdmSolve mesher calc 1 applyFn applyDirFn solveFn Nothing [] Douglas tMat 0 nSteps 0
--
-- [@\"my payoff is a standard vanilla\/log payoff, I don't want a per-node callback\"@] skip
--   'withCustomFdmInnerValueCalculator' and reach for one of the /native/ calculators instead --
--   QuantLib's own built-in 'FdmInnerValueCalculator' subclasses, bound directly so pricing a plain
--   payoff doesn't pay a Haskell round-trip per grid node:
--
--   > logCalc <- fdmLogInnerValue payoff mesher 0        -- striked payoff on a log-spot grid
--   > fdmLogEuro <- fdmSolve mesher logCalc 1 applyFn applyDirFn solveFn Nothing [] Douglas tMat 0 nSteps 0
--
--   'fdmZeroInnerValue' (always 0), 'fdmCellAveragingInnerValue'\/'withCustomCellAveragingInnerValue'
--   (identity or custom @gridMapping@), and 'fdmLogInnerValue' (@gridMapping = exp@, the common case
--   on a log-spot grid) round out the set -- see the reference entries below for the exact
--   cell-averaging-vs-point-evaluation contract each one has. Reach for
--   'withCustomFdmInnerValueCalculator' only once none of these fit your payoff shape.
--
-- [@\"my payoff depends on more than one underlying\"@] build one 'Fdm1dMesher' per underlying and
--   combine them with 'fdmMesherComposite'; 'fdmLogBasketInnerValue' takes a basket payoff (e.g.
--   @Max@, see "QuantLib.Instrument.Option") evaluated across all dimensions at once:
--
--   > basketMesher <- fdmMesherComposite [mesh1d, mesh1d]   -- two correlated log-spot dimensions
--   > basketCalc <- fdmLogBasketInnerValue (Max payoff) basketMesher
--   > val <- fdmAvgInnerValue basketCalc basketMesher [i, j] tMat   -- inspect one node directly
--
-- [@\"I want to price a swap\/swaption under a calibrated short-rate model\"@] the most specialized
--   entry points here: 'fdmAffineG2ModelSwapInnerValue'\/'fdmAffineHullWhiteModelSwapInnerValue'
--   drive the same calculator @fdG2SwaptionEngine@\/@fdHullWhiteSwaptionEngine@ already use
--   internally. Reach for these directly only when composing your own custom FDM pipeline around
--   this calculator; if a plain Bermudan-swaption NPV is all you need, prefer those two
--   already-bound black-box engines from "QuantLib.PricingEngine" instead.
--
-- [@\"I just want one node's value, no PDE solve\"@] 'fdmInnerValue'\/'fdmAvgInnerValue' evaluate
--   any bound calculator -- custom or native -- at a single mesher node directly, without
--   assembling a whole 'fdmSolve'. Handy as a sanity check while developing (as @Fdm.hs@'s own
--   tests do throughout), or whenever a single point's intrinsic value is all you actually need.
--
-- ==== Technical reference
--
-- The terse version of the above, for a reader who already knows the vocabulary and wants the
-- exact contract rather than the walkthrough's prose.
--
-- [@Rolling a grid back@] 'fdmRollback' takes a precomputed initial grid (a plain @[Double]@) and
--   rolls it back through time via three Haskell-defined operator callbacks
--   (@withFdmApply@ et al. below) plus an optional step condition (e.g.
--   American\/Bermudan early exercise). These callbacks cross the language boundary once per outer
--   timestep, over the /whole/ grid. 'fdmSolve' is the sibling that instead derives its own
--   initial grid from a mesher and
--   an 'FdmInnerValueCalculator' (below), reusing the same operator\/step-condition machinery.
--
-- [@Building a grid@] 'Fdm1dMesher's ('predefined1dMesher', 'uniform1dMesher',
--   'concentrating1dMesher', 'fdmBlackScholesMesher', and the other process-specific meshers) each
--   describe one PDE dimension; 'fdmMesherComposite' combines one or more into the multi-dimensional
--   'FdmMesher' 'fdmSolve' and 'FdmInnerValueCalculator' operate over. 'fdmMesherLocations' reads a
--   dimension's real-valued node locations back out, e.g. to map a flat result array back to
--   coordinates. 'gluedMesher' splices two 'Fdm1dMesher's end to end (e.g. a fine mesh near a
--   barrier glued to a coarse one further out) -- their ranges must already be ordered and
--   non-overlapping, and a shared boundary point is deduplicated automatically.
--
-- [@Custom inner values, fully general@] 'withCustomFdmInnerValueCalculator' wraps a Haskell
--   @t -> location -> value@ pair of functions as an 'FdmInnerValueCalculator'. Unlike every
--   callback above, this one crosses the language boundary once /per grid node/ -- there is no
--   batched shape for it anywhere in QuantLib or QuantLib-SWIG, so the real per-call cost is
--   accepted, matching QuantLib-SWIG's own @FdmInnerValueCalculatorDelegate@ precedent.
--   The calculator and native dependents retain both callbacks after the continuation returns;
--   callback exceptions are rethrown by the enclosing Haskell call.
--
-- [@Custom inner values, native@] QuantLib's own concrete 'FdmInnerValueCalculator' subclasses are
--   bound directly, for the common cases that don't need a per-node Haskell callback at all:
--   'fdmZeroInnerValue' (always 0), 'fdmCellAveragingInnerValue'\/'fdmLogInnerValue' (a payoff
--   cell-averaged -- Simpson-integrated across each grid cell, not just evaluated at its center --
--   with an identity or @exp@ value mapping respectively), and 'fdmLogBasketInnerValue' (the
--   multi-asset counterpart, one @exp@ mapping per dimension). These retain their payoff,
--   including any Haskell callback it owns. There is also
--   'withCustomCellAveragingInnerValue', the one native constructor that /does/ take an explicit
--   @gridMapping@ callback, retained by the native calculator. 'fdmAffineG2ModelSwapInnerValue'\/'fdmAffineHullWhiteModelSwapInnerValue' price a swap
--   under a calibrated 'QuantLib.Model.G2'\/'QuantLib.Model.HullWhite' model directly -- the same
--   calculator @fdG2SwaptionEngine@\/@fdHullWhiteSwaptionEngine@ use internally.
--
-- [@Inspecting a calculator directly@] 'fdmInnerValue'\/'fdmAvgInnerValue' evaluate any bound
--   calculator (custom or native) at a single mesher node, without assembling a whole 'fdmSolve' --
--   useful for a targeted self-consistency check, as @Fdm.hs@'s own tests do throughout.
--
-- === What's deliberately not bound: operators, schemes, boundary conditions
--
-- QuantLib-SWIG also exposes QuantLib's concrete 'FdmLinearOpComposite' subclasses (@FdmBlackScholesOp@,
-- @FdmHestonOp@, @FdmG2Op@, ...), its scheme objects (@DouglasScheme@, @CraigSneydScheme@,
-- @HundsdorferScheme@, ...), and its @FdmBoundaryCondition@ family as real C++ objects. hasquant does
-- not mirror these, and won't by default -- it's a design boundary already crossed once, not a gap.
--
-- 'fdmRollback'\/'fdmSolve' take the operator, the implicit-solve step, and the scheme all as Haskell
-- closures instead (@applyFn@\/@applyDirFn@\/@solveFn@ above). That's the same "coarsen the
-- language-boundary crossing" call already made for step conditions: bind the reusable numerical
-- /primitive/ (rollback through a fixed timestep, of an arbitrary tridiagonal\/multi-dimensional
-- operator) and let Haskell drive it, rather than bind every concrete operator\/scheme QuantLib ships
-- as its own object. @test\/example\/QuantLib\/Example\/Fdm.hs@'s hand-rolled 'operatorBands'\/'applyOp'
-- /is/ the replacement for @FdmBlackScholesOp@ + @DouglasScheme@, not a stand-in waiting for those to
-- get bound -- pricing a new payoff\/process combination here means writing its operator once in
-- Haskell, not calling into fifteen QuantLib operator classes one by one.
--
-- Binding the operator\/scheme family as objects would add a second, redundant way to drive the same
-- 'fdmSolve'\/'fdmRollback' backbone, without extending what's actually solvable -- anything a bound
-- @FdmXxxOp@ could do, a Haskell @applyFn@ already can. Revisit only if a concrete need shows up that
-- the callback shape genuinely can't express (none has, so far).
module QuantLib.Method
  (
    -- * Types
    -- ** Path and random sequences
    PathGenerator
  , SamplePath
  , GaussianRsg

    -- ** Finite differences
  , Fdm1dMesher
  , FdmMesher
  , FdmInnerValueCalculator

    -- * Constructors
    -- ** Path generation
  , pathGenerator
  , sobolPathGenerator
    -- ** Random sequence generation
  , gaussianRsg
  , sobolGaussianRsg
    -- ** Finite-difference meshers
  , predefined1dMesher
  , uniform1dMesher
  , concentrating1dMesher
  , concentrating1dMesherMulti
  , gluedMesher
  , fdmBlackScholesMesher
  , fdmCev1dMesher
  , exponentialJump1dMesher
  , fdmSimpleProcess1dMesher
  , fdmHestonVarianceMesher
  , fdmHestonLocalVolatilityVarianceMesher
  , fdmMesherComposite
    -- ** Finite-difference inner-value calculators
  , withCustomFdmInnerValueCalculator
  , fdmZeroInnerValue
  , fdmCellAveragingInnerValue
  , withCustomCellAveragingInnerValue
  , fdmLogInnerValue
  , fdmLogBasketInnerValue
  , fdmAffineG2ModelSwapInnerValue
  , fdmAffineHullWhiteModelSwapInnerValue

    -- * Inspectors
    -- ** Path and random sequences
  , next
  , antithetic
  , nextSequence
    -- ** Longstaff-Schwartz regression
  , lsmRegress
  , lsmBasisSize
  , lsmRegressMulti
  , lsmFit
  , lsmEvaluate
  , lsmEvaluatorIdentity
    -- ** Finite differences
  , fdmRollback
  , fdmInnerValue
  , fdmAvgInnerValue
  , fdmSolve
    -- ** Paths
  , weight
  , assetNumber
  , pathSize
  , assetAt
  , asset
    -- ** Random sequences and meshers
  , rsgDimension
  , lastSequence
  , pathGeneratorSequence
  , fdmMesherLocations
  ) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.ForeignPtr as C2HSImp
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified System.IO.Unsafe as C2HSImp







import QuantLib.Internal
import qualified QuantLib.Internal.Callback as Callback
import QuantLib.Internal.Type hiding (ptr) -- c2hs {#get#} binds its own `ptr'
import QuantLib.Internal.Common
import QuantLib.Math
{-# LINE 309 "./QuantLib/Method.chs" #-}

import Foreign.C.String(peekCString)
import Foreign.C.Types(CDouble)
import Foreign.Ptr(Ptr, nullPtr, castPtr)
import Foreign.Marshal.Alloc(alloca)
import Foreign.Marshal.Array(moveArray)
import Control.Exception(throwIO)
import qualified Data.Vector.Storable as V


{-# LINE 318 "./QuantLib/Method.chs" #-}


{-# LINE 319 "./QuantLib/Method.chs" #-}


{-# LINE 320 "./QuantLib/Method.chs" #-}


{-# LINE 321 "./QuantLib/Method.chs" #-}


{-# LINE 322 "./QuantLib/Method.chs" #-}


{-# LINE 323 "./QuantLib/Method.chs" #-}


{-# LINE 324 "./QuantLib/Method.chs" #-}


{-# LINE 325 "./QuantLib/Method.chs" #-}


{-# LINE 326 "./QuantLib/Method.chs" #-}


{-# LINE 327 "./QuantLib/Method.chs" #-}


{-# LINE 328 "./QuantLib/Method.chs" #-}


{-# LINE 329 "./QuantLib/Method.chs" #-}


{-# LINE 330 "./QuantLib/Method.chs" #-}


{-# LINE 331 "./QuantLib/Method.chs" #-}


{-# LINE 332 "./QuantLib/Method.chs" #-}


{-# LINE 333 "./QuantLib/Method.chs" #-}


{-# LINE 334 "./QuantLib/Method.chs" #-}


{-# LINE 335 "./QuantLib/Method.chs" #-}


{-# LINE 336 "./QuantLib/Method.chs" #-}


-- A step condition may return its borrowed input, which shares the output buffer.
pokeFdmResult :: Int -> Ptr CDouble -> RealVector -> IO ()
pokeFdmResult :: Int -> Ptr CDouble -> RealVector -> IO ()
pokeFdmResult Int
expected Ptr CDouble
out RealVector
result
  | RealVector -> Int
forall a. Storable a => Vector a -> Int
V.length RealVector
result Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
expected = Error -> IO ()
forall e a. (HasCallStack, Exception e) => e -> IO a
throwIO (Int -> Int -> Error
CallbackResultLength Int
expected (RealVector -> Int
forall a. Storable a => Vector a -> Int
V.length RealVector
result))
  | Bool
otherwise = RealVector -> (Ptr Double -> IO ()) -> IO ()
forall a b. Storable a => Vector a -> (Ptr a -> IO b) -> IO b
V.unsafeWith RealVector
result ((Ptr Double -> IO ()) -> IO ()) -> (Ptr Double -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Double
p -> Ptr CDouble -> Ptr CDouble -> Int -> IO ()
forall a. Storable a => Ptr a -> Ptr a -> Int -> IO ()
moveArray Ptr CDouble
out (Ptr Double -> Ptr CDouble
forall a b. Ptr a -> Ptr b
castPtr Ptr Double
p) Int
expected

withFdmResult :: (Callback.CallbackArgs -> RealVector -> RealVector) -> (Ptr () -> IO b) -> IO b
withFdmResult :: forall b.
(CallbackArgs -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
withFdmResult CallbackArgs -> RealVector -> RealVector
f Ptr () -> IO b
use = (CallbackArgs -> IO ()) -> (Callback -> IO b) -> IO b
forall a. (CallbackArgs -> IO ()) -> (Callback -> IO a) -> IO a
Callback.withCallback CallbackArgs -> IO ()
call (Callback -> (Ptr () -> IO b) -> IO b
forall b. Callback -> (Ptr () -> IO b) -> IO b
`withCallbackPtr` Ptr () -> IO b
use)
  where
    call :: CallbackArgs -> IO ()
call CallbackArgs
args = do
      x <- Ptr CDouble -> CUInt -> IO RealVector
borrowRealVector (CallbackArgs -> Ptr CDouble
Callback.callbackInput CallbackArgs
args) (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CallbackArgs -> Int
Callback.callbackSize CallbackArgs
args))
      pokeFdmResult (Callback.callbackSize args) (Callback.callbackOutput args) (f args x)

withFdmApply :: ((Double, Double) -> RealVector -> RealVector) -> (Ptr () -> IO b) -> IO b
withFdmApply :: forall b.
((Double, Double) -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
withFdmApply (Double, Double) -> RealVector -> RealVector
f = (CallbackArgs -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
forall b.
(CallbackArgs -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
withFdmResult ((CallbackArgs -> RealVector -> RealVector)
 -> (Ptr () -> IO b) -> IO b)
-> (CallbackArgs -> RealVector -> RealVector)
-> (Ptr () -> IO b)
-> IO b
forall a b. (a -> b) -> a -> b
$ \CallbackArgs
args -> (Double, Double) -> RealVector -> RealVector
f (CallbackArgs -> Double
Callback.callbackTime1 CallbackArgs
args, CallbackArgs -> Double
Callback.callbackTime2 CallbackArgs
args)

withFdmApplyDirection :: (Int -> (Double, Double) -> RealVector -> RealVector) -> (Ptr () -> IO b) -> IO b
withFdmApplyDirection :: forall b.
(Int -> (Double, Double) -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
withFdmApplyDirection Int -> (Double, Double) -> RealVector -> RealVector
f = (CallbackArgs -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
forall b.
(CallbackArgs -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
withFdmResult ((CallbackArgs -> RealVector -> RealVector)
 -> (Ptr () -> IO b) -> IO b)
-> (CallbackArgs -> RealVector -> RealVector)
-> (Ptr () -> IO b)
-> IO b
forall a b. (a -> b) -> a -> b
$ \CallbackArgs
args ->
  Int -> (Double, Double) -> RealVector -> RealVector
f (CallbackArgs -> Int
Callback.callbackDirection CallbackArgs
args) (CallbackArgs -> Double
Callback.callbackTime1 CallbackArgs
args, CallbackArgs -> Double
Callback.callbackTime2 CallbackArgs
args)

withFdmSolveSplitting :: (Int -> Double -> (Double, Double) -> RealVector -> RealVector) -> (Ptr () -> IO b) -> IO b
withFdmSolveSplitting :: forall b.
(Int -> Double -> (Double, Double) -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
withFdmSolveSplitting Int -> Double -> (Double, Double) -> RealVector -> RealVector
f = (CallbackArgs -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
forall b.
(CallbackArgs -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
withFdmResult ((CallbackArgs -> RealVector -> RealVector)
 -> (Ptr () -> IO b) -> IO b)
-> (CallbackArgs -> RealVector -> RealVector)
-> (Ptr () -> IO b)
-> IO b
forall a b. (a -> b) -> a -> b
$ \CallbackArgs
args ->
  Int -> Double -> (Double, Double) -> RealVector -> RealVector
f (CallbackArgs -> Int
Callback.callbackDirection CallbackArgs
args) (CallbackArgs -> Double
Callback.callbackScalar CallbackArgs
args) (CallbackArgs -> Double
Callback.callbackTime1 CallbackArgs
args, CallbackArgs -> Double
Callback.callbackTime2 CallbackArgs
args)

withMaybeFdmStepCondition :: Maybe (Double -> RealVector -> RealVector) -> (Ptr () -> IO b) -> IO b
withMaybeFdmStepCondition :: forall b.
Maybe (Double -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
withMaybeFdmStepCondition Maybe (Double -> RealVector -> RealVector)
Nothing Ptr () -> IO b
use = Ptr () -> IO b
use Ptr ()
forall a. Ptr a
nullPtr
withMaybeFdmStepCondition (Just Double -> RealVector -> RealVector
f) Ptr () -> IO b
use = (CallbackArgs -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
forall b.
(CallbackArgs -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
withFdmResult (Double -> RealVector -> RealVector
f (Double -> RealVector -> RealVector)
-> (CallbackArgs -> Double)
-> CallbackArgs
-> RealVector
-> RealVector
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CallbackArgs -> Double
Callback.callbackTime1) Ptr () -> IO b
use

-- |build a multi-asset path generator driven by a pseudo-random number generator (Mersenne Twister, Poisson, or Ziggurat, chosen by the RNG trait) over the given process and time grid.
pathGenerator :: (RngTrait) -> (GenStochasticProcess p) -> (TimeGrid) -> (Word) -- ^seed
 -> (Word) -- ^dimension
 -> (Bool) -- ^brownian bridge
 -> IO ((PathGenerator))
pathGenerator :: forall p.
RngTrait
-> GenStochasticProcess p
-> TimeGrid
-> Word
-> Word
-> Bool
-> IO PathGenerator
pathGenerator RngTrait
a1 GenStochasticProcess p
a2 TimeGrid
a3 Word
a4 Word
a5 Bool
a6 =
  let {a1' :: CInt
a1' = RngTrait -> CInt
forall a b. (Enum a, Integral b) => a -> b
fromEnumC RngTrait
a1} in 
  GenStochasticProcess p
-> (Ptr CStochasticProcess' -> IO PathGenerator)
-> IO PathGenerator
forall p b.
GenStochasticProcess p -> (Ptr CStochasticProcess' -> IO b) -> IO b
withStochasticProcess GenStochasticProcess p
a2 ((Ptr CStochasticProcess' -> IO PathGenerator) -> IO PathGenerator)
-> (Ptr CStochasticProcess' -> IO PathGenerator)
-> IO PathGenerator
forall a b. (a -> b) -> a -> b
$ \Ptr CStochasticProcess'
a2' -> 
  TimeGrid -> (Ptr CTimeGrid -> IO PathGenerator) -> IO PathGenerator
forall b. TimeGrid -> (Ptr CTimeGrid -> IO b) -> IO b
withTimeGrid TimeGrid
a3 ((Ptr CTimeGrid -> IO PathGenerator) -> IO PathGenerator)
-> (Ptr CTimeGrid -> IO PathGenerator) -> IO PathGenerator
forall a b. (a -> b) -> a -> b
$ \Ptr CTimeGrid
a3' -> 
  let {a4' :: CUInt
a4' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a4} in 
  let {a5' :: CUInt
a5' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a5} in 
  let {a6' :: CInt
a6' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a6} in 
  (Ptr (Ptr ()) -> IO PathGenerator) -> IO PathGenerator
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO PathGenerator) -> IO PathGenerator)
-> (Ptr (Ptr ()) -> IO PathGenerator) -> IO PathGenerator
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a7' -> 
  CInt
-> Ptr CStochasticProcess'
-> Ptr CTimeGrid
-> CUInt
-> CUInt
-> CInt
-> Ptr (Ptr ())
-> IO (Ptr CPathGenerator)
pathGenerator'_ CInt
a1' Ptr CStochasticProcess'
a2' Ptr CTimeGrid
a3' CUInt
a4' CUInt
a5' CInt
a6' Ptr (Ptr ())
a7' IO (Ptr CPathGenerator)
-> (Ptr CPathGenerator -> IO PathGenerator) -> IO PathGenerator
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CPathGenerator
res ->
  Ptr CPathGenerator -> IO PathGenerator
peekPathGenerator Ptr CPathGenerator
res IO PathGenerator
-> (PathGenerator -> IO PathGenerator) -> IO PathGenerator
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \PathGenerator
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a7'IO () -> IO PathGenerator -> IO PathGenerator
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  PathGenerator -> IO PathGenerator
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (PathGenerator
res')

{-# LINE 371 "./QuantLib/Method.chs" #-}


-- |build a multi-asset path generator driven by a low-discrepancy (Sobol) sequence, using the given direction integers, over the given process and time grid.
sobolPathGenerator :: (SobolDirectionIntegers) -> (GenStochasticProcess p) -> (TimeGrid) -> (Word) -- ^seed
 -> (Word) -- ^dimension
 -> (Bool) -- ^brownian bridge
 -> IO ((PathGenerator))
sobolPathGenerator a1 a2 a3 a4 a5 a6 =
  let {a1' = fromEnumC a1} in 
  withStochasticProcess a2 $ \a2' -> 
  withTimeGrid a3 $ \a3' -> 
  let {a4' = fromIntegral a4} in 
  let {a5' = fromIntegral a5} in 
  let {a6' = C2HSImp.fromBool a6} in 
  preErrorCheck $ \a7' -> 
  sobolPathGenerator'_ a1' a2' a3' a4' a5' a6' a7' >>= \res ->
  peekPathGenerator res >>= \res' ->
  errorCheck  a7'>>
  return (res')

{-# LINE 378 "./QuantLib/Method.chs" #-}


-- |The gaussian sequence generator a 'pathGenerator' drives its evolution with, exposed on its own
-- so a Haskell-defined SDE can be simulated with no FFI call in the inner loop -- the same
-- decomposition 'lsmRegress' applies to @LongstaffSchwartzPathPricer@, one level lower down.
--
-- QuantLib's @StochasticProcess@ has no Haskell-subclassable hook here by design: @MultiPathGenerator@
-- (which 'pathGenerator' wraps) calls @process->evolve@ once per timestep /per path/, so binding
-- that virtual as a callback would put an FFI crossing in the hottest loop there is. Drawing the
-- normals with 'nextSequence' and writing @evolve@ in Haskell instead costs one crossing per
-- /path/, and the result composes with 'lsmRegress' into a complete custom-SDE American Monte
-- Carlo. The trade-off is that the result is a set of paths, not a @StochasticProcess@ object, so
-- it cannot be fed to 'fdmSimpleProcess1dMesher' or to a pricing engine -- but no stock QuantLib
-- engine would have accepted a custom process anyway: their constructors are typed on concrete
-- process classes (@GeneralizedBlackScholesProcess@ and friends), not on the abstract base.
--
-- @dimension@ is the length of each drawn sequence: (normals drawn per step) * timesteps. For
-- 'pathGenerator' parity the per-step count is the process's @factors@; a Haskell-evolved model
-- may draw more normals per step than it has Brownian drivers. The construction mirrors
-- 'pathGenerator''s exactly (same trait, same seed, same direction integers), so a
-- Haskell-evolved path can be compared draw for draw against a 'pathGenerator' one on a bound
-- process.
gaussianRsg :: (RngTrait) -> (Word) -- ^dimension
 -> (Word) -- ^seed
 -> IO ((GaussianRsg))
gaussianRsg :: RngTrait -> Word -> Word -> IO GaussianRsg
gaussianRsg RngTrait
a1 Word
a2 Word
a3 =
  let {a1' :: CInt
a1' = RngTrait -> CInt
forall a b. (Enum a, Integral b) => a -> b
fromEnumC RngTrait
a1} in 
  let {a2' :: CUInt
a2' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a2} in 
  let {a3' :: CUInt
a3' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a3} in 
  (Ptr (Ptr ()) -> IO GaussianRsg) -> IO GaussianRsg
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO GaussianRsg) -> IO GaussianRsg)
-> (Ptr (Ptr ()) -> IO GaussianRsg) -> IO GaussianRsg
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a4' -> 
  CInt -> CUInt -> CUInt -> Ptr (Ptr ()) -> IO (Ptr CGaussianRsg)
gaussianRsg'_ CInt
a1' CUInt
a2' CUInt
a3' Ptr (Ptr ())
a4' IO (Ptr CGaussianRsg)
-> (Ptr CGaussianRsg -> IO GaussianRsg) -> IO GaussianRsg
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CGaussianRsg
res ->
  Ptr CGaussianRsg -> IO GaussianRsg
peekGaussianRsg Ptr CGaussianRsg
res IO GaussianRsg -> (GaussianRsg -> IO GaussianRsg) -> IO GaussianRsg
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \GaussianRsg
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a4'IO () -> IO GaussianRsg -> IO GaussianRsg
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  GaussianRsg -> IO GaussianRsg
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (GaussianRsg
res')

{-# LINE 403 "./QuantLib/Method.chs" #-}


-- |'gaussianRsg' driven by a low-discrepancy (Sobol) sequence with the given direction integers --
-- the 'sobolPathGenerator' counterpart. The maximum @dimension@ depends on the direction-integer
-- set and on QuantLib's build-time @PPMT_MAX_DIM@; a larger one raises an exception.
sobolGaussianRsg :: (SobolDirectionIntegers) -> (Word) -- ^dimension
 -> (Word) -- ^seed
 -> IO ((GaussianRsg))
sobolGaussianRsg a1 a2 a3 =
  let {a1' = fromEnumC a1} in 
  let {a2' = fromIntegral a2} in 
  let {a3' = fromIntegral a3} in 
  preErrorCheck $ \a4' -> 
  sobolGaussianRsg'_ a1' a2' a3' a4' >>= \res ->
  peekGaussianRsg res >>= \res' ->
  errorCheck  a4'>>
  return (res')

{-# LINE 411 "./QuantLib/Method.chs" #-}


-- |the length of each sequence the generator draws.
rsgDimension :: (GaussianRsg) -> (Word)
rsgDimension a1 =
  C2HSImp.unsafePerformIO $
  withGaussianRsg a1 $ \a1' -> 
  rsgDimension'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 414 "./QuantLib/Method.chs" #-}


-- |draw the next sequence of standard normal variates, with its sample weight (1 for every trait
-- bound here, carried through for symmetry with 'weight').
nextSequence :: (GaussianRsg) -> IO ((RealVector), (Double))
nextSequence a1 =
  withGaussianRsg a1 $ \a1' -> 
  preDoubleArray $ \(a2'1, a2'2) -> 
  alloca $ \a3' -> 
  preErrorCheck $ \a4' -> 
  nextSequence'_ a1' a2'1  a2'2 a3' a4' >>
  peekRealVector  a2'1  a2'2>>= \a2'' -> 
  peekDouble  a3'>>= \a3'' -> 
  errorCheck  a4'>>
  return (a2'', a3'')

{-# LINE 421 "./QuantLib/Method.chs" #-}


-- |re-read the sequence 'nextSequence' last drew, without advancing the generator.
lastSequence :: (GaussianRsg) -> IO ((RealVector), (Double))
lastSequence a1 =
  withGaussianRsg a1 $ \a1' -> 
  preDoubleArray $ \(a2'1, a2'2) -> 
  alloca $ \a3' -> 
  preErrorCheck $ \a4' -> 
  lastSequence'_ a1' a2'1  a2'2 a3' a4' >>
  peekRealVector  a2'1  a2'2>>= \a2'' -> 
  peekDouble  a3'>>= \a3'' -> 
  errorCheck  a4'>>
  return (a2'', a3'')

{-# LINE 427 "./QuantLib/Method.chs" #-}


-- |The random sequence consumed by the last 'next', with its sample weight, without advancing
-- the generator. Refuses before the first draw. These are variates before process correlation;
-- 'antithetic' uses their negatives and leaves this original sequence unchanged.
pathGeneratorSequence :: (PathGenerator) -- ^generator
 -> IO ((RealVector), (Double))
pathGeneratorSequence a1 =
  withPathGenerator a1 $ \a1' -> 
  preDoubleArray $ \(a2'1, a2'2) -> 
  alloca $ \a3' -> 
  preErrorCheck $ \a4' -> 
  pathGeneratorSequence'_ a1' a2'1  a2'2 a3' a4' >>
  peekRealVector  a2'1  a2'2>>= \a2'' -> 
  peekDouble  a3'>>= \a3'' -> 
  errorCheck  a4'>>
  return (a2'', a3'')

{-# LINE 435 "./QuantLib/Method.chs" #-}


-- |draw the next weighted sample path from the generator.
next :: (PathGenerator) -> IO ((SamplePath))
next a1 =
  withPathGenerator a1 $ \a1' -> 
  preErrorCheck $ \a2' -> 
  next'_ a1' a2' >>= \res ->
  peekSamplePath res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 438 "./QuantLib/Method.chs" #-}


-- |draw the antithetic (sign-flipped) counterpart of the last drawn sample path.
antithetic :: (PathGenerator) -> IO ((SamplePath))
antithetic a1 =
  withPathGenerator a1 $ \a1' -> 
  preErrorCheck $ \a2' -> 
  antithetic'_ a1' a2' >>= \res ->
  peekSamplePath res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 441 "./QuantLib/Method.chs" #-}


-- |the weight associated with a sample path.
weight :: (SamplePath) -> (Double)
weight a1 =
  C2HSImp.unsafePerformIO $
  withSamplePath a1 $ \a1' -> 
  weight'_ a1' >>= \res ->
  let {res' = realToFrac res} in
  return (res')

{-# LINE 444 "./QuantLib/Method.chs" #-}


-- |the number of correlated asset paths in a sample.
assetNumber :: (SamplePath) -> (Word)
assetNumber a1 =
  C2HSImp.unsafePerformIO $
  withSamplePath a1 $ \a1' -> 
  assetNumber'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 447 "./QuantLib/Method.chs" #-}


-- |the number of time steps in each asset path of a sample.
pathSize :: (SamplePath) -> (Word)
pathSize a1 =
  C2HSImp.unsafePerformIO $
  withSamplePath a1 $ \a1' -> 
  pathSize'_ a1' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')

{-# LINE 450 "./QuantLib/Method.chs" #-}


-- |the value of one asset's path at a given time step.
assetAt :: (SamplePath) -> (Word) -- ^asset
 -> (Word) -- ^point
 -> IO ((Double))
assetAt a1 a2 a3 =
  withSamplePath a1 $ \a1' -> 
  let {a2' = fromIntegral a2} in 
  let {a3' = fromIntegral a3} in 
  preErrorCheck $ \a4' -> 
  assetAt'_ a1' a2' a3' a4' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a4'>>
  return (res')

{-# LINE 455 "./QuantLib/Method.chs" #-}


-- |The full simulated path (values at every time step) of a single asset.
asset :: (SamplePath) -> (Word) -> IO ((RealVector))
asset a1 a2 =
  withSamplePath a1 $ \a1' -> 
  let {a2' = fromIntegral a2} in 
  preDoubleArray $ \(a3'1, a3'2) -> 
  preErrorCheck $ \a4' -> 
  asset'_ a1' a2' a3'1  a3'2 a4' >>
  peekRealVector  a3'1  a3'2>>= \a3'' -> 
  errorCheck  a4'>>
  return (a3'')

{-# LINE 458 "./QuantLib/Method.chs" #-}


-- |one step of Longstaff-Schwartz early-exercise regression: fit a polynomial basis of the given
-- order/type against the (in-the-money) fit states and their continuation targets, then evaluate the
-- fitted continuation value at each of the given eval states. This is the same per-exercise-date
-- regression @LongstaffSchwartzPathPricer@ performs internally against a bound @Payoff@, exposed so it
-- can be driven from a Haskell-defined payoff instead: call it once per exercise date, walking dates
-- strictly backward, batched across all paths rather than per path. See this module's header for the
-- full backward-induction pattern.
lsmRegress :: (PolynomialType) -> (Word) -- ^basis order
 -> (RealVector) -- ^fit states (in-the-money paths only)
 -> (RealVector) -- ^fit targets (continuation value at these states)
 -> (RealVector) -- ^eval states (all paths' state at this date)
 -> IO ((RealVector))
lsmRegress :: PolynomialType
-> Word -> RealVector -> RealVector -> RealVector -> IO RealVector
lsmRegress PolynomialType
a1 Word
a2 RealVector
a3 RealVector
a4 RealVector
a5 =
  let {a1' :: CInt
a1' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (PolynomialType -> Int) -> PolynomialType -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PolynomialType -> Int
forall a. Enum a => a -> Int
fromEnum) PolynomialType
a1} in 
  let {a2' :: CUInt
a2' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a2} in 
  RealVector
-> ((CUInt, Ptr CDouble) -> IO RealVector) -> IO RealVector
forall b. RealVector -> ((CUInt, Ptr CDouble) -> IO b) -> IO b
withRealVector RealVector
a3 (((CUInt, Ptr CDouble) -> IO RealVector) -> IO RealVector)
-> ((CUInt, Ptr CDouble) -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \(CUInt
a3'1, Ptr CDouble
a3'2) -> 
  RealVector
-> ((CUInt, Ptr CDouble) -> IO RealVector) -> IO RealVector
forall b. RealVector -> ((CUInt, Ptr CDouble) -> IO b) -> IO b
withRealVector RealVector
a4 (((CUInt, Ptr CDouble) -> IO RealVector) -> IO RealVector)
-> ((CUInt, Ptr CDouble) -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \(CUInt
a4'1, Ptr CDouble
a4'2) -> 
  RealVector
-> ((CUInt, Ptr CDouble) -> IO RealVector) -> IO RealVector
forall b. RealVector -> ((CUInt, Ptr CDouble) -> IO b) -> IO b
withRealVector RealVector
a5 (((CUInt, Ptr CDouble) -> IO RealVector) -> IO RealVector)
-> ((CUInt, Ptr CDouble) -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \(CUInt
a5'1, Ptr CDouble
a5'2) -> 
  ((Ptr CUInt, Ptr (Ptr CDouble)) -> IO RealVector) -> IO RealVector
forall b. ((Ptr CUInt, Ptr (Ptr CDouble)) -> IO b) -> IO b
preDoubleArray (((Ptr CUInt, Ptr (Ptr CDouble)) -> IO RealVector)
 -> IO RealVector)
-> ((Ptr CUInt, Ptr (Ptr CDouble)) -> IO RealVector)
-> IO RealVector
forall a b. (a -> b) -> a -> b
$ \(Ptr CUInt
a6'1, Ptr (Ptr CDouble)
a6'2) -> 
  (Ptr (Ptr ()) -> IO RealVector) -> IO RealVector
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO RealVector) -> IO RealVector)
-> (Ptr (Ptr ()) -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a7' -> 
  CInt
-> CUInt
-> CUInt
-> Ptr CDouble
-> CUInt
-> Ptr CDouble
-> CUInt
-> Ptr CDouble
-> Ptr CUInt
-> Ptr (Ptr CDouble)
-> Ptr (Ptr ())
-> IO ()
lsmRegress'_ CInt
a1' CUInt
a2' CUInt
a3'1  Ptr CDouble
a3'2 CUInt
a4'1  Ptr CDouble
a4'2 CUInt
a5'1  Ptr CDouble
a5'2 Ptr CUInt
a6'1  Ptr (Ptr CDouble)
a6'2 Ptr (Ptr ())
a7' IO () -> IO RealVector -> IO RealVector
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  Ptr CUInt -> Ptr (Ptr CDouble) -> IO RealVector
peekRealVector  Ptr CUInt
a6'1  Ptr (Ptr CDouble)
a6'2IO RealVector -> (RealVector -> IO RealVector) -> IO RealVector
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \RealVector
a6'' -> 
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a7'IO () -> IO RealVector -> IO RealVector
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  RealVector -> IO RealVector
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (RealVector
a6'')

{-# LINE 472 "./QuantLib/Method.chs" #-}


-- |number of basis terms 'lsmRegressMulti' fits for a given number of underlyings and order --
-- @C(dim+order, order)@, the binomial coefficient @LsmBasisSystem::multiPathBasisSystem@ actually
-- returns (not @order+1@, which only coincides at @dim=1@ -- 'lsmRegress' uses that special case
-- directly rather than calling this). Use it to size the \"enough in-the-money calibration paths to
-- fit\" guard before calling 'lsmRegressMulti': the underlying least-squares solve requires at least
-- this many fit rows, and undershooting it throws rather than returning a degenerate fit.
lsmBasisSize :: Word -> Word -> Word
lsmBasisSize dim order = fromInteger $ binomial (toInteger dim + toInteger order) (toInteger order)
  where binomial n k = product [n - k + 1 .. n] `div` product [1 .. k]

-- |multi-asset counterpart of 'lsmRegress', for a Haskell-defined basket (several correlated
-- underlyings) early-exercise payoff -- 'lsmRegress' itself only regresses against one state
-- variable. Fit\/eval states are contiguous row-major 'RealMatrix' values: one row per path, one column per underlying, and the
-- two matrices' column counts must agree. Regresses against
-- @LsmBasisSystem::multiPathBasisSystem@'s combinatorial basis; see 'lsmBasisSize' for its size and
-- this module's header for the surrounding backward-induction pattern (identical to the scalar case,
-- just with 'Matrix'-shaped states).
lsmRegressMulti :: PolynomialType -> Word -> RealMatrix -- ^fit states (in-the-money paths only)
  -> RealVector -- ^fit targets (continuation value at these states)
  -> RealMatrix -- ^eval states (all paths' state at this date)
  -> IO RealVector -- ^continuation value estimate per eval row
lsmRegressMulti :: PolynomialType
-> Word -> RealMatrix -> RealVector -> RealMatrix -> IO RealVector
lsmRegressMulti PolynomialType
p Word
order (RealMatrix Word
fr Word
fc RealVector
fd) RealVector
t (RealMatrix Word
er Word
ec RealVector
ed) = PolynomialType
-> Word
-> Word
-> Word
-> RealVector
-> RealVector
-> Word
-> Word
-> RealVector
-> IO RealVector
qlLsmRegressMulti PolynomialType
p Word
order Word
fr Word
fc RealVector
fd RealVector
t Word
er Word
ec RealVector
ed
qlLsmRegressMulti :: (PolynomialType) -> (Word) -- ^basis order
 -> (Word) -- ^fit rows
 -> (Word) -- ^fit columns (underlyings)
 -> (RealVector) -- ^fit states, row-major
 -> (RealVector) -- ^fit targets
 -> (Word) -- ^eval rows
 -> (Word) -- ^eval columns (underlyings)
 -> (RealVector) -- ^eval states, row-major
 -> IO ((RealVector))
qlLsmRegressMulti :: PolynomialType
-> Word
-> Word
-> Word
-> RealVector
-> RealVector
-> Word
-> Word
-> RealVector
-> IO RealVector
qlLsmRegressMulti PolynomialType
a1 Word
a2 Word
a3 Word
a4 RealVector
a5 RealVector
a6 Word
a7 Word
a8 RealVector
a9 =
  let {a1' :: CInt
a1' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (PolynomialType -> Int) -> PolynomialType -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PolynomialType -> Int
forall a. Enum a => a -> Int
fromEnum) PolynomialType
a1} in 
  let {a2' :: CUInt
a2' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a2} in 
  let {a3' :: CUInt
a3' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a3} in 
  let {a4' :: CUInt
a4' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a4} in 
  RealVector -> (Ptr CDouble -> IO RealVector) -> IO RealVector
forall b. RealVector -> (Ptr CDouble -> IO b) -> IO b
withRealVectorRaw RealVector
a5 ((Ptr CDouble -> IO RealVector) -> IO RealVector)
-> (Ptr CDouble -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr CDouble
a5' -> 
  RealVector
-> ((CUInt, Ptr CDouble) -> IO RealVector) -> IO RealVector
forall b. RealVector -> ((CUInt, Ptr CDouble) -> IO b) -> IO b
withRealVector RealVector
a6 (((CUInt, Ptr CDouble) -> IO RealVector) -> IO RealVector)
-> ((CUInt, Ptr CDouble) -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \(CUInt
a6'1, Ptr CDouble
a6'2) -> 
  let {a7' :: CUInt
a7' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a7} in 
  let {a8' :: CUInt
a8' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral a8} in 
  RealVector -> (Ptr CDouble -> IO RealVector) -> IO RealVector
forall b. RealVector -> (Ptr CDouble -> IO b) -> IO b
withRealVectorRaw RealVector
a9 ((Ptr CDouble -> IO RealVector) -> IO RealVector)
-> (Ptr CDouble -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr CDouble
a9' -> 
  ((Ptr CUInt, Ptr (Ptr CDouble)) -> IO RealVector) -> IO RealVector
forall b. ((Ptr CUInt, Ptr (Ptr CDouble)) -> IO b) -> IO b
preDoubleArray (((Ptr CUInt, Ptr (Ptr CDouble)) -> IO RealVector)
 -> IO RealVector)
-> ((Ptr CUInt, Ptr (Ptr CDouble)) -> IO RealVector)
-> IO RealVector
forall a b. (a -> b) -> a -> b
$ \(Ptr CUInt
a10'1, Ptr (Ptr CDouble)
a10'2) -> 
  (Ptr (Ptr ()) -> IO RealVector) -> IO RealVector
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO RealVector) -> IO RealVector)
-> (Ptr (Ptr ()) -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a11' -> 
  CInt
-> CUInt
-> CUInt
-> CUInt
-> Ptr CDouble
-> CUInt
-> Ptr CDouble
-> CUInt
-> CUInt
-> Ptr CDouble
-> Ptr CUInt
-> Ptr (Ptr CDouble)
-> Ptr (Ptr ())
-> IO ()
qlLsmRegressMulti'_ CInt
a1' CUInt
a2' CUInt
a3' CUInt
a4' Ptr CDouble
a5' CUInt
a6'1  Ptr CDouble
a6'2 CUInt
a7' CUInt
a8' Ptr CDouble
a9' Ptr CUInt
a10'1  Ptr (Ptr CDouble)
a10'2 Ptr (Ptr ())
a11' IO () -> IO RealVector -> IO RealVector
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  Ptr CUInt -> Ptr (Ptr CDouble) -> IO RealVector
peekRealVector  Ptr CUInt
a10'1  Ptr (Ptr CDouble)
a10'2IO RealVector -> (RealVector -> IO RealVector) -> IO RealVector
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \RealVector
a10'' -> 
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a11'IO () -> IO RealVector -> IO RealVector
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  RealVector -> IO RealVector
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (RealVector
a10'')

{-# LINE 505 "./QuantLib/Method.chs" #-}


-- |basis coefficients of one Longstaff-Schwartz fit, the fitting half of 'lsmRegress' (one state
-- column) or 'lsmRegressMulti' (several): fit states are a row-major 'RealMatrix', one row per
-- path. There are 'lsmBasisSize' of them, in QuantLib's basis order; evaluate them with 'lsmEvaluate'.
lsmFit :: PolynomialType -> Word -> RealMatrix -- ^fit states (in-the-money paths only)
  -> RealVector -- ^fit targets (continuation value at these states)
  -> IO RealVector -- ^basis coefficients
lsmFit p order (RealMatrix r c d) = qlLsmFit p order r c d
qlLsmFit :: (PolynomialType) -> (Word) -- ^basis order
 -> (Word) -- ^rows
 -> (Word) -- ^columns
 -> (RealVector) -- ^states, row-major
 -> (RealVector) -- ^targets
 -> IO ((RealVector))
qlLsmFit a1 a2 a3 a4 a5 a6 =
  let {a1' = (fromIntegral . fromEnum) a1} in 
  let {a2' = fromIntegral a2} in 
  let {a3' = fromIntegral a3} in 
  let {a4' = fromIntegral a4} in 
  withRealVectorRaw a5 $ \a5' -> 
  withRealVector a6 $ \(a6'1, a6'2) -> 
  preDoubleArray $ \(a7'1, a7'2) -> 
  preErrorCheck $ \a8' -> 
  qlLsmFit'_ a1' a2' a3' a4' a5' a6'1  a6'2 a7'1  a7'2 a8' >>
  peekRealVector  a7'1  a7'2>>= \a7'' -> 
  errorCheck  a8'>>
  return (a7'')

{-# LINE 520 "./QuantLib/Method.chs" #-}


-- |continuation value of 'lsmFit' coefficients at each row of the given states, which must have
-- the fit's column count; the polynomial type and order must be the fit's too. Throws unless there
-- are 'lsmBasisSize' coefficients for that column count.
lsmEvaluate :: PolynomialType -> Word -> RealVector -- ^coefficients
  -> RealMatrix -- ^eval states (one row per path)
  -> IO RealVector -- ^continuation value estimate per row
lsmEvaluate p order coefficients (RealMatrix r c d) = qlLsmEvaluate p order coefficients r c d
qlLsmEvaluate :: (PolynomialType) -> (Word) -- ^basis order
 -> (RealVector) -- ^coefficients
 -> (Word) -- ^rows
 -> (Word) -- ^columns
 -> (RealVector) -- ^states, row-major
 -> IO ((RealVector))
qlLsmEvaluate :: PolynomialType
-> Word
-> RealVector
-> Word
-> Word
-> RealVector
-> IO RealVector
qlLsmEvaluate PolynomialType
a1 Word
a2 RealVector
a3 Word
a4 Word
a5 RealVector
a6 =
  let {a1' :: CInt
a1' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (PolynomialType -> Int) -> PolynomialType -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PolynomialType -> Int
forall a. Enum a => a -> Int
fromEnum) PolynomialType
a1} in 
  let {a2' :: CUInt
a2' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a2} in 
  RealVector
-> ((CUInt, Ptr CDouble) -> IO RealVector) -> IO RealVector
forall b. RealVector -> ((CUInt, Ptr CDouble) -> IO b) -> IO b
withRealVector RealVector
a3 (((CUInt, Ptr CDouble) -> IO RealVector) -> IO RealVector)
-> ((CUInt, Ptr CDouble) -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \(CUInt
a3'1, Ptr CDouble
a3'2) -> 
  let {a4' :: CUInt
a4' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a4} in 
  let {a5' :: CUInt
a5' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a5} in 
  RealVector -> (Ptr CDouble -> IO RealVector) -> IO RealVector
forall b. RealVector -> (Ptr CDouble -> IO b) -> IO b
withRealVectorRaw RealVector
a6 ((Ptr CDouble -> IO RealVector) -> IO RealVector)
-> (Ptr CDouble -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr CDouble
a6' -> 
  ((Ptr CUInt, Ptr (Ptr CDouble)) -> IO RealVector) -> IO RealVector
forall b. ((Ptr CUInt, Ptr (Ptr CDouble)) -> IO b) -> IO b
preDoubleArray (((Ptr CUInt, Ptr (Ptr CDouble)) -> IO RealVector)
 -> IO RealVector)
-> ((Ptr CUInt, Ptr (Ptr CDouble)) -> IO RealVector)
-> IO RealVector
forall a b. (a -> b) -> a -> b
$ \(Ptr CUInt
a7'1, Ptr (Ptr CDouble)
a7'2) -> 
  (Ptr (Ptr ()) -> IO RealVector) -> IO RealVector
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO RealVector) -> IO RealVector)
-> (Ptr (Ptr ()) -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a8' -> 
  CInt
-> CUInt
-> CUInt
-> Ptr CDouble
-> CUInt
-> CUInt
-> Ptr CDouble
-> Ptr CUInt
-> Ptr (Ptr CDouble)
-> Ptr (Ptr ())
-> IO ()
qlLsmEvaluate'_ CInt
a1' CUInt
a2' CUInt
a3'1  Ptr CDouble
a3'2 CUInt
a4' CUInt
a5' Ptr CDouble
a6' Ptr CUInt
a7'1  Ptr (Ptr CDouble)
a7'2 Ptr (Ptr ())
a8' IO () -> IO RealVector -> IO RealVector
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  Ptr CUInt -> Ptr (Ptr CDouble) -> IO RealVector
peekRealVector  Ptr CUInt
a7'1  Ptr (Ptr CDouble)
a7'2IO RealVector -> (RealVector -> IO RealVector) -> IO RealVector
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \RealVector
a7'' -> 
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a8'IO () -> IO RealVector -> IO RealVector
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  RealVector -> IO RealVector
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (RealVector
a7'')

{-# LINE 535 "./QuantLib/Method.chs" #-}


-- |the build that 'lsmFit' and 'lsmEvaluate' belong to: the shim's basis revision, the QuantLib
-- version, the compiler and the architecture. Store it beside coefficients meant for later use.
lsmEvaluatorIdentity :: (String)
lsmEvaluatorIdentity =
  C2HSImp.unsafePerformIO $
  lsmEvaluatorIdentity'_ >>= \res ->
  peekCString res >>= \res' ->
  return (res')

{-# LINE 539 "./QuantLib/Method.chs" #-}


-- |Drive @FdmBackwardSolver::rollback@ with a Haskell-defined 'FdmLinearOpComposite' (the
-- @apply@\/@apply_direction@\/@solve_splitting@ callbacks) and an optional Haskell-defined step
-- condition (e.g. American\/Bermudan early exercise, or a barrier), instead of a bound mesher +
-- @FdmInnerValueCalculator@ as every concrete FDM pricing engine in "QuantLib.PricingEngine"
-- uses. This coarsened callback shape is modeled on QuantLib-SWIG's
-- @FdmLinearOpCompositeDelegate@\/
-- @FdmStepConditionDelegate@ (@SWIG\/fdm.i@): each callback crosses once per outer iteration over
-- the whole grid array, not once per grid node.
-- Internally each callback receives one native argument record, avoiding a wide mixed-argument
-- callback ABI at the Haskell boundary; this does not affect the public callback types.
--
-- The grid is a plain @[Double]@ in and out -- no mesher, no @FdmInnerValueCalculator@, no
-- @FdmSolverDesc@ is bound; callers manage their own grid geometry entirely in Haskell. Boundary
-- conditions are always the empty @FdmBoundaryConditionSet()@ (not bound). Every callback must
-- return an array of its input's length; any other length throws 'QuantLib.Context.CallbackResultLength'.
--
-- /Only DouglasScheme::step's three virtuals are implemented -- 'apply', 'apply_direction' and/
-- /'solve_splitting'; @apply_mixed@\/@preconditioner@ are unimplemented and @QL_FAIL@ at the C++/
-- /level if called./ This makes 'fdmRollback' safe to drive with 'QuantLib.Internal.Common.Douglas'
-- or 'QuantLib.Internal.Common.CrankNicolson' in one dimension (the two schemes
-- @DouglasScheme::step@ itself is used for) -- anything needing mixed derivatives across more than
-- one PDE direction (Craig-Sneyd, Hundsdorfer, or any genuinely multi-dimensional operator) will
-- throw partway through 'fdmRollback' rather than silently mispricing.
fdmRollback :: (Int) -- ^number of PDE directions\/dimensions the operator has (e.g. 1 for a 1D Black-Scholes-in-log-spot operator) -- /not/ the grid array length, which is the length of every @[Double]@ passed to\/returned from the callbacks below
 -> ((Double,Double) -> RealVector -> RealVector) -- ^@apply(r)@: whole-grid operator application at the current @(t1,t2)@ time pair (no direction argument -- QuantLib's own 'FdmLinearOp' base method)
 -> (Int -> (Double,Double) -> RealVector -> RealVector) -- ^@apply_direction(direction, r)@
 -> (Int -> Double -> (Double,Double) -> RealVector -> RealVector) -- ^@solve_splitting(direction, r, s)@ -- the implicit per-direction solve (e.g. a tridiagonal\/Thomas-algorithm solve for a 1D operator)
 -> (Maybe (Double -> RealVector -> RealVector)) -- ^optional step condition @applyTo(a, t)@, e.g. American\/Bermudan early exercise (@max(a_i, intrinsic_i)@ at every step) or a barrier knockout
 -> (RealVector) -- ^stopping times at which the step condition above is applied (ignored if there is no step condition); pass every rollback step's time to apply it at every step
 -> (FdmScheme) -- ^the finite-difference scheme (see the haddock above for which schemes are actually safe to use here)
 -> (RealVector) -- ^initial grid values, at time \'from\'
 -> (Double) -- ^from (start time of the rollback, e.g. option maturity)
 -> (Double) -- ^to (end time of the rollback, e.g. 0)
 -> (Int) -- ^steps
 -> (Int) -- ^dampingSteps
 -> IO ((RealVector))
fdmRollback :: Int
-> ((Double, Double) -> RealVector -> RealVector)
-> (Int -> (Double, Double) -> RealVector -> RealVector)
-> (Int -> Double -> (Double, Double) -> RealVector -> RealVector)
-> Maybe (Double -> RealVector -> RealVector)
-> RealVector
-> FdmScheme
-> RealVector
-> Double
-> Double
-> Int
-> Int
-> IO RealVector
fdmRollback Int
a1 (Double, Double) -> RealVector -> RealVector
a2 Int -> (Double, Double) -> RealVector -> RealVector
a3 Int -> Double -> (Double, Double) -> RealVector -> RealVector
a4 Maybe (Double -> RealVector -> RealVector)
a5 RealVector
a6 FdmScheme
a7 RealVector
a8 Double
a9 Double
a10 Int
a11 Int
a12 =
  let {a1' :: CUInt
a1' = Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a1} in 
  ((Double, Double) -> RealVector -> RealVector)
-> (Ptr () -> IO RealVector) -> IO RealVector
forall b.
((Double, Double) -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
withFdmApply (Double, Double) -> RealVector -> RealVector
a2 ((Ptr () -> IO RealVector) -> IO RealVector)
-> (Ptr () -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr ()
a2' -> 
  (Int -> (Double, Double) -> RealVector -> RealVector)
-> (Ptr () -> IO RealVector) -> IO RealVector
forall b.
(Int -> (Double, Double) -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
withFdmApplyDirection Int -> (Double, Double) -> RealVector -> RealVector
a3 ((Ptr () -> IO RealVector) -> IO RealVector)
-> (Ptr () -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr ()
a3' -> 
  (Int -> Double -> (Double, Double) -> RealVector -> RealVector)
-> (Ptr () -> IO RealVector) -> IO RealVector
forall b.
(Int -> Double -> (Double, Double) -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
withFdmSolveSplitting Int -> Double -> (Double, Double) -> RealVector -> RealVector
a4 ((Ptr () -> IO RealVector) -> IO RealVector)
-> (Ptr () -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr ()
a4' -> 
  Maybe (Double -> RealVector -> RealVector)
-> (Ptr () -> IO RealVector) -> IO RealVector
forall b.
Maybe (Double -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
withMaybeFdmStepCondition Maybe (Double -> RealVector -> RealVector)
a5 ((Ptr () -> IO RealVector) -> IO RealVector)
-> (Ptr () -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr ()
a5' -> 
  withRealVector a6 $ \(a6'1, a6'2) -> 
  withFdmSchemeDesc a7 $ \a7' -> 
  withRealVector a8 $ \(a8'1, a8'2) -> 
  let {a9' = realToFrac a9} in 
  let {a10' = realToFrac a10} in 
  let {a11' = fromIntegral a11} in 
  let {a12' = fromIntegral a12} in 
  preDoubleArray $ \(a13'1, a13'2) -> 
  preErrorCheck $ \a14' -> 
  fdmRollback'_ a1' a2' a3' a4' a5' a6'1  a6'2 a7' a8'1  a8'2 a9' a10' a11' a12' a13'1  a13'2 a14' >>
  peekRealVector  a13'1  a13'2>>= \a13'' -> 
  errorCheck  a14'>>
  return (a13'')

{-# LINE 577 "./QuantLib/Method.chs" #-}


-- |'Predefined1dMesher(points)' -- an 'Fdm1dMesher' over an explicit, caller-supplied set of grid points.
predefined1dMesher :: (RealVector) -- ^points
 -> IO ((Fdm1dMesher))
predefined1dMesher a1 =
  withRealVector a1 $ \(a1'1, a1'2) -> 
  preErrorCheck $ \a2' -> 
  predefined1dMesher'_ a1'1  a1'2 a2' >>= \res ->
  peekFdm1dMesher res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 581 "./QuantLib/Method.chs" #-}


-- |'Uniform1dMesher(start, end, size)' -- an evenly spaced 'Fdm1dMesher'.
uniform1dMesher :: (Double) -- ^start
 -> (Double) -- ^end
 -> (Word) -- ^size
 -> IO ((Fdm1dMesher))
uniform1dMesher a1 a2 a3 =
  let {a1' = realToFrac a1} in 
  let {a2' = realToFrac a2} in 
  let {a3' = fromIntegral a3} in 
  preErrorCheck $ \a4' -> 
  uniform1dMesher'_ a1' a2' a3' a4' >>= \res ->
  peekFdm1dMesher res >>= \res' ->
  errorCheck  a4'>>
  return (res')

{-# LINE 587 "./QuantLib/Method.chs" #-}


-- |'Concentrating1dMesher(start, end, size, cPoint, requireCPoint)' -- an 'Fdm1dMesher' with grid
-- points concentrated near @cPoint@ (e.g. a strike or barrier), or plain uniform spacing when
-- @cPoint@ is 'Nothing' for both coordinates.
concentrating1dMesher :: (Double) -- ^start
 -> (Double) -- ^end
 -> (Word) -- ^size
 -> (Maybe Double) -- ^concentration point location
 -> (Maybe Double) -- ^concentration point density
 -> (Bool) -- ^requireCPoint: force the concentration point itself onto the grid
 -> IO ((Fdm1dMesher))
concentrating1dMesher :: Double
-> Double
-> Word
-> Maybe Double
-> Maybe Double
-> Bool
-> IO Fdm1dMesher
concentrating1dMesher Double
a1 Double
a2 Word
a3 Maybe Double
a4 Maybe Double
a5 Bool
a6 =
  let {a1' :: CDouble
a1' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a1} in 
  let {a2' :: CDouble
a2' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a2} in 
  let {a3' :: CUInt
a3' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a3} in 
  let {a4' :: CDouble
a4' = Maybe Double -> CDouble
fromMaybeDouble Maybe Double
a4} in 
  let {a5' :: CDouble
a5' = Maybe Double -> CDouble
fromMaybeDouble Maybe Double
a5} in 
  let {a6' :: CInt
a6' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a6} in 
  (Ptr (Ptr ()) -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO Fdm1dMesher) -> IO Fdm1dMesher)
-> (Ptr (Ptr ()) -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a7' -> 
  CDouble
-> CDouble
-> CUInt
-> CDouble
-> CDouble
-> CInt
-> Ptr (Ptr ())
-> IO (Ptr CFdm1dMesher)
concentrating1dMesher'_ CDouble
a1' CDouble
a2' CUInt
a3' CDouble
a4' CDouble
a5' CInt
a6' Ptr (Ptr ())
a7' IO (Ptr CFdm1dMesher)
-> (Ptr CFdm1dMesher -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CFdm1dMesher
res ->
  Ptr CFdm1dMesher -> IO Fdm1dMesher
peekFdm1dMesher Ptr CFdm1dMesher
res IO Fdm1dMesher -> (Fdm1dMesher -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Fdm1dMesher
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a7'IO () -> IO Fdm1dMesher -> IO Fdm1dMesher
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  Fdm1dMesher -> IO Fdm1dMesher
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Fdm1dMesher
res')

{-# LINE 598 "./QuantLib/Method.chs" #-}


-- |Multi-concentration-point overload of 'concentrating1dMesher'
-- (@Concentrating1dMesher(start, end, size, cPoints, tol)@) -- a distinct upstream constructor,
-- not a defaulted-arg variant of the single-point one.
concentrating1dMesherMulti :: Double -> Double -> Word
  -> [(Double, Double, Bool)] -- ^concentration points: (location, density, requireCPoint)
  -> Double -- ^tol
  -> IO Fdm1dMesher
concentrating1dMesherMulti start end sz cPoints tol =
  let (locs, densities, reqs) = unzip3 cPoints
  in qlConcentrating1dMesherMulti start end sz (fromIntegral (length cPoints)) locs densities reqs tol
qlConcentrating1dMesherMulti :: (Double) -> (Double) -> (Word) -> (Word) -- ^number of concentration points
 -> ([Double]) -- ^locations
 -> ([Double]) -- ^densities
 -> ([Bool]) -- ^requireCPoint per point
 -> (Double) -- ^tol
 -> IO ((Fdm1dMesher))
qlConcentrating1dMesherMulti :: Double
-> Double
-> Word
-> Word
-> [Double]
-> [Double]
-> [Bool]
-> Double
-> IO Fdm1dMesher
qlConcentrating1dMesherMulti Double
a1 Double
a2 Word
a3 Word
a4 [Double]
a5 [Double]
a6 [Bool]
a7 Double
a8 =
  let {a1' :: CDouble
a1' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a1} in 
  let {a2' :: CDouble
a2' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a2} in 
  let {a3' :: CUInt
a3' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a3} in 
  let {a4' :: CUInt
a4' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a4} in 
  [Double] -> (Ptr CDouble -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall b. [Double] -> (Ptr CDouble -> IO b) -> IO b
withDoubleArrayRaw [Double]
a5 ((Ptr CDouble -> IO Fdm1dMesher) -> IO Fdm1dMesher)
-> (Ptr CDouble -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. (a -> b) -> a -> b
$ \Ptr CDouble
a5' -> 
  [Double] -> (Ptr CDouble -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall b. [Double] -> (Ptr CDouble -> IO b) -> IO b
withDoubleArrayRaw [Double]
a6 ((Ptr CDouble -> IO Fdm1dMesher) -> IO Fdm1dMesher)
-> (Ptr CDouble -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. (a -> b) -> a -> b
$ \Ptr CDouble
a6' -> 
  [Bool] -> (Ptr CInt -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall b. [Bool] -> (Ptr CInt -> IO b) -> IO b
withBoolArrayRaw [Bool]
a7 ((Ptr CInt -> IO Fdm1dMesher) -> IO Fdm1dMesher)
-> (Ptr CInt -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
a7' -> 
  let {a8' :: CDouble
a8' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a8} in 
  (Ptr (Ptr ()) -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO Fdm1dMesher) -> IO Fdm1dMesher)
-> (Ptr (Ptr ()) -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a9' -> 
  CDouble
-> CDouble
-> CUInt
-> CUInt
-> Ptr CDouble
-> Ptr CDouble
-> Ptr CInt
-> CDouble
-> Ptr (Ptr ())
-> IO (Ptr CFdm1dMesher)
qlConcentrating1dMesherMulti'_ CDouble
a1' CDouble
a2' CUInt
a3' CUInt
a4' Ptr CDouble
a5' Ptr CDouble
a6' Ptr CInt
a7' CDouble
a8' Ptr (Ptr ())
a9' IO (Ptr CFdm1dMesher)
-> (Ptr CFdm1dMesher -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CFdm1dMesher
res ->
  Ptr CFdm1dMesher -> IO Fdm1dMesher
peekFdm1dMesher Ptr CFdm1dMesher
res IO Fdm1dMesher -> (Fdm1dMesher -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Fdm1dMesher
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a9'IO () -> IO Fdm1dMesher -> IO Fdm1dMesher
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  Fdm1dMesher -> IO Fdm1dMesher
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Fdm1dMesher
res')

{-# LINE 616 "./QuantLib/Method.chs" #-}


-- |'Glued1dMesher(leftMesher, rightMesher)' -- splices two 'Fdm1dMesher's into one, deduplicating
-- their shared boundary point if @leftMesher@'s rightmost location and @rightMesher@'s leftmost
-- location coincide (within QuantLib's usual @close@ tolerance). Throws if @leftMesher@'s rightmost
-- point is strictly greater than @rightMesher@'s leftmost point -- the two ranges may touch or be
-- disjoint-but-ordered, never overlap or reverse.
gluedMesher :: (Fdm1dMesher) -- ^leftMesher
 -> (Fdm1dMesher) -- ^rightMesher
 -> IO ((Fdm1dMesher))
gluedMesher a1 a2 =
  withFdm1dMesher a1 $ \a1' -> 
  withFdm1dMesher a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  gluedMesher'_ a1' a2' a3' >>= \res ->
  peekFdm1dMesher res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 625 "./QuantLib/Method.chs" #-}


-- |'FdmBlackScholesMesher(size, process, maturity, strike, ...)' -- the standard log-spot mesher
-- for a Black-Scholes-family process, reusing the same 'GeneralizedBlackScholesProcess'\/
-- 'Dividend'\/'FdmQuantoHelper' plumbing "QuantLib.PricingEngine"'s @fd*@ engines already use.
fdmBlackScholesMesher :: (Word) -- ^size
 -> (GenGeneralizedBlackScholesProcess gbs) -> (Double) -- ^maturity
 -> (Double) -- ^strike
 -> (Maybe Double) -- ^xMinConstraint
 -> (Maybe Double) -- ^xMaxConstraint
 -> (Double) -- ^eps
 -> (Double) -- ^scaleFactor
 -> (Maybe Double) -- ^concentration point location
 -> (Maybe Double) -- ^concentration point density
 -> ([Dividend]) -> (Maybe FdmQuantoHelper) -> (Double) -- ^spotAdjustment
 -> IO ((Fdm1dMesher))
fdmBlackScholesMesher :: forall gbs.
Word
-> GenGeneralizedBlackScholesProcess gbs
-> Double
-> Double
-> Maybe Double
-> Maybe Double
-> Double
-> Double
-> Maybe Double
-> Maybe Double
-> [Dividend]
-> Maybe FdmQuantoHelper
-> Double
-> IO Fdm1dMesher
fdmBlackScholesMesher Word
a1 GenGeneralizedBlackScholesProcess gbs
a2 Double
a3 Double
a4 Maybe Double
a5 Maybe Double
a6 Double
a7 Double
a8 Maybe Double
a9 Maybe Double
a10 [Dividend]
a11 Maybe FdmQuantoHelper
a12 Double
a13 =
  let {a1' :: CUInt
a1' = Word -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
a1} in 
  GenGeneralizedBlackScholesProcess gbs
-> (Ptr CGeneralizedBlackScholesProcess' -> IO Fdm1dMesher)
-> IO Fdm1dMesher
forall gbs b.
GenGeneralizedBlackScholesProcess gbs
-> (Ptr CGeneralizedBlackScholesProcess' -> IO b) -> IO b
withGeneralizedBlackScholesProcess GenGeneralizedBlackScholesProcess gbs
a2 ((Ptr CGeneralizedBlackScholesProcess' -> IO Fdm1dMesher)
 -> IO Fdm1dMesher)
-> (Ptr CGeneralizedBlackScholesProcess' -> IO Fdm1dMesher)
-> IO Fdm1dMesher
forall a b. (a -> b) -> a -> b
$ \Ptr CGeneralizedBlackScholesProcess'
a2' -> 
  let {a3' :: CDouble
a3' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a3} in 
  let {a4' :: CDouble
a4' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a4} in 
  let {a5' :: CDouble
a5' = Maybe Double -> CDouble
fromMaybeDouble Maybe Double
a5} in 
  let {a6' :: CDouble
a6' = Maybe Double -> CDouble
fromMaybeDouble Maybe Double
a6} in 
  let {a7' :: CDouble
a7' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a7} in 
  let {a8' :: CDouble
a8' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a8} in 
  let {a9' :: CDouble
a9' = Maybe Double -> CDouble
fromMaybeDouble Maybe Double
a9} in 
  let {a10' :: CDouble
a10' = Maybe Double -> CDouble
fromMaybeDouble Maybe Double
a10} in 
  [Dividend]
-> ((CUInt, Ptr (Ptr CDividend)) -> IO Fdm1dMesher)
-> IO Fdm1dMesher
forall b.
[Dividend] -> ((CUInt, Ptr (Ptr CDividend)) -> IO b) -> IO b
withDividendArray [Dividend]
a11 (((CUInt, Ptr (Ptr CDividend)) -> IO Fdm1dMesher)
 -> IO Fdm1dMesher)
-> ((CUInt, Ptr (Ptr CDividend)) -> IO Fdm1dMesher)
-> IO Fdm1dMesher
forall a b. (a -> b) -> a -> b
$ \(CUInt
a11'1, Ptr (Ptr CDividend)
a11'2) -> 
  Maybe FdmQuantoHelper
-> (Ptr CFdmQuantoHelper -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall b.
Maybe FdmQuantoHelper -> (Ptr CFdmQuantoHelper -> IO b) -> IO b
withMaybeFdmQuantoHelper Maybe FdmQuantoHelper
a12 ((Ptr CFdmQuantoHelper -> IO Fdm1dMesher) -> IO Fdm1dMesher)
-> (Ptr CFdmQuantoHelper -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. (a -> b) -> a -> b
$ \Ptr CFdmQuantoHelper
a12' -> 
  let {a13' :: CDouble
a13' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a13} in 
  (Ptr (Ptr ()) -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO Fdm1dMesher) -> IO Fdm1dMesher)
-> (Ptr (Ptr ()) -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a14' -> 
  CUInt
-> Ptr CGeneralizedBlackScholesProcess'
-> CDouble
-> CDouble
-> CDouble
-> CDouble
-> CDouble
-> CDouble
-> CDouble
-> CDouble
-> CUInt
-> Ptr (Ptr CDividend)
-> Ptr CFdmQuantoHelper
-> CDouble
-> Ptr (Ptr ())
-> IO (Ptr CFdm1dMesher)
fdmBlackScholesMesher'_ CUInt
a1' Ptr CGeneralizedBlackScholesProcess'
a2' CDouble
a3' CDouble
a4' CDouble
a5' CDouble
a6' CDouble
a7' CDouble
a8' CDouble
a9' CDouble
a10' CUInt
a11'1  Ptr (Ptr CDividend)
a11'2 Ptr CFdmQuantoHelper
a12' CDouble
a13' Ptr (Ptr ())
a14' IO (Ptr CFdm1dMesher)
-> (Ptr CFdm1dMesher -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CFdm1dMesher
res ->
  Ptr CFdm1dMesher -> IO Fdm1dMesher
peekFdm1dMesher Ptr CFdm1dMesher
res IO Fdm1dMesher -> (Fdm1dMesher -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Fdm1dMesher
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a14'IO () -> IO Fdm1dMesher -> IO Fdm1dMesher
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  Fdm1dMesher -> IO Fdm1dMesher
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Fdm1dMesher
res')

{-# LINE 643 "./QuantLib/Method.chs" #-}


-- |'FdmCEV1dMesher(size, f0, alpha, beta, maturity, eps, scaleFactor, cPoint)' -- the standard
-- mesher for a CEV process.
fdmCev1dMesher :: (Word) -- ^size
 -> (Double) -- ^f0
 -> (Double) -- ^alpha
 -> (Double) -- ^beta
 -> (Double) -- ^maturity
 -> (Double) -- ^eps
 -> (Double) -- ^scaleFactor
 -> (Maybe Double) -- ^concentration point location
 -> (Maybe Double) -- ^concentration point density
 -> IO ((Fdm1dMesher))
fdmCev1dMesher a1 a2 a3 a4 a5 a6 a7 a8 a9 =
  let {a1' = fromIntegral a1} in 
  let {a2' = realToFrac a2} in 
  let {a3' = realToFrac a3} in 
  let {a4' = realToFrac a4} in 
  let {a5' = realToFrac a5} in 
  let {a6' = realToFrac a6} in 
  let {a7' = realToFrac a7} in 
  let {a8' = fromMaybeDouble a8} in 
  let {a9' = fromMaybeDouble a9} in 
  preErrorCheck $ \a10' -> 
  fdmCev1dMesher'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' >>= \res ->
  peekFdm1dMesher res >>= \res' ->
  errorCheck  a10'>>
  return (res')

{-# LINE 656 "./QuantLib/Method.chs" #-}


-- |'ExponentialJump1dMesher(steps, beta, jumpIntensity, eta, eps)' -- mesher for the jump-diffusion
-- component of a jump-diffusion process.
exponentialJump1dMesher :: (Word) -- ^steps
 -> (Double) -- ^beta
 -> (Double) -- ^jumpIntensity
 -> (Double) -- ^eta
 -> (Double) -- ^eps
 -> IO ((Fdm1dMesher))
exponentialJump1dMesher a1 a2 a3 a4 a5 =
  let {a1' = fromIntegral a1} in 
  let {a2' = realToFrac a2} in 
  let {a3' = realToFrac a3} in 
  let {a4' = realToFrac a4} in 
  let {a5' = realToFrac a5} in 
  preErrorCheck $ \a6' -> 
  exponentialJump1dMesher'_ a1' a2' a3' a4' a5' a6' >>= \res ->
  peekFdm1dMesher res >>= \res' ->
  errorCheck  a6'>>
  return (res')

{-# LINE 665 "./QuantLib/Method.chs" #-}


-- |'FdmSimpleProcess1dMesher(size, process, maturity, tAvgSteps, epsilon, mandatoryPoint)' --
-- generic mesher for any bound one-dimensional 'StochasticProcess1D'.
fdmSimpleProcess1dMesher :: (Word) -- ^size
 -> (GenStochasticProcess1D p1d) -> (Double) -- ^maturity
 -> (Word) -- ^tAvgSteps
 -> (Double) -- ^epsilon
 -> (Maybe Double) -- ^mandatoryPoint
 -> IO ((Fdm1dMesher))
fdmSimpleProcess1dMesher a1 a2 a3 a4 a5 a6 =
  let {a1' = fromIntegral a1} in 
  withStochasticProcess1D a2 $ \a2' -> 
  let {a3' = realToFrac a3} in 
  let {a4' = fromIntegral a4} in 
  let {a5' = realToFrac a5} in 
  let {a6' = fromMaybeDouble a6} in 
  preErrorCheck $ \a7' -> 
  fdmSimpleProcess1dMesher'_ a1' a2' a3' a4' a5' a6' a7' >>= \res ->
  peekFdm1dMesher res >>= \res' ->
  errorCheck  a7'>>
  return (res')

{-# LINE 675 "./QuantLib/Method.chs" #-}


-- |'FdmHestonVarianceMesher(size, process, maturity, tAvgSteps, epsilon, mixingFactor)' -- variance
-- mesher for a Heston-family process.
fdmHestonVarianceMesher :: (Word) -- ^size
 -> (GenHestonProcess hp) -> (Double) -- ^maturity
 -> (Word) -- ^tAvgSteps
 -> (Double) -- ^epsilon
 -> (Double) -- ^mixingFactor
 -> IO ((Fdm1dMesher))
fdmHestonVarianceMesher a1 a2 a3 a4 a5 a6 =
  let {a1' = fromIntegral a1} in 
  withHestonProcess a2 $ \a2' -> 
  let {a3' = realToFrac a3} in 
  let {a4' = fromIntegral a4} in 
  let {a5' = realToFrac a5} in 
  let {a6' = realToFrac a6} in 
  preErrorCheck $ \a7' -> 
  fdmHestonVarianceMesher'_ a1' a2' a3' a4' a5' a6' a7' >>= \res ->
  peekFdm1dMesher res >>= \res' ->
  errorCheck  a7'>>
  return (res')

{-# LINE 685 "./QuantLib/Method.chs" #-}


-- |'FdmHestonLocalVolatilityVarianceMesher(size, process, leverageFct, maturity, tAvgSteps, epsilon, mixingFactor)'
-- -- Heston variance mesher accounting for a local-volatility leverage function.
fdmHestonLocalVolatilityVarianceMesher :: (Word) -- ^size
 -> (GenHestonProcess hp) -> (GenLocalVolTermStructure lv) -- ^leverageFct
 -> (Double) -- ^maturity
 -> (Word) -- ^tAvgSteps
 -> (Double) -- ^epsilon
 -> (Double) -- ^mixingFactor
 -> IO ((Fdm1dMesher))
fdmHestonLocalVolatilityVarianceMesher a1 a2 a3 a4 a5 a6 a7 =
  let {a1' = fromIntegral a1} in 
  withHestonProcess a2 $ \a2' -> 
  withGenLocalVolTermStructure a3 $ \a3' -> 
  let {a4' = realToFrac a4} in 
  let {a5' = fromIntegral a5} in 
  let {a6' = realToFrac a6} in 
  let {a7' = realToFrac a7} in 
  preErrorCheck $ \a8' -> 
  fdmHestonLocalVolatilityVarianceMesher'_ a1' a2' a3' a4' a5' a6' a7' a8' >>= \res ->
  peekFdm1dMesher res >>= \res' ->
  errorCheck  a8'>>
  return (res')

{-# LINE 696 "./QuantLib/Method.chs" #-}


-- |'FdmMesherComposite' -- combine one or more 'Fdm1dMesher's into the multi-dimensional
-- 'FdmMesher' the operator\/step-condition callbacks and 'fdmSolve' operate over; the sole
-- concrete 'FdmMesher' upstream.
fdmMesherComposite :: ([Fdm1dMesher]) -> IO ((FdmMesher))
fdmMesherComposite a1 =
  withFdm1dMesherArray a1 $ \(a1'1, a1'2) -> 
  preErrorCheck $ \a2' -> 
  fdmMesherComposite'_ a1'1  a1'2 a2' >>= \res ->
  peekFdmMesher res >>= \res' ->
  errorCheck  a2'>>
  return (res')

{-# LINE 702 "./QuantLib/Method.chs" #-}


-- |Real-valued node locations along one dimension of a mesher, e.g. to map 'fdmSolve''s flat
-- result array back to coordinates (mirrors how @Fdm1DimSolver@\/@FdmNdimSolver@ build their own
-- @x_@ arrays from this same call upstream).
fdmMesherLocations :: (FdmMesher) -> (Int) -- ^direction
 -> IO ((RealVector))
fdmMesherLocations a1 a2 =
  withFdmMesher a1 $ \a1' -> 
  let {a2' = fromIntegral a2} in 
  preDoubleArray $ \(a3'1, a3'2) -> 
  preErrorCheck $ \a4' -> 
  fdmMesherLocations'_ a1' a2' a3'1  a3'2 a4' >>
  peekRealVector  a3'1  a3'2>>= \a3'' -> 
  errorCheck  a4'>>
  return (a3'')

{-# LINE 710 "./QuantLib/Method.chs" #-}


qlFdmInnerValueCalculatorFromFunctions :: (FdmMesher) -> (Callback) -> (Callback) -> IO ((FdmInnerValueCalculator))
qlFdmInnerValueCalculatorFromFunctions a1 a2 a3 =
  withFdmMesher a1 $ \a1' -> 
  withCallbackPtr a2 $ \a2' -> 
  withCallbackPtr a3 $ \a3' -> 
  preErrorCheck $ \a4' -> 
  qlFdmInnerValueCalculatorFromFunctions'_ a1' a2' a3' a4' >>= \res ->
  peekFdmInnerValueCalculator res >>= \res' ->
  errorCheck  a4'>>
  return (res')

{-# LINE 714 "./QuantLib/Method.chs" #-}


-- |Wraps a Haskell @t -> location -> value@ pair of @innerValue@\/@avgInnerValue@ functions as a
-- real 'FdmInnerValueCalculator' that retains both callbacks after the continuation returns.
-- Callback exceptions are rethrown by the enclosing Haskell call. Unlike every callback
-- 'fdmRollback' takes, this crosses the language boundary once /per grid node/, not once per outer
-- iteration over the whole grid -- there is no batched \"whole-grid inner value\" shape anywhere
-- in QuantLib or QuantLib-SWIG. The per-call FFI cost across
-- every node (and, if a step condition also calls the calculator, every node at every exercise
-- date) is accepted -- matching QuantLib-SWIG's own accepted-cost precedent,
-- @FdmInnerValueCalculatorDelegate@ (@SWIG\/fdm.i@).
withCustomFdmInnerValueCalculator :: FdmMesher
  -> (Double -> [Double] -> Double) -- ^innerValue(t, location)
  -> (Double -> [Double] -> Double) -- ^avgInnerValue(t, location)
  -> (FdmInnerValueCalculator -> IO b) -> IO b
withCustomFdmInnerValueCalculator :: forall b.
FdmMesher
-> (Double -> [Double] -> Double)
-> (Double -> [Double] -> Double)
-> (FdmInnerValueCalculator -> IO b)
-> IO b
withCustomFdmInnerValueCalculator FdmMesher
mesher Double -> [Double] -> Double
iv Double -> [Double] -> Double
aiv FdmInnerValueCalculator -> IO b
k =
  (Double -> [Double] -> Double) -> (Callback -> IO b) -> IO b
forall b.
(Double -> [Double] -> Double) -> (Callback -> IO b) -> IO b
withFdmInnerValue Double -> [Double] -> Double
iv ((Callback -> IO b) -> IO b) -> (Callback -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \Callback
inner ->
  (Double -> [Double] -> Double) -> (Callback -> IO b) -> IO b
forall b.
(Double -> [Double] -> Double) -> (Callback -> IO b) -> IO b
withFdmInnerValue Double -> [Double] -> Double
aiv ((Callback -> IO b) -> IO b) -> (Callback -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \Callback
average ->
  FdmMesher -> Callback -> Callback -> IO FdmInnerValueCalculator
qlFdmInnerValueCalculatorFromFunctions FdmMesher
mesher Callback
inner Callback
average IO FdmInnerValueCalculator
-> (FdmInnerValueCalculator -> IO b) -> IO b
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= FdmInnerValueCalculator -> IO b
k

-- |'FdmZeroInnerValue' -- an 'FdmInnerValueCalculator' whose @innerValue@\/@avgInnerValue@ are
-- always 0.
fdmZeroInnerValue :: IO ((FdmInnerValueCalculator))
fdmZeroInnerValue :: IO FdmInnerValueCalculator
fdmZeroInnerValue =
  (Ptr (Ptr ()) -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr (Ptr ()) -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a1' -> 
  Ptr (Ptr ()) -> IO (Ptr CFdmInnerValueCalculator)
fdmZeroInnerValue'_ Ptr (Ptr ())
a1' IO (Ptr CFdmInnerValueCalculator)
-> (Ptr CFdmInnerValueCalculator -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CFdmInnerValueCalculator
res ->
  Ptr CFdmInnerValueCalculator -> IO FdmInnerValueCalculator
peekFdmInnerValueCalculator Ptr CFdmInnerValueCalculator
res IO FdmInnerValueCalculator
-> (FdmInnerValueCalculator -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \FdmInnerValueCalculator
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a1'IO () -> IO FdmInnerValueCalculator -> IO FdmInnerValueCalculator
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  FdmInnerValueCalculator -> IO FdmInnerValueCalculator
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (FdmInnerValueCalculator
res')

{-# LINE 736 "./QuantLib/Method.chs" #-}


-- |'FdmCellAveragingInnerValue(payoff, mesher, direction)' -- cell-averages @payoff@ over each
-- grid cell along @direction@ (Simpson-integrating across the cell straddling a kink, e.g. a
-- strike, rather than just evaluating at the cell center), with the identity value mapping. See
-- 'withCustomCellAveragingInnerValue' for the @gridMapping@-taking overload (e.g. to reproduce
-- 'fdmLogInnerValue' by hand), and 'fdmLogInnerValue' for the common log-mapped case QuantLib
-- itself gives its own dedicated subclass.
fdmCellAveragingInnerValue :: (Payoff) -> (FdmMesher) -> (Int) -- ^direction
 -> IO ((FdmInnerValueCalculator))
fdmCellAveragingInnerValue :: Payoff -> FdmMesher -> Int -> IO FdmInnerValueCalculator
fdmCellAveragingInnerValue Payoff
a1 FdmMesher
a2 Int
a3 =
  Payoff
-> (QlPayoff -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a. Payoff -> (QlPayoff -> IO a) -> IO a
withPayoff Payoff
a1 ((QlPayoff -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (QlPayoff -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \QlPayoff
a1' -> 
  FdmMesher
-> (Ptr CFdmMesher -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall b. FdmMesher -> (Ptr CFdmMesher -> IO b) -> IO b
withFdmMesher FdmMesher
a2 ((Ptr CFdmMesher -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr CFdmMesher -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr CFdmMesher
a2' -> 
  let {a3' :: CUInt
a3' = Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a3} in 
  (Ptr (Ptr ()) -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr (Ptr ()) -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a4' -> 
  QlPayoff
-> Ptr CFdmMesher
-> CUInt
-> Ptr (Ptr ())
-> IO (Ptr CFdmInnerValueCalculator)
fdmCellAveragingInnerValue'_ QlPayoff
a1' Ptr CFdmMesher
a2' CUInt
a3' Ptr (Ptr ())
a4' IO (Ptr CFdmInnerValueCalculator)
-> (Ptr CFdmInnerValueCalculator -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CFdmInnerValueCalculator
res ->
  Ptr CFdmInnerValueCalculator -> IO FdmInnerValueCalculator
peekFdmInnerValueCalculator Ptr CFdmInnerValueCalculator
res IO FdmInnerValueCalculator
-> (FdmInnerValueCalculator -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \FdmInnerValueCalculator
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a4'IO () -> IO FdmInnerValueCalculator -> IO FdmInnerValueCalculator
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  FdmInnerValueCalculator -> IO FdmInnerValueCalculator
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (FdmInnerValueCalculator
res')

{-# LINE 747 "./QuantLib/Method.chs" #-}


qlFdmCellAveragingInnerValueMapped :: (Payoff) -> (FdmMesher) -> (Int) -> (Callback) -> IO ((FdmInnerValueCalculator))
qlFdmCellAveragingInnerValueMapped a1 a2 a3 a4 =
  withPayoff a1 $ \a1' -> 
  withFdmMesher a2 $ \a2' -> 
  let {a3' = fromIntegral a3} in 
  withCallbackPtr a4 $ \a4' -> 
  preErrorCheck $ \a5' -> 
  qlFdmCellAveragingInnerValueMapped'_ a1' a2' a3' a4' a5' >>= \res ->
  peekFdmInnerValueCalculator res >>= \res' ->
  errorCheck  a5'>>
  return (res')

{-# LINE 751 "./QuantLib/Method.chs" #-}


-- |As 'fdmCellAveragingInnerValue', but with an explicit @gridMapping :: Double -> Double@ applied
-- to each node's location before the payoff sees it (e.g. @exp@ on a log-spot grid, reproducing
-- 'fdmLogInnerValue' by hand) -- a genuine per-node Haskell callback; see
-- 'withCustomFdmInnerValueCalculator'. The calculator retains the callback after the continuation.
withCustomCellAveragingInnerValue :: Payoff -> FdmMesher -> Int -> (Double -> Double)
  -> (FdmInnerValueCalculator -> IO b) -> IO b
withCustomCellAveragingInnerValue payoff mesher direction mapping k =
  withFdmGridMapping mapping $ \callback ->
  qlFdmCellAveragingInnerValueMapped payoff mesher direction callback >>= k

-- |'FdmLogInnerValue(payoff, mesher, direction)' -- 'fdmCellAveragingInnerValue' with the
-- @gridMapping = exp@ QuantLib itself gives its own dedicated subclass (the standard shape for a
-- log-spot grid, e.g. 'fdmBlackScholesMesher''s own grid).
fdmLogInnerValue :: (Payoff) -> (FdmMesher) -> (Int) -- ^direction
 -> IO ((FdmInnerValueCalculator))
fdmLogInnerValue :: Payoff -> FdmMesher -> Int -> IO FdmInnerValueCalculator
fdmLogInnerValue Payoff
a1 FdmMesher
a2 Int
a3 =
  Payoff
-> (QlPayoff -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a. Payoff -> (QlPayoff -> IO a) -> IO a
withPayoff Payoff
a1 ((QlPayoff -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (QlPayoff -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \QlPayoff
a1' -> 
  FdmMesher
-> (Ptr CFdmMesher -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall b. FdmMesher -> (Ptr CFdmMesher -> IO b) -> IO b
withFdmMesher FdmMesher
a2 ((Ptr CFdmMesher -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr CFdmMesher -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr CFdmMesher
a2' -> 
  let {a3' :: CUInt
a3' = Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a3} in 
  (Ptr (Ptr ()) -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr (Ptr ()) -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a4' -> 
  QlPayoff
-> Ptr CFdmMesher
-> CUInt
-> Ptr (Ptr ())
-> IO (Ptr CFdmInnerValueCalculator)
fdmLogInnerValue'_ QlPayoff
a1' Ptr CFdmMesher
a2' CUInt
a3' Ptr (Ptr ())
a4' IO (Ptr CFdmInnerValueCalculator)
-> (Ptr CFdmInnerValueCalculator -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CFdmInnerValueCalculator
res ->
  Ptr CFdmInnerValueCalculator -> IO FdmInnerValueCalculator
peekFdmInnerValueCalculator Ptr CFdmInnerValueCalculator
res IO FdmInnerValueCalculator
-> (FdmInnerValueCalculator -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \FdmInnerValueCalculator
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a4'IO () -> IO FdmInnerValueCalculator -> IO FdmInnerValueCalculator
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  FdmInnerValueCalculator -> IO FdmInnerValueCalculator
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (FdmInnerValueCalculator
res')

{-# LINE 769 "./QuantLib/Method.chs" #-}


-- |'FdmLogBasketInnerValue(payoff, mesher)' -- the multi-asset counterpart to 'fdmLogInnerValue':
-- evaluates a 'BasketPayoff' with each dimension's location exponentiated first (@exp@ on every
-- mesher direction, i.e. a log-spot grid per underlying), no cell averaging.
fdmLogBasketInnerValue :: (BasketPayoff) -> (FdmMesher) -> IO ((FdmInnerValueCalculator))
fdmLogBasketInnerValue a1 a2 =
  withBasketPayoff a1 $ \a1' -> 
  withFdmMesher a2 $ \a2' -> 
  preErrorCheck $ \a3' -> 
  fdmLogBasketInnerValue'_ a1' a2' a3' >>= \res ->
  peekFdmInnerValueCalculator res >>= \res' ->
  errorCheck  a3'>>
  return (res')

{-# LINE 776 "./QuantLib/Method.chs" #-}


-- |'FdmAffineModelSwapInnerValue\<G2\>(disModel, fwdModel, swap, exerciseDates, mesher, direction)'
-- -- the swap-NPV-under-the-model 'FdmInnerValueCalculator' used internally by
-- 'QuantLib.PricingEngine.fdG2SwaptionEngine'. @exerciseDates@ pairs each exercise time (the same
-- @Time@-as-@Double@ year-fraction convention used throughout, not a dedicated type) with the
-- 'Data.Time.Calendar.Day' it corresponds to (upstream's @std::map\<Time, Date\>@).
fdmAffineG2ModelSwapInnerValue :: G2 -> G2 -> GenFixedVsFloatingSwap f -> [(Double, Day)] -> FdmMesher -> Int -> IO FdmInnerValueCalculator
fdmAffineG2ModelSwapInnerValue disModel fwdModel swap exerciseDates =
  let (times, dates) = unzip exerciseDates
  in qlFdmAffineG2ModelSwapInnerValue disModel fwdModel swap (length exerciseDates) times dates
qlFdmAffineG2ModelSwapInnerValue :: (G2) -> (G2) -> (GenFixedVsFloatingSwap f) -> (Int) -- ^number of exercise dates
 -> ([Double]) -- ^exercise times
 -> ([Day]) -- ^exercise dates
 -> (FdmMesher) -> (Int) -- ^direction
 -> IO ((FdmInnerValueCalculator))
qlFdmAffineG2ModelSwapInnerValue :: forall f.
G2
-> G2
-> GenFixedVsFloatingSwap f
-> Int
-> [Double]
-> [Day]
-> FdmMesher
-> Int
-> IO FdmInnerValueCalculator
qlFdmAffineG2ModelSwapInnerValue G2
a1 G2
a2 GenFixedVsFloatingSwap f
a3 Int
a4 [Double]
a5 [Day]
a6 FdmMesher
a7 Int
a8 =
  G2
-> (Ptr CG2' -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall b. G2 -> (Ptr CG2' -> IO b) -> IO b
withG2 G2
a1 ((Ptr CG2' -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr CG2' -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr CG2'
a1' -> 
  G2
-> (Ptr CG2' -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall b. G2 -> (Ptr CG2' -> IO b) -> IO b
withG2 G2
a2 ((Ptr CG2' -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr CG2' -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr CG2'
a2' -> 
  GenFixedVsFloatingSwap f
-> (Ptr CFixedVsFloatingSwap' -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall f b.
GenFixedVsFloatingSwap f
-> (Ptr CFixedVsFloatingSwap' -> IO b) -> IO b
withFixedVsFloatingSwap GenFixedVsFloatingSwap f
a3 ((Ptr CFixedVsFloatingSwap' -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr CFixedVsFloatingSwap' -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr CFixedVsFloatingSwap'
a3' -> 
  let {a4' :: CUInt
a4' = Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a4} in 
  [Double]
-> (Ptr CDouble -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall b. [Double] -> (Ptr CDouble -> IO b) -> IO b
withDoubleArrayRaw [Double]
a5 ((Ptr CDouble -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr CDouble -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr CDouble
a5' -> 
  [Day]
-> (Ptr CInt -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a. [Day] -> (Ptr CInt -> IO a) -> IO a
withDayPtr [Day]
a6 ((Ptr CInt -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr CInt -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
a6' -> 
  FdmMesher
-> (Ptr CFdmMesher -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall b. FdmMesher -> (Ptr CFdmMesher -> IO b) -> IO b
withFdmMesher FdmMesher
a7 ((Ptr CFdmMesher -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr CFdmMesher -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr CFdmMesher
a7' -> 
  let {a8' :: CUInt
a8' = Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a8} in 
  preErrorCheck $ \a9' -> 
  qlFdmAffineG2ModelSwapInnerValue'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' >>= \res ->
  peekFdmInnerValueCalculator res >>= \res' ->
  errorCheck  a9'>>
  return (res')

{-# LINE 795 "./QuantLib/Method.chs" #-}


-- |As 'fdmAffineG2ModelSwapInnerValue', but for 'HullWhite' -- used internally by
-- 'QuantLib.PricingEngine.fdHullWhiteSwaptionEngine'.
fdmAffineHullWhiteModelSwapInnerValue :: HullWhite -> HullWhite -> GenFixedVsFloatingSwap f -> [(Double, Day)] -> FdmMesher -> Int -> IO FdmInnerValueCalculator
fdmAffineHullWhiteModelSwapInnerValue disModel fwdModel swap exerciseDates =
  let (times, dates) = unzip exerciseDates
  in qlFdmAffineHullWhiteModelSwapInnerValue disModel fwdModel swap (length exerciseDates) times dates
qlFdmAffineHullWhiteModelSwapInnerValue :: (HullWhite) -> (HullWhite) -> (GenFixedVsFloatingSwap f) -> (Int) -- ^number of exercise dates
 -> ([Double]) -- ^exercise times
 -> ([Day]) -- ^exercise dates
 -> (FdmMesher) -> (Int) -- ^direction
 -> IO ((FdmInnerValueCalculator))
qlFdmAffineHullWhiteModelSwapInnerValue :: forall f.
HullWhite
-> HullWhite
-> GenFixedVsFloatingSwap f
-> Int
-> [Double]
-> [Day]
-> FdmMesher
-> Int
-> IO FdmInnerValueCalculator
qlFdmAffineHullWhiteModelSwapInnerValue HullWhite
a1 HullWhite
a2 GenFixedVsFloatingSwap f
a3 Int
a4 [Double]
a5 [Day]
a6 FdmMesher
a7 Int
a8 =
  HullWhite
-> (Ptr CHullWhite' -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall b. HullWhite -> (Ptr CHullWhite' -> IO b) -> IO b
withHullWhite HullWhite
a1 ((Ptr CHullWhite' -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr CHullWhite' -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr CHullWhite'
a1' -> 
  HullWhite
-> (Ptr CHullWhite' -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall b. HullWhite -> (Ptr CHullWhite' -> IO b) -> IO b
withHullWhite HullWhite
a2 ((Ptr CHullWhite' -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr CHullWhite' -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr CHullWhite'
a2' -> 
  GenFixedVsFloatingSwap f
-> (Ptr CFixedVsFloatingSwap' -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall f b.
GenFixedVsFloatingSwap f
-> (Ptr CFixedVsFloatingSwap' -> IO b) -> IO b
withFixedVsFloatingSwap GenFixedVsFloatingSwap f
a3 ((Ptr CFixedVsFloatingSwap' -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr CFixedVsFloatingSwap' -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr CFixedVsFloatingSwap'
a3' -> 
  let {a4' :: CUInt
a4' = Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a4} in 
  [Double]
-> (Ptr CDouble -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall b. [Double] -> (Ptr CDouble -> IO b) -> IO b
withDoubleArrayRaw [Double]
a5 ((Ptr CDouble -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr CDouble -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr CDouble
a5' -> 
  [Day]
-> (Ptr CInt -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a. [Day] -> (Ptr CInt -> IO a) -> IO a
withDayPtr [Day]
a6 ((Ptr CInt -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr CInt -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
a6' -> 
  FdmMesher
-> (Ptr CFdmMesher -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall b. FdmMesher -> (Ptr CFdmMesher -> IO b) -> IO b
withFdmMesher FdmMesher
a7 ((Ptr CFdmMesher -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr CFdmMesher -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr CFdmMesher
a7' -> 
  let {a8' :: CUInt
a8' = Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a8} in 
  (Ptr (Ptr ()) -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr (Ptr ()) -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a9' -> 
  Ptr CHullWhite'
-> Ptr CHullWhite'
-> Ptr CFixedVsFloatingSwap'
-> CUInt
-> Ptr CDouble
-> Ptr CInt
-> Ptr CFdmMesher
-> CUInt
-> Ptr (Ptr ())
-> IO (Ptr CFdmInnerValueCalculator)
qlFdmAffineHullWhiteModelSwapInnerValue'_ Ptr CHullWhite'
a1' Ptr CHullWhite'
a2' Ptr CFixedVsFloatingSwap'
a3' CUInt
a4' Ptr CDouble
a5' Ptr CInt
a6' Ptr CFdmMesher
a7' CUInt
a8' Ptr (Ptr ())
a9' IO (Ptr CFdmInnerValueCalculator)
-> (Ptr CFdmInnerValueCalculator -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Ptr CFdmInnerValueCalculator
res ->
  Ptr CFdmInnerValueCalculator -> IO FdmInnerValueCalculator
peekFdmInnerValueCalculator Ptr CFdmInnerValueCalculator
res IO FdmInnerValueCalculator
-> (FdmInnerValueCalculator -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \FdmInnerValueCalculator
res' ->
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a9'IO () -> IO FdmInnerValueCalculator -> IO FdmInnerValueCalculator
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  FdmInnerValueCalculator -> IO FdmInnerValueCalculator
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (FdmInnerValueCalculator
res')

{-# LINE 811 "./QuantLib/Method.chs" #-}


-- |Evaluate an 'FdmInnerValueCalculator''s @innerValue@ at the mesher node given by its
-- coordinates (one index per PDE dimension), at time @t@ -- lets any bound calculator (native or
-- built via 'withCustomFdmInnerValueCalculator') be inspected directly without assembling a whole
-- 'fdmSolve'.
fdmInnerValue :: (FdmInnerValueCalculator) -> (FdmMesher) -> ([Int]) -- ^node coordinates
 -> (Double) -- ^t
 -> IO ((Double))
fdmInnerValue a1 a2 a3 a4 =
  withFdmInnerValueCalculator a1 $ \a1' -> 
  withFdmMesher a2 $ \a2' -> 
  withIntArray a3 $ \(a3'1, a3'2) -> 
  let {a4' = realToFrac a4} in 
  preErrorCheck $ \a5' -> 
  fdmInnerValue'_ a1' a2' a3'1  a3'2 a4' a5' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a5'>>
  return (res')

{-# LINE 821 "./QuantLib/Method.chs" #-}


-- |As 'fdmInnerValue', but for @avgInnerValue@.
fdmAvgInnerValue :: (FdmInnerValueCalculator) -> (FdmMesher) -> ([Int]) -- ^node coordinates
 -> (Double) -- ^t
 -> IO ((Double))
fdmAvgInnerValue a1 a2 a3 a4 =
  withFdmInnerValueCalculator a1 $ \a1' -> 
  withFdmMesher a2 $ \a2' -> 
  withIntArray a3 $ \(a3'1, a3'2) -> 
  let {a4' = realToFrac a4} in 
  preErrorCheck $ \a5' -> 
  fdmAvgInnerValue'_ a1' a2' a3'1  a3'2 a4' a5' >>= \res ->
  let {res' = realToFrac res} in
  errorCheck  a5'>>
  return (res')

{-# LINE 828 "./QuantLib/Method.chs" #-}


-- |Sibling of 'fdmRollback' that derives its own initial grid from a mesher and an
-- 'FdmInnerValueCalculator' (@avgInnerValue(t, location)@ per node, called once per mesher node at
-- @t = maturity@ -- mirroring @Fdm1DimSolver@\/@FdmNdimSolver@'s own constructor loop) instead of
-- taking a precomputed grid array. Everything else (operator\/step-condition\/scheme\/rollback) is
-- identical to 'fdmRollback', reusing the same callback machinery. The calculator can be either
-- fully custom ('fdmInnerValueCalculator') or one of QuantLib's own native subclasses.
--
-- @Fdm1DimSolver@\/@FdmNdimSolver@ themselves (their own @LazyObject@ caching and cubic-spline
-- interpolation) are /not/ bound; combine this function's result with 'fdmMesherLocations' for
-- interpolation.
fdmSolve :: (FdmMesher) -> (FdmInnerValueCalculator) -> (Int) -- ^number of PDE directions\/dimensions the operator has
 -> ((Double,Double) -> RealVector -> RealVector) -- ^@apply(r)@
 -> (Int -> (Double,Double) -> RealVector -> RealVector) -- ^@apply_direction(direction, r)@
 -> (Int -> Double -> (Double,Double) -> RealVector -> RealVector) -- ^@solve_splitting(direction, r, s)@
 -> (Maybe (Double -> RealVector -> RealVector)) -- ^optional step condition
 -> (RealVector) -- ^stopping times at which the step condition above is applied
 -> (FdmScheme) -- ^the finite-difference scheme
 -> (Double) -- ^maturity (start time of the rollback, and the time at which avgInnerValue builds the initial grid)
 -> (Double) -- ^to (end time of the rollback, e.g. 0)
 -> (Int) -- ^steps
 -> (Int) -- ^dampingSteps
 -> IO ((RealVector))
fdmSolve :: FdmMesher
-> FdmInnerValueCalculator
-> Int
-> ((Double, Double) -> RealVector -> RealVector)
-> (Int -> (Double, Double) -> RealVector -> RealVector)
-> (Int -> Double -> (Double, Double) -> RealVector -> RealVector)
-> Maybe (Double -> RealVector -> RealVector)
-> RealVector
-> FdmScheme
-> Double
-> Double
-> Int
-> Int
-> IO RealVector
fdmSolve FdmMesher
a1 FdmInnerValueCalculator
a2 Int
a3 (Double, Double) -> RealVector -> RealVector
a4 Int -> (Double, Double) -> RealVector -> RealVector
a5 Int -> Double -> (Double, Double) -> RealVector -> RealVector
a6 Maybe (Double -> RealVector -> RealVector)
a7 RealVector
a8 FdmScheme
a9 Double
a10 Double
a11 Int
a12 Int
a13 =
  FdmMesher -> (Ptr CFdmMesher -> IO RealVector) -> IO RealVector
forall b. FdmMesher -> (Ptr CFdmMesher -> IO b) -> IO b
withFdmMesher FdmMesher
a1 ((Ptr CFdmMesher -> IO RealVector) -> IO RealVector)
-> (Ptr CFdmMesher -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr CFdmMesher
a1' -> 
  FdmInnerValueCalculator
-> (Ptr CFdmInnerValueCalculator -> IO RealVector) -> IO RealVector
forall b.
FdmInnerValueCalculator
-> (Ptr CFdmInnerValueCalculator -> IO b) -> IO b
withFdmInnerValueCalculator FdmInnerValueCalculator
a2 ((Ptr CFdmInnerValueCalculator -> IO RealVector) -> IO RealVector)
-> (Ptr CFdmInnerValueCalculator -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr CFdmInnerValueCalculator
a2' -> 
  let {a3' :: CUInt
a3' = Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a3} in 
  ((Double, Double) -> RealVector -> RealVector)
-> (Ptr () -> IO RealVector) -> IO RealVector
forall b.
((Double, Double) -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
withFdmApply (Double, Double) -> RealVector -> RealVector
a4 ((Ptr () -> IO RealVector) -> IO RealVector)
-> (Ptr () -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr ()
a4' -> 
  (Int -> (Double, Double) -> RealVector -> RealVector)
-> (Ptr () -> IO RealVector) -> IO RealVector
forall b.
(Int -> (Double, Double) -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
withFdmApplyDirection Int -> (Double, Double) -> RealVector -> RealVector
a5 ((Ptr () -> IO RealVector) -> IO RealVector)
-> (Ptr () -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr ()
a5' -> 
  (Int -> Double -> (Double, Double) -> RealVector -> RealVector)
-> (Ptr () -> IO RealVector) -> IO RealVector
forall b.
(Int -> Double -> (Double, Double) -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
withFdmSolveSplitting Int -> Double -> (Double, Double) -> RealVector -> RealVector
a6 ((Ptr () -> IO RealVector) -> IO RealVector)
-> (Ptr () -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr ()
a6' -> 
  Maybe (Double -> RealVector -> RealVector)
-> (Ptr () -> IO RealVector) -> IO RealVector
forall b.
Maybe (Double -> RealVector -> RealVector)
-> (Ptr () -> IO b) -> IO b
withMaybeFdmStepCondition Maybe (Double -> RealVector -> RealVector)
a7 ((Ptr () -> IO RealVector) -> IO RealVector)
-> (Ptr () -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr ()
a7' -> 
  RealVector
-> ((CUInt, Ptr CDouble) -> IO RealVector) -> IO RealVector
forall b. RealVector -> ((CUInt, Ptr CDouble) -> IO b) -> IO b
withRealVector RealVector
a8 (((CUInt, Ptr CDouble) -> IO RealVector) -> IO RealVector)
-> ((CUInt, Ptr CDouble) -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \(CUInt
a8'1, Ptr CDouble
a8'2) -> 
  FdmScheme -> (Ptr CFdmSchemeDesc -> IO RealVector) -> IO RealVector
forall a. FdmScheme -> (Ptr CFdmSchemeDesc -> IO a) -> IO a
withFdmSchemeDesc FdmScheme
a9 ((Ptr CFdmSchemeDesc -> IO RealVector) -> IO RealVector)
-> (Ptr CFdmSchemeDesc -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr CFdmSchemeDesc
a9' -> 
  let {a10' :: CDouble
a10' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a10} in 
  let {a11' :: CDouble
a11' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a11} in 
  let {a12' :: CUInt
a12' = Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a12} in 
  let {a13' :: CUInt
a13' = Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a13} in 
  ((Ptr CUInt, Ptr (Ptr CDouble)) -> IO RealVector) -> IO RealVector
forall b. ((Ptr CUInt, Ptr (Ptr CDouble)) -> IO b) -> IO b
preDoubleArray (((Ptr CUInt, Ptr (Ptr CDouble)) -> IO RealVector)
 -> IO RealVector)
-> ((Ptr CUInt, Ptr (Ptr CDouble)) -> IO RealVector)
-> IO RealVector
forall a b. (a -> b) -> a -> b
$ \(Ptr CUInt
a14'1, Ptr (Ptr CDouble)
a14'2) -> 
  (Ptr (Ptr ()) -> IO RealVector) -> IO RealVector
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr ()) -> IO RealVector) -> IO RealVector)
-> (Ptr (Ptr ()) -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr ())
a15' -> 
  Ptr CFdmMesher
-> Ptr CFdmInnerValueCalculator
-> CUInt
-> Ptr ()
-> Ptr ()
-> Ptr ()
-> Ptr ()
-> CUInt
-> Ptr CDouble
-> Ptr CFdmSchemeDesc
-> CDouble
-> CDouble
-> CUInt
-> CUInt
-> Ptr CUInt
-> Ptr (Ptr CDouble)
-> Ptr (Ptr ())
-> IO ()
fdmSolve'_ Ptr CFdmMesher
a1' Ptr CFdmInnerValueCalculator
a2' CUInt
a3' Ptr ()
a4' Ptr ()
a5' Ptr ()
a6' Ptr ()
a7' CUInt
a8'1  Ptr CDouble
a8'2 Ptr CFdmSchemeDesc
a9' CDouble
a10' CDouble
a11' CUInt
a12' CUInt
a13' Ptr CUInt
a14'1  Ptr (Ptr CDouble)
a14'2 Ptr (Ptr ())
a15' IO () -> IO RealVector -> IO RealVector
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  Ptr CUInt -> Ptr (Ptr CDouble) -> IO RealVector
peekRealVector  Ptr CUInt
a14'1  Ptr (Ptr CDouble)
a14'2IO RealVector -> (RealVector -> IO RealVector) -> IO RealVector
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \RealVector
a14'' -> 
  Ptr (Ptr ()) -> IO ()
forall a. Ptr (Ptr a) -> IO ()
errorCheck  Ptr (Ptr ())
a15'IO () -> IO RealVector -> IO RealVector
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
  RealVector -> IO RealVector
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (RealVector
a14'')

{-# LINE 854 "./QuantLib/Method.chs" #-}


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

foreign import ccall safe "QuantLib/Method.chs.h qlPathGenerator"
  pathGenerator'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (CStochasticProcess')) -> ((C2HSImp.Ptr (CTimeGrid)) -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CPathGenerator))))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlSobolPathGenerator"
  sobolPathGenerator'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (CStochasticProcess')) -> ((C2HSImp.Ptr (CTimeGrid)) -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CPathGenerator))))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlGaussianRsg"
  gaussianRsg'_ :: (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CGaussianRsg)))))))

foreign import ccall safe "QuantLib/Method.chs.h qlSobolGaussianRsg"
  sobolGaussianRsg'_ :: (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CGaussianRsg)))))))

foreign import ccall safe "QuantLib/Method.chs.h qlGaussianRsgDimension"
  rsgDimension'_ :: ((C2HSImp.Ptr (CGaussianRsg)) -> (IO C2HSImp.CUInt))

foreign import ccall safe "QuantLib/Method.chs.h qlGaussianRsgNextSequence"
  nextSequence'_ :: ((C2HSImp.Ptr (CGaussianRsg)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))

foreign import ccall safe "QuantLib/Method.chs.h qlGaussianRsgLastSequence"
  lastSequence'_ :: ((C2HSImp.Ptr (CGaussianRsg)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))

foreign import ccall safe "QuantLib/Method.chs.h qlPathGeneratorSequence"
  pathGeneratorSequence'_ :: ((C2HSImp.Ptr (CPathGenerator)) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))

foreign import ccall safe "QuantLib/Method.chs.h qlPathGeneratorNext"
  next'_ :: ((C2HSImp.Ptr (CPathGenerator)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CSamplePath)))))

foreign import ccall safe "QuantLib/Method.chs.h qlPathGeneratorAntithetic"
  antithetic'_ :: ((C2HSImp.Ptr (CPathGenerator)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CSamplePath)))))

foreign import ccall safe "QuantLib/Method.chs.h qlSamplePathWeight"
  weight'_ :: ((C2HSImp.Ptr (CSamplePath)) -> (IO C2HSImp.CDouble))

foreign import ccall safe "QuantLib/Method.chs.h qlSamplePathAssetNumber"
  assetNumber'_ :: ((C2HSImp.Ptr (CSamplePath)) -> (IO C2HSImp.CUInt))

foreign import ccall safe "QuantLib/Method.chs.h qlSamplePathSize"
  pathSize'_ :: ((C2HSImp.Ptr (CSamplePath)) -> (IO C2HSImp.CUInt))

foreign import ccall safe "QuantLib/Method.chs.h qlSamplePathAt"
  assetAt'_ :: ((C2HSImp.Ptr (CSamplePath)) -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))

foreign import ccall safe "QuantLib/Method.chs.h qlSamplePathAssetPath"
  asset'_ :: ((C2HSImp.Ptr (CSamplePath)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))

foreign import ccall safe "QuantLib/Method.chs.h qlLsmRegress"
  lsmRegress'_ :: (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlLsmRegressMulti"
  qlLsmRegressMulti'_ :: (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlLsmFit"
  qlLsmFit'_ :: (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlLsmEvaluate"
  qlLsmEvaluate'_ :: (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ())))))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlLsmEvaluatorIdentity"
  lsmEvaluatorIdentity'_ :: (IO (C2HSImp.Ptr C2HSImp.CChar))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmRollback"
  fdmRollback'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (CFdmSchemeDesc)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))))))))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlPredefined1dMesher"
  predefined1dMesher'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdm1dMesher))))))

foreign import ccall safe "QuantLib/Method.chs.h qlUniform1dMesher"
  uniform1dMesher'_ :: (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdm1dMesher)))))))

foreign import ccall safe "QuantLib/Method.chs.h qlConcentrating1dMesher"
  concentrating1dMesher'_ :: (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdm1dMesher))))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlConcentrating1dMesherMulti"
  qlConcentrating1dMesherMulti'_ :: (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr C2HSImp.CInt) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdm1dMesher))))))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlGluedMesher"
  gluedMesher'_ :: ((C2HSImp.Ptr (CFdm1dMesher)) -> ((C2HSImp.Ptr (CFdm1dMesher)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdm1dMesher))))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmBlackScholesMesher"
  fdmBlackScholesMesher'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr (CGeneralizedBlackScholesProcess')) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CDividend))) -> ((C2HSImp.Ptr (CFdmQuantoHelper)) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdm1dMesher))))))))))))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmCev1dMesher"
  fdmCev1dMesher'_ :: (C2HSImp.CUInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdm1dMesher)))))))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlExponentialJump1dMesher"
  exponentialJump1dMesher'_ :: (C2HSImp.CUInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdm1dMesher)))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmSimpleProcess1dMesher"
  fdmSimpleProcess1dMesher'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr (CStochasticProcess1D')) -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdm1dMesher))))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmHestonVarianceMesher"
  fdmHestonVarianceMesher'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr (CHestonProcess')) -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdm1dMesher))))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmHestonLocalVolatilityVarianceMesher"
  fdmHestonLocalVolatilityVarianceMesher'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr (CHestonProcess')) -> ((C2HSImp.Ptr (CLocalVolTermStructure')) -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdm1dMesher)))))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmMesherComposite"
  fdmMesherComposite'_ :: (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr (CFdm1dMesher))) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdmMesher))))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmMesherLocations"
  fdmMesherLocations'_ :: ((C2HSImp.Ptr (CFdmMesher)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmInnerValueCalculatorFromFunctions"
  qlFdmInnerValueCalculatorFromFunctions'_ :: ((C2HSImp.Ptr (CFdmMesher)) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdmInnerValueCalculator)))))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmZeroInnerValue"
  fdmZeroInnerValue'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdmInnerValueCalculator))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmCellAveragingInnerValue"
  fdmCellAveragingInnerValue'_ :: ((QlPayoff) -> ((C2HSImp.Ptr (CFdmMesher)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdmInnerValueCalculator)))))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmCellAveragingInnerValueMapped"
  qlFdmCellAveragingInnerValueMapped'_ :: ((QlPayoff) -> ((C2HSImp.Ptr (CFdmMesher)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdmInnerValueCalculator))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmLogInnerValue"
  fdmLogInnerValue'_ :: ((QlPayoff) -> ((C2HSImp.Ptr (CFdmMesher)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdmInnerValueCalculator)))))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmLogBasketInnerValue"
  fdmLogBasketInnerValue'_ :: ((QlBasketPayoff) -> ((C2HSImp.Ptr (CFdmMesher)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdmInnerValueCalculator))))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmAffineG2ModelSwapInnerValue"
  qlFdmAffineG2ModelSwapInnerValue'_ :: ((C2HSImp.Ptr (CG2')) -> ((C2HSImp.Ptr (CG2')) -> ((C2HSImp.Ptr (CFixedVsFloatingSwap')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr (CFdmMesher)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdmInnerValueCalculator))))))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmAffineHullWhiteModelSwapInnerValue"
  qlFdmAffineHullWhiteModelSwapInnerValue'_ :: ((C2HSImp.Ptr (CHullWhite')) -> ((C2HSImp.Ptr (CHullWhite')) -> ((C2HSImp.Ptr (CFixedVsFloatingSwap')) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr C2HSImp.CInt) -> ((C2HSImp.Ptr (CFdmMesher)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO (C2HSImp.Ptr (CFdmInnerValueCalculator))))))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmInnerValueCalculatorEval"
  fdmInnerValue'_ :: ((C2HSImp.Ptr (CFdmInnerValueCalculator)) -> ((C2HSImp.Ptr (CFdmMesher)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CUInt) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmInnerValueCalculatorAvgEval"
  fdmAvgInnerValue'_ :: ((C2HSImp.Ptr (CFdmInnerValueCalculator)) -> ((C2HSImp.Ptr (CFdmMesher)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CUInt) -> (C2HSImp.CDouble -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO C2HSImp.CDouble)))))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmSolve"
  fdmSolve'_ :: ((C2HSImp.Ptr (CFdmMesher)) -> ((C2HSImp.Ptr (CFdmInnerValueCalculator)) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CDouble) -> ((C2HSImp.Ptr (CFdmSchemeDesc)) -> (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr C2HSImp.CUInt) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CDouble)) -> ((C2HSImp.Ptr (C2HSImp.Ptr ())) -> (IO ()))))))))))))))))))