-- 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.
--
-- @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
--   ('QuantLib.Internal.Type.withFdmApply' et al.) 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. Because the
--   two callbacks are stored /inside/ the returned calculator and invoked again on every later
--   'fdmSolve'\/'fdmInnerValue' call (not just during construction), the calculator is only valid
--   /inside/ this continuation -- it cannot be built with a plain @IO FdmInnerValueCalculator@
--   smart constructor the way the native calculators below can.
--
-- [@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 hold no Haskell callback, so
--   they're plain @IO FdmInnerValueCalculator@ constructors -- except
--   'withCustomCellAveragingInnerValue', the one native constructor that /does/ take an explicit
--   @gridMapping@ callback, which needs the same continuation treatment as the fully custom case
--   above. '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
    -- ** Finite differences
  , fdmRollback
  , fdmInnerValue
  , fdmAvgInnerValue
  , fdmSolve
    -- ** Paths
  , weight
  , assetNumber
  , pathSize
  , assetAt
  , asset
    -- ** Random sequences and meshers
  , rsgDimension
  , lastSequence
  , 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 Foreign.Storable as C2HSImp
import qualified System.IO.Unsafe as C2HSImp







import QuantLib.Internal
import QuantLib.Internal.Type
import QuantLib.Internal.Common
import QuantLib.Math
{-# LINE 294 "./QuantLib/Method.chs" #-}

import Foreign.C.String(CString)
import Foreign.C.Types(CUInt, CDouble)
import Foreign.Ptr(Ptr, FunPtr, nullFunPtr, freeHaskellFunPtr, plusPtr, castPtr)
import Foreign.Marshal.Alloc(alloca)
import Foreign.Marshal.Array(copyArray)
import Foreign.Marshal.Utils(fillBytes)
import Foreign.Storable(sizeOf)
import Control.Exception(finally, mask)
import Control.Monad(when)
import qualified Data.Vector.Storable as V


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


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


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


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


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


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


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


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


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


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


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


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


{-# 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" #-}


-- FDM callbacks cross the ABI as one C struct pointer. c2hs reads every field offset from
-- FdmCallbackArgs itself, avoiding a duplicate target-layout contract in Haskell.
data CFdmCallbackArgs
-- c2hs erases callback-parameter struct pointers in generated imports, so retain its
-- @Ptr ()@ ABI here and cast only before the c2hs-generated field reads.
type FdmCallbackFun = Ptr () -> IO ()
foreign import ccall "wrapper" mkFdmCallbackFunPtr :: FdmCallbackFun -> IO (FunPtr FdmCallbackFun)

pokeBoundedFdmResult :: CUInt -> Ptr CDouble -> RealVector -> IO ()
pokeBoundedFdmResult :: CUInt -> Ptr CDouble -> RealVector -> IO ()
pokeBoundedFdmResult CUInt
n Ptr CDouble
out RealVector
result = do
  let expected :: Int
expected = CUInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CUInt
n
      copied :: Int
copied = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
expected (RealVector -> Int
forall a. Storable a => Vector a -> Int
V.length RealVector
result)
  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 ()
copyArray Ptr CDouble
out (Ptr Double -> Ptr CDouble
forall a b. Ptr a -> Ptr b
castPtr Ptr Double
p) Int
copied
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
copied Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
expected) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ Ptr (ZonkAny 0) -> Word8 -> Int -> IO ()
forall a. Ptr a -> Word8 -> Int -> IO ()
fillBytes (Ptr CDouble
out Ptr CDouble -> Int -> Ptr (ZonkAny 0)
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
copied Int -> Int -> Int
forall a. Num a => a -> a -> a
* CDouble -> Int
forall a. Storable a => a -> Int
sizeOf (CDouble
forall a. HasCallStack => a
undefined :: CDouble))) Word8
0 ((Int
expected Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
copied) Int -> Int -> Int
forall a. Num a => a -> a -> a
* CDouble -> Int
forall a. Storable a => a -> Int
sizeOf (CDouble
forall a. HasCallStack => a
undefined :: CDouble))

withFdmCallbackArgs :: Ptr CFdmCallbackArgs -> (Ptr CDouble -> CUInt -> CUInt -> CDouble -> CDouble -> CDouble -> Ptr CDouble -> IO a) -> IO a
withFdmCallbackArgs :: forall a.
Ptr CFdmCallbackArgs
-> (Ptr CDouble
    -> CUInt
    -> CUInt
    -> CDouble
    -> CDouble
    -> CDouble
    -> Ptr CDouble
    -> IO a)
-> IO a
withFdmCallbackArgs Ptr CFdmCallbackArgs
p Ptr CDouble
-> CUInt
-> CUInt
-> CDouble
-> CDouble
-> CDouble
-> Ptr CDouble
-> IO a
f = do
  s <- (\Ptr CFdmCallbackArgs
ptr -> do {Ptr CFdmCallbackArgs -> Int -> IO CDouble
forall b. Ptr b -> Int -> IO CDouble
forall a b. Storable a => Ptr b -> Int -> IO a
C2HSImp.peekByteOff Ptr CFdmCallbackArgs
ptr Int
0 :: IO C2HSImp.CDouble}) Ptr CFdmCallbackArgs
p
  t1 <- (\Ptr CFdmCallbackArgs
ptr -> do {Ptr CFdmCallbackArgs -> Int -> IO CDouble
forall b. Ptr b -> Int -> IO CDouble
forall a b. Storable a => Ptr b -> Int -> IO a
C2HSImp.peekByteOff Ptr CFdmCallbackArgs
ptr Int
8 :: IO C2HSImp.CDouble}) p
  t2 <- (\Ptr CFdmCallbackArgs
ptr -> do {Ptr CFdmCallbackArgs -> Int -> IO CDouble
forall b. Ptr b -> Int -> IO CDouble
forall a b. Storable a => Ptr b -> Int -> IO a
C2HSImp.peekByteOff Ptr CFdmCallbackArgs
ptr Int
16 :: IO C2HSImp.CDouble}) p
  input <- (\Ptr CFdmCallbackArgs
ptr -> do {Ptr CFdmCallbackArgs -> Int -> IO (Ptr CDouble)
forall b. Ptr b -> Int -> IO (Ptr CDouble)
forall a b. Storable a => Ptr b -> Int -> IO a
C2HSImp.peekByteOff Ptr CFdmCallbackArgs
ptr Int
24 :: IO (C2HSImp.Ptr C2HSImp.CDouble)}) p
  output <- (\Ptr CFdmCallbackArgs
ptr -> do {Ptr CFdmCallbackArgs -> Int -> IO (Ptr CDouble)
forall b. Ptr b -> Int -> IO (Ptr CDouble)
forall a b. Storable a => Ptr b -> Int -> IO a
C2HSImp.peekByteOff Ptr CFdmCallbackArgs
ptr Int
32 :: IO (C2HSImp.Ptr C2HSImp.CDouble)}) p
  n <- (\Ptr CFdmCallbackArgs
ptr -> do {Ptr CFdmCallbackArgs -> Int -> IO CUInt
forall b. Ptr b -> Int -> IO CUInt
forall a b. Storable a => Ptr b -> Int -> IO a
C2HSImp.peekByteOff Ptr CFdmCallbackArgs
ptr Int
40 :: IO C2HSImp.CUInt}) p
  direction <- (\Ptr CFdmCallbackArgs
ptr -> do {Ptr CFdmCallbackArgs -> Int -> IO CUInt
forall b. Ptr b -> Int -> IO CUInt
forall a b. Storable a => Ptr b -> Int -> IO a
C2HSImp.peekByteOff Ptr CFdmCallbackArgs
ptr Int
44 :: IO C2HSImp.CUInt}) p
  f input n direction s t1 t2 output

withFdmApply :: ((Double, Double) -> RealVector -> RealVector) -> (FunPtr FdmCallbackFun -> IO b) -> IO b
withFdmApply :: forall b.
((Double, Double) -> RealVector -> RealVector)
-> (FunPtr FdmCallbackFun -> IO b) -> IO b
withFdmApply (Double, Double) -> RealVector -> RealVector
f FunPtr FdmCallbackFun -> IO b
g = ((forall a. IO a -> IO a) -> IO b) -> IO b
forall b. ((forall a. IO a -> IO a) -> IO b) -> IO b
mask (((forall a. IO a -> IO a) -> IO b) -> IO b)
-> ((forall a. IO a -> IO a) -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \forall a. IO a -> IO a
restore -> do
  fp <- FdmCallbackFun -> IO (FunPtr FdmCallbackFun)
mkFdmCallbackFunPtr FdmCallbackFun
forall {a}. Ptr a -> IO ()
call
  restore (g fp) `finally` freeHaskellFunPtr fp
  where
    call :: Ptr a -> IO ()
call Ptr a
args = Ptr CFdmCallbackArgs
-> (Ptr CDouble
    -> CUInt
    -> CUInt
    -> CDouble
    -> CDouble
    -> CDouble
    -> Ptr CDouble
    -> IO ())
-> IO ()
forall a.
Ptr CFdmCallbackArgs
-> (Ptr CDouble
    -> CUInt
    -> CUInt
    -> CDouble
    -> CDouble
    -> CDouble
    -> Ptr CDouble
    -> IO a)
-> IO a
withFdmCallbackArgs (Ptr a -> Ptr CFdmCallbackArgs
forall a b. Ptr a -> Ptr b
castPtr Ptr a
args) ((Ptr CDouble
  -> CUInt
  -> CUInt
  -> CDouble
  -> CDouble
  -> CDouble
  -> Ptr CDouble
  -> IO ())
 -> IO ())
-> (Ptr CDouble
    -> CUInt
    -> CUInt
    -> CDouble
    -> CDouble
    -> CDouble
    -> Ptr CDouble
    -> IO ())
-> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr CDouble
xs CUInt
n CUInt
_dir CDouble
_s CDouble
t1 CDouble
t2 Ptr CDouble
out -> do
      x <- Ptr CDouble -> CUInt -> IO RealVector
borrowRealVector Ptr CDouble
xs CUInt
n
      pokeBoundedFdmResult n out (f (realToFrac t1, realToFrac t2) x)

withFdmApplyDirection :: (Int -> (Double, Double) -> RealVector -> RealVector) -> (FunPtr FdmCallbackFun -> IO b) -> IO b
withFdmApplyDirection :: forall b.
(Int -> (Double, Double) -> RealVector -> RealVector)
-> (FunPtr FdmCallbackFun -> IO b) -> IO b
withFdmApplyDirection Int -> (Double, Double) -> RealVector -> RealVector
f FunPtr FdmCallbackFun -> IO b
g = ((forall a. IO a -> IO a) -> IO b) -> IO b
forall b. ((forall a. IO a -> IO a) -> IO b) -> IO b
mask (((forall a. IO a -> IO a) -> IO b) -> IO b)
-> ((forall a. IO a -> IO a) -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \forall a. IO a -> IO a
restore -> do
  fp <- FdmCallbackFun -> IO (FunPtr FdmCallbackFun)
mkFdmCallbackFunPtr FdmCallbackFun
forall {a}. Ptr a -> IO ()
call
  restore (g fp) `finally` freeHaskellFunPtr fp
  where
    call :: Ptr a -> IO ()
call Ptr a
args = Ptr CFdmCallbackArgs
-> (Ptr CDouble
    -> CUInt
    -> CUInt
    -> CDouble
    -> CDouble
    -> CDouble
    -> Ptr CDouble
    -> IO ())
-> IO ()
forall a.
Ptr CFdmCallbackArgs
-> (Ptr CDouble
    -> CUInt
    -> CUInt
    -> CDouble
    -> CDouble
    -> CDouble
    -> Ptr CDouble
    -> IO a)
-> IO a
withFdmCallbackArgs (Ptr a -> Ptr CFdmCallbackArgs
forall a b. Ptr a -> Ptr b
castPtr Ptr a
args) ((Ptr CDouble
  -> CUInt
  -> CUInt
  -> CDouble
  -> CDouble
  -> CDouble
  -> Ptr CDouble
  -> IO ())
 -> IO ())
-> (Ptr CDouble
    -> CUInt
    -> CUInt
    -> CDouble
    -> CDouble
    -> CDouble
    -> Ptr CDouble
    -> IO ())
-> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr CDouble
xs CUInt
n CUInt
dir CDouble
_s CDouble
t1 CDouble
t2 Ptr CDouble
out -> do
      x <- Ptr CDouble -> CUInt -> IO RealVector
borrowRealVector Ptr CDouble
xs CUInt
n
      pokeBoundedFdmResult n out (f (fromIntegral dir) (realToFrac t1, realToFrac t2) x)

withFdmSolveSplitting :: (Int -> Double -> (Double, Double) -> RealVector -> RealVector) -> (FunPtr FdmCallbackFun -> IO b) -> IO b
withFdmSolveSplitting :: forall b.
(Int -> Double -> (Double, Double) -> RealVector -> RealVector)
-> (FunPtr FdmCallbackFun -> IO b) -> IO b
withFdmSolveSplitting Int -> Double -> (Double, Double) -> RealVector -> RealVector
f FunPtr FdmCallbackFun -> IO b
g = ((forall a. IO a -> IO a) -> IO b) -> IO b
forall b. ((forall a. IO a -> IO a) -> IO b) -> IO b
mask (((forall a. IO a -> IO a) -> IO b) -> IO b)
-> ((forall a. IO a -> IO a) -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \forall a. IO a -> IO a
restore -> do
  fp <- FdmCallbackFun -> IO (FunPtr FdmCallbackFun)
mkFdmCallbackFunPtr FdmCallbackFun
forall {a}. Ptr a -> IO ()
call
  restore (g fp) `finally` freeHaskellFunPtr fp
  where
    call :: Ptr a -> IO ()
call Ptr a
args = Ptr CFdmCallbackArgs
-> (Ptr CDouble
    -> CUInt
    -> CUInt
    -> CDouble
    -> CDouble
    -> CDouble
    -> Ptr CDouble
    -> IO ())
-> IO ()
forall a.
Ptr CFdmCallbackArgs
-> (Ptr CDouble
    -> CUInt
    -> CUInt
    -> CDouble
    -> CDouble
    -> CDouble
    -> Ptr CDouble
    -> IO a)
-> IO a
withFdmCallbackArgs (Ptr a -> Ptr CFdmCallbackArgs
forall a b. Ptr a -> Ptr b
castPtr Ptr a
args) ((Ptr CDouble
  -> CUInt
  -> CUInt
  -> CDouble
  -> CDouble
  -> CDouble
  -> Ptr CDouble
  -> IO ())
 -> IO ())
-> (Ptr CDouble
    -> CUInt
    -> CUInt
    -> CDouble
    -> CDouble
    -> CDouble
    -> Ptr CDouble
    -> IO ())
-> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr CDouble
xs CUInt
n CUInt
dir CDouble
s CDouble
t1 CDouble
t2 Ptr CDouble
out -> do
      x <- Ptr CDouble -> CUInt -> IO RealVector
borrowRealVector Ptr CDouble
xs CUInt
n
      pokeBoundedFdmResult n out (f (fromIntegral dir) (realToFrac s) (realToFrac t1, realToFrac t2) x)

withMaybeFdmStepCondition :: Maybe (Double -> RealVector -> RealVector) -> (FunPtr FdmCallbackFun -> IO b) -> IO b
withMaybeFdmStepCondition :: forall b.
Maybe (Double -> RealVector -> RealVector)
-> (FunPtr FdmCallbackFun -> IO b) -> IO b
withMaybeFdmStepCondition Maybe (Double -> RealVector -> RealVector)
Nothing FunPtr FdmCallbackFun -> IO b
g = FunPtr FdmCallbackFun -> IO b
g FunPtr FdmCallbackFun
forall a. FunPtr a
nullFunPtr
withMaybeFdmStepCondition (Just Double -> RealVector -> RealVector
f) FunPtr FdmCallbackFun -> IO b
g = ((forall a. IO a -> IO a) -> IO b) -> IO b
forall b. ((forall a. IO a -> IO a) -> IO b) -> IO b
mask (((forall a. IO a -> IO a) -> IO b) -> IO b)
-> ((forall a. IO a -> IO a) -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \forall a. IO a -> IO a
restore -> do
  fp <- FdmCallbackFun -> IO (FunPtr FdmCallbackFun)
mkFdmCallbackFunPtr FdmCallbackFun
forall {a}. Ptr a -> IO ()
call
  restore (g fp) `finally` freeHaskellFunPtr fp
  where
    call :: Ptr a -> IO ()
call Ptr a
args = Ptr CFdmCallbackArgs
-> (Ptr CDouble
    -> CUInt
    -> CUInt
    -> CDouble
    -> CDouble
    -> CDouble
    -> Ptr CDouble
    -> IO ())
-> IO ()
forall a.
Ptr CFdmCallbackArgs
-> (Ptr CDouble
    -> CUInt
    -> CUInt
    -> CDouble
    -> CDouble
    -> CDouble
    -> Ptr CDouble
    -> IO a)
-> IO a
withFdmCallbackArgs (Ptr a -> Ptr CFdmCallbackArgs
forall a b. Ptr a -> Ptr b
castPtr Ptr a
args) ((Ptr CDouble
  -> CUInt
  -> CUInt
  -> CDouble
  -> CDouble
  -> CDouble
  -> Ptr CDouble
  -> IO ())
 -> IO ())
-> (Ptr CDouble
    -> CUInt
    -> CUInt
    -> CDouble
    -> CDouble
    -> CDouble
    -> Ptr CDouble
    -> IO ())
-> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr CDouble
xs CUInt
n CUInt
_dir CDouble
_s CDouble
t CDouble
_t2 Ptr CDouble
out -> do
      x <- Ptr CDouble -> CUInt -> IO RealVector
borrowRealVector Ptr CDouble
xs CUInt
n
      pokeBoundedFdmResult n out (f (realToFrac t) x)

-- |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 CChar) -> IO PathGenerator) -> IO PathGenerator
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO PathGenerator) -> IO PathGenerator)
-> (Ptr (Ptr CChar) -> IO PathGenerator) -> IO PathGenerator
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a7' -> 
  CInt
-> Ptr CStochasticProcess'
-> Ptr CTimeGrid
-> CUInt
-> CUInt
-> CInt
-> Ptr (Ptr CChar)
-> IO (Ptr CPathGenerator)
pathGenerator'_ CInt
a1' Ptr CStochasticProcess'
a2' Ptr CTimeGrid
a3' CUInt
a4' CUInt
a5' CInt
a6' Ptr (Ptr CChar)
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 CChar) -> IO ()
errorCheck  Ptr (Ptr CChar)
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 394 "./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 401 "./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 -- for a path set, @assets * timesteps@,
-- matching what 'pathGenerator' is passed. 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 CChar) -> IO GaussianRsg) -> IO GaussianRsg
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO GaussianRsg) -> IO GaussianRsg)
-> (Ptr (Ptr CChar) -> IO GaussianRsg) -> IO GaussianRsg
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a4' -> 
  CInt -> CUInt -> CUInt -> Ptr (Ptr CChar) -> IO (Ptr CGaussianRsg)
gaussianRsg'_ CInt
a1' CUInt
a2' CUInt
a3' Ptr (Ptr CChar)
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 CChar) -> IO ()
errorCheck  Ptr (Ptr CChar)
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 424 "./QuantLib/Method.chs" #-}


-- |'gaussianRsg' driven by a low-discrepancy (Sobol) sequence with the given direction integers --
-- the 'sobolPathGenerator' counterpart.
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 431 "./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 434 "./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' -> 
  preArray $ \(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 441 "./QuantLib/Method.chs" #-}


-- |re-read the sequence 'nextSequence' last drew, without advancing the generator.
lastSequence :: (GaussianRsg) -> IO ((RealVector), (Double))
lastSequence a1 =
  withGaussianRsg a1 $ \a1' -> 
  preArray $ \(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 447 "./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 450 "./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 453 "./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 456 "./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 459 "./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 462 "./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 467 "./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 
  preArray $ \(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 470 "./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 a b. ((Ptr CUInt, Ptr (Ptr a)) -> IO b) -> IO b
preArray (((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 CChar) -> IO RealVector) -> IO RealVector
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO RealVector) -> IO RealVector)
-> (Ptr (Ptr CChar) -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a7' -> 
  CInt
-> CUInt
-> CUInt
-> Ptr CDouble
-> CUInt
-> Ptr CDouble
-> CUInt
-> Ptr CDouble
-> Ptr CUInt
-> Ptr (Ptr CDouble)
-> Ptr (Ptr CChar)
-> 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 CChar)
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 CChar) -> IO ()
errorCheck  Ptr (Ptr CChar)
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 484 "./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 Word
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 a b. ((Ptr CUInt, Ptr (Ptr a)) -> IO b) -> IO b
preArray (((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 CChar) -> IO RealVector) -> IO RealVector
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO RealVector) -> IO RealVector)
-> (Ptr (Ptr CChar) -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a11' -> 
  CInt
-> CUInt
-> CUInt
-> CUInt
-> Ptr CDouble
-> CUInt
-> Ptr CDouble
-> CUInt
-> CUInt
-> Ptr CDouble
-> Ptr CUInt
-> Ptr (Ptr CDouble)
-> Ptr (Ptr CChar)
-> 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 CChar)
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 CChar) -> IO ()
errorCheck  Ptr (Ptr CChar)
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 517 "./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).
--
-- /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)
-> (FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector
forall b.
((Double, Double) -> RealVector -> RealVector)
-> (FunPtr FdmCallbackFun -> IO b) -> IO b
withFdmApply (Double, Double) -> RealVector -> RealVector
a2 ((FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector)
-> (FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \FunPtr FdmCallbackFun
a2' -> 
  (Int -> (Double, Double) -> RealVector -> RealVector)
-> (FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector
forall b.
(Int -> (Double, Double) -> RealVector -> RealVector)
-> (FunPtr FdmCallbackFun -> IO b) -> IO b
withFdmApplyDirection Int -> (Double, Double) -> RealVector -> RealVector
a3 ((FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector)
-> (FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \FunPtr FdmCallbackFun
a3' -> 
  (Int -> Double -> (Double, Double) -> RealVector -> RealVector)
-> (FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector
forall b.
(Int -> Double -> (Double, Double) -> RealVector -> RealVector)
-> (FunPtr FdmCallbackFun -> IO b) -> IO b
withFdmSolveSplitting Int -> Double -> (Double, Double) -> RealVector -> RealVector
a4 ((FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector)
-> (FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \FunPtr FdmCallbackFun
a4' -> 
  Maybe (Double -> RealVector -> RealVector)
-> (FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector
forall b.
Maybe (Double -> RealVector -> RealVector)
-> (FunPtr FdmCallbackFun -> IO b) -> IO b
withMaybeFdmStepCondition Maybe (Double -> RealVector -> RealVector)
a5 ((FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector)
-> (FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \FunPtr FdmCallbackFun
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) -> 
  FdmScheme -> (Ptr CFdmSchemeDesc -> IO RealVector) -> IO RealVector
forall a. FdmScheme -> (Ptr CFdmSchemeDesc -> IO a) -> IO a
withFdmSchemeDesc FdmScheme
a7 ((Ptr CFdmSchemeDesc -> IO RealVector) -> IO RealVector)
-> (Ptr CFdmSchemeDesc -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr CFdmSchemeDesc
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) -> 
  let {a9' :: CDouble
a9' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a9} in 
  let {a10' :: CDouble
a10' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
a10} in 
  let {a11' :: CUInt
a11' = Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a11} in 
  let {a12' :: CUInt
a12' = Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a12} in 
  ((Ptr CUInt, Ptr (Ptr CDouble)) -> IO RealVector) -> IO RealVector
forall a b. ((Ptr CUInt, Ptr (Ptr a)) -> IO b) -> IO b
preArray (((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
a13'1, Ptr (Ptr CDouble)
a13'2) -> 
  (Ptr (Ptr CChar) -> IO RealVector) -> IO RealVector
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO RealVector) -> IO RealVector)
-> (Ptr (Ptr CChar) -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a14' -> 
  CUInt
-> FunPtr FdmCallbackFun
-> FunPtr FdmCallbackFun
-> FunPtr FdmCallbackFun
-> FunPtr FdmCallbackFun
-> CUInt
-> Ptr CDouble
-> Ptr CFdmSchemeDesc
-> CUInt
-> Ptr CDouble
-> CDouble
-> CDouble
-> CUInt
-> CUInt
-> Ptr CUInt
-> Ptr (Ptr CDouble)
-> Ptr (Ptr CChar)
-> IO ()
fdmRollback'_ CUInt
a1' FunPtr FdmCallbackFun
a2' FunPtr FdmCallbackFun
a3' FunPtr FdmCallbackFun
a4' FunPtr FdmCallbackFun
a5' CUInt
a6'1  Ptr CDouble
a6'2 Ptr CFdmSchemeDesc
a7' CUInt
a8'1  Ptr CDouble
a8'2 CDouble
a9' CDouble
a10' CUInt
a11' CUInt
a12' Ptr CUInt
a13'1  Ptr (Ptr CDouble)
a13'2 Ptr (Ptr CChar)
a14' 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
a13'1  Ptr (Ptr CDouble)
a13'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
a13'' -> 
  Ptr (Ptr CChar) -> IO ()
errorCheck  Ptr (Ptr CChar)
a14'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
a13'')

{-# LINE 554 "./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 558 "./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 564 "./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 CChar) -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO Fdm1dMesher) -> IO Fdm1dMesher)
-> (Ptr (Ptr CChar) -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a7' -> 
  CDouble
-> CDouble
-> CUInt
-> CDouble
-> CDouble
-> CInt
-> Ptr (Ptr CChar)
-> IO (Ptr CFdm1dMesher)
concentrating1dMesher'_ CDouble
a1' CDouble
a2' CUInt
a3' CDouble
a4' CDouble
a5' CInt
a6' Ptr (Ptr CChar)
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 CChar) -> IO ()
errorCheck  Ptr (Ptr CChar)
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 575 "./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 CChar) -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO Fdm1dMesher) -> IO Fdm1dMesher)
-> (Ptr (Ptr CChar) -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a9' -> 
  CDouble
-> CDouble
-> CUInt
-> CUInt
-> Ptr CDouble
-> Ptr CDouble
-> Ptr CInt
-> CDouble
-> Ptr (Ptr CChar)
-> 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 CChar)
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 CChar) -> IO ()
errorCheck  Ptr (Ptr CChar)
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 593 "./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 602 "./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
 -> (GeneralizedBlackScholesProcess) -> (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 :: Word
-> GeneralizedBlackScholesProcess
-> Double
-> Double
-> Maybe Double
-> Maybe Double
-> Double
-> Double
-> Maybe Double
-> Maybe Double
-> [Dividend]
-> Maybe FdmQuantoHelper
-> Double
-> IO Fdm1dMesher
fdmBlackScholesMesher Word
a1 GeneralizedBlackScholesProcess
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 
  GeneralizedBlackScholesProcess
-> (Ptr CGeneralizedBlackScholesProcess' -> IO Fdm1dMesher)
-> IO Fdm1dMesher
forall gbs b.
GenGeneralizedBlackScholesProcess gbs
-> (Ptr CGeneralizedBlackScholesProcess' -> IO b) -> IO b
withGeneralizedBlackScholesProcess GeneralizedBlackScholesProcess
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 CChar) -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO Fdm1dMesher) -> IO Fdm1dMesher)
-> (Ptr (Ptr CChar) -> IO Fdm1dMesher) -> IO Fdm1dMesher
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a14' -> 
  CUInt
-> Ptr CGeneralizedBlackScholesProcess'
-> CDouble
-> CDouble
-> CDouble
-> CDouble
-> CDouble
-> CDouble
-> CDouble
-> CDouble
-> CUInt
-> Ptr (Ptr CDividend)
-> Ptr CFdmQuantoHelper
-> CDouble
-> Ptr (Ptr CChar)
-> 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 CChar)
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 CChar) -> IO ()
errorCheck  Ptr (Ptr CChar)
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 620 "./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 633 "./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 642 "./QuantLib/Method.chs" #-}


-- |'FdmSimpleProcess1dMesher(size, process, maturity, tAvgSteps, epsilon, mandatoryPoint)' --
-- generic mesher for any bound one-dimensional 'StochasticProcess1D'.
fdmSimpleProcess1dMesher :: (Word) -- ^size
 -> (StochasticProcess1D) -> (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 652 "./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 662 "./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 673 "./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 679 "./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 
  preArray $ \(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 687 "./QuantLib/Method.chs" #-}


-- Raw import, not a {#fun#}: 'withCustomFdmInnerValueCalculator' below needs the two
-- 'FunPtr's kept alive for as long as the returned 'FdmInnerValueCalculator' can be called into
-- (i.e. across the whole continuation, which typically includes a later 'fdmSolve' call), not
-- just for the duration of this one construction call the way a plain {#fun#}-generated
-- 'withFdmInnerValue' bracket would provide -- see the haddock below.
foreign import ccall "ql.h qlFdmInnerValueCalculatorFromFunctions"
  c_qlFdmInnerValueCalculatorFromFunctions :: Ptr CFdmMesher -> FunPtr FdmInnerValueFun -> FunPtr FdmInnerValueFun
    -> Ptr CString -> IO (Ptr CFdmInnerValueCalculator)

-- |Wraps a Haskell @t -> location -> value@ pair of @innerValue@\/@avgInnerValue@ functions as a
-- real 'FdmInnerValueCalculator' object, valid only inside the continuation -- the fully custom
-- counterpart to constructors built from QuantLib's own concrete subclasses (bound alongside
-- this, which need no such bracket: they hold no Haskell callback). 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 =
  FdmMesher -> (Ptr CFdmMesher -> IO b) -> IO b
forall b. FdmMesher -> (Ptr CFdmMesher -> IO b) -> IO b
withFdmMesher FdmMesher
mesher ((Ptr CFdmMesher -> IO b) -> IO b)
-> (Ptr CFdmMesher -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \Ptr CFdmMesher
mesher' ->
  (Double -> [Double] -> Double)
-> (FunPtr FdmInnerValueFun -> IO b) -> IO b
forall b.
(Double -> [Double] -> Double)
-> (FunPtr FdmInnerValueFun -> IO b) -> IO b
withFdmInnerValue Double -> [Double] -> Double
iv ((FunPtr FdmInnerValueFun -> IO b) -> IO b)
-> (FunPtr FdmInnerValueFun -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \FunPtr FdmInnerValueFun
ivFp ->
  (Double -> [Double] -> Double)
-> (FunPtr FdmInnerValueFun -> IO b) -> IO b
forall b.
(Double -> [Double] -> Double)
-> (FunPtr FdmInnerValueFun -> IO b) -> IO b
withFdmInnerValue Double -> [Double] -> Double
aiv ((FunPtr FdmInnerValueFun -> IO b) -> IO b)
-> (FunPtr FdmInnerValueFun -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \FunPtr FdmInnerValueFun
aivFp ->
  (Ptr (Ptr CChar) -> IO b) -> IO b
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO b) -> IO b)
-> (Ptr (Ptr CChar) -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
errPtr -> do
    res <- Ptr CFdmMesher
-> FunPtr FdmInnerValueFun
-> FunPtr FdmInnerValueFun
-> Ptr (Ptr CChar)
-> IO (Ptr CFdmInnerValueCalculator)
c_qlFdmInnerValueCalculatorFromFunctions Ptr CFdmMesher
mesher' FunPtr FdmInnerValueFun
ivFp FunPtr FdmInnerValueFun
aivFp Ptr (Ptr CChar)
errPtr
    errorCheck errPtr
    peekFdmInnerValueCalculator res >>= k

-- |'FdmZeroInnerValue' -- an 'FdmInnerValueCalculator' whose @innerValue@\/@avgInnerValue@ are
-- always 0.
fdmZeroInnerValue :: IO ((FdmInnerValueCalculator))
fdmZeroInnerValue :: IO FdmInnerValueCalculator
fdmZeroInnerValue =
  (Ptr (Ptr CChar) -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr (Ptr CChar) -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a1' -> 
  Ptr (Ptr CChar) -> IO (Ptr CFdmInnerValueCalculator)
fdmZeroInnerValue'_ Ptr (Ptr CChar)
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 CChar) -> IO ()
errorCheck  Ptr (Ptr CChar)
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 723 "./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 CChar) -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr (Ptr CChar) -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a4' -> 
  QlPayoff
-> Ptr CFdmMesher
-> CUInt
-> Ptr (Ptr CChar)
-> IO (Ptr CFdmInnerValueCalculator)
fdmCellAveragingInnerValue'_ QlPayoff
a1' Ptr CFdmMesher
a2' CUInt
a3' Ptr (Ptr CChar)
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 CChar) -> IO ()
errorCheck  Ptr (Ptr CChar)
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 734 "./QuantLib/Method.chs" #-}


-- Raw import, not a {#fun#}: same FunPtr-lifetime hazard as
-- 'c_qlFdmInnerValueCalculatorFromFunctions' above -- 'gridMapping' is stored inside the C++
-- object and invoked again on every later 'innerValue'\/'avgInnerValue' call, not just during
-- construction.
foreign import ccall "ql.h qlFdmCellAveragingInnerValueMapped"
  c_qlFdmCellAveragingInnerValueMapped :: QlPayoff -> Ptr CFdmMesher -> CUInt -> FunPtr FdmGridMappingFun
    -> Ptr CString -> IO (Ptr CFdmInnerValueCalculator)

-- |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
-- resulting 'FdmInnerValueCalculator' is only valid inside this continuation.
withCustomCellAveragingInnerValue :: Payoff -> FdmMesher -> Int -> (Double -> Double)
  -> (FdmInnerValueCalculator -> IO b) -> IO b
withCustomCellAveragingInnerValue :: forall b.
Payoff
-> FdmMesher
-> Int
-> (Double -> Double)
-> (FdmInnerValueCalculator -> IO b)
-> IO b
withCustomCellAveragingInnerValue Payoff
payoff FdmMesher
mesher Int
direction Double -> Double
mapping FdmInnerValueCalculator -> IO b
k =
  Payoff -> (QlPayoff -> IO b) -> IO b
forall a. Payoff -> (QlPayoff -> IO a) -> IO a
withPayoff Payoff
payoff ((QlPayoff -> IO b) -> IO b) -> (QlPayoff -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \QlPayoff
payoff' ->
  FdmMesher -> (Ptr CFdmMesher -> IO b) -> IO b
forall b. FdmMesher -> (Ptr CFdmMesher -> IO b) -> IO b
withFdmMesher FdmMesher
mesher ((Ptr CFdmMesher -> IO b) -> IO b)
-> (Ptr CFdmMesher -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \Ptr CFdmMesher
mesher' ->
  (Double -> Double) -> (FunPtr FdmGridMappingFun -> IO b) -> IO b
forall b.
(Double -> Double) -> (FunPtr FdmGridMappingFun -> IO b) -> IO b
withFdmGridMapping Double -> Double
mapping ((FunPtr FdmGridMappingFun -> IO b) -> IO b)
-> (FunPtr FdmGridMappingFun -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \FunPtr FdmGridMappingFun
mappingFp ->
  (Ptr (Ptr CChar) -> IO b) -> IO b
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO b) -> IO b)
-> (Ptr (Ptr CChar) -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
errPtr -> do
    res <- QlPayoff
-> Ptr CFdmMesher
-> CUInt
-> FunPtr FdmGridMappingFun
-> Ptr (Ptr CChar)
-> IO (Ptr CFdmInnerValueCalculator)
c_qlFdmCellAveragingInnerValueMapped QlPayoff
payoff' Ptr CFdmMesher
mesher' (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
direction) FunPtr FdmGridMappingFun
mappingFp Ptr (Ptr CChar)
errPtr
    errorCheck errPtr
    peekFdmInnerValueCalculator res >>= 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 CChar) -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr (Ptr CChar) -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a4' -> 
  QlPayoff
-> Ptr CFdmMesher
-> CUInt
-> Ptr (Ptr CChar)
-> IO (Ptr CFdmInnerValueCalculator)
fdmLogInnerValue'_ QlPayoff
a1' Ptr CFdmMesher
a2' CUInt
a3' Ptr (Ptr CChar)
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 CChar) -> IO ()
errorCheck  Ptr (Ptr CChar)
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 766 "./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 773 "./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 
  (Ptr (Ptr CChar) -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr (Ptr CChar) -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a9' -> 
  Ptr CG2'
-> Ptr CG2'
-> Ptr CFixedVsFloatingSwap'
-> CUInt
-> Ptr CDouble
-> Ptr CInt
-> Ptr CFdmMesher
-> CUInt
-> Ptr (Ptr CChar)
-> IO (Ptr CFdmInnerValueCalculator)
qlFdmAffineG2ModelSwapInnerValue'_ Ptr CG2'
a1' Ptr CG2'
a2' Ptr CFixedVsFloatingSwap'
a3' CUInt
a4' Ptr CDouble
a5' Ptr CInt
a6' Ptr CFdmMesher
a7' CUInt
a8' Ptr (Ptr CChar)
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 CChar) -> IO ()
errorCheck  Ptr (Ptr CChar)
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 792 "./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 CChar) -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO FdmInnerValueCalculator)
 -> IO FdmInnerValueCalculator)
-> (Ptr (Ptr CChar) -> IO FdmInnerValueCalculator)
-> IO FdmInnerValueCalculator
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a9' -> 
  Ptr CHullWhite'
-> Ptr CHullWhite'
-> Ptr CFixedVsFloatingSwap'
-> CUInt
-> Ptr CDouble
-> Ptr CInt
-> Ptr CFdmMesher
-> CUInt
-> Ptr (Ptr CChar)
-> 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 CChar)
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 CChar) -> IO ()
errorCheck  Ptr (Ptr CChar)
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 808 "./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 818 "./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 825 "./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)
-> (FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector
forall b.
((Double, Double) -> RealVector -> RealVector)
-> (FunPtr FdmCallbackFun -> IO b) -> IO b
withFdmApply (Double, Double) -> RealVector -> RealVector
a4 ((FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector)
-> (FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \FunPtr FdmCallbackFun
a4' -> 
  (Int -> (Double, Double) -> RealVector -> RealVector)
-> (FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector
forall b.
(Int -> (Double, Double) -> RealVector -> RealVector)
-> (FunPtr FdmCallbackFun -> IO b) -> IO b
withFdmApplyDirection Int -> (Double, Double) -> RealVector -> RealVector
a5 ((FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector)
-> (FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \FunPtr FdmCallbackFun
a5' -> 
  (Int -> Double -> (Double, Double) -> RealVector -> RealVector)
-> (FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector
forall b.
(Int -> Double -> (Double, Double) -> RealVector -> RealVector)
-> (FunPtr FdmCallbackFun -> IO b) -> IO b
withFdmSolveSplitting Int -> Double -> (Double, Double) -> RealVector -> RealVector
a6 ((FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector)
-> (FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \FunPtr FdmCallbackFun
a6' -> 
  Maybe (Double -> RealVector -> RealVector)
-> (FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector
forall b.
Maybe (Double -> RealVector -> RealVector)
-> (FunPtr FdmCallbackFun -> IO b) -> IO b
withMaybeFdmStepCondition Maybe (Double -> RealVector -> RealVector)
a7 ((FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector)
-> (FunPtr FdmCallbackFun -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \FunPtr FdmCallbackFun
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 a b. ((Ptr CUInt, Ptr (Ptr a)) -> IO b) -> IO b
preArray (((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 CChar) -> IO RealVector) -> IO RealVector
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO RealVector) -> IO RealVector)
-> (Ptr (Ptr CChar) -> IO RealVector) -> IO RealVector
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a15' -> 
  Ptr CFdmMesher
-> Ptr CFdmInnerValueCalculator
-> CUInt
-> FunPtr FdmCallbackFun
-> FunPtr FdmCallbackFun
-> FunPtr FdmCallbackFun
-> FunPtr FdmCallbackFun
-> CUInt
-> Ptr CDouble
-> Ptr CFdmSchemeDesc
-> CDouble
-> CDouble
-> CUInt
-> CUInt
-> Ptr CUInt
-> Ptr (Ptr CDouble)
-> Ptr (Ptr CChar)
-> IO ()
fdmSolve'_ Ptr CFdmMesher
a1' Ptr CFdmInnerValueCalculator
a2' CUInt
a3' FunPtr FdmCallbackFun
a4' FunPtr FdmCallbackFun
a5' FunPtr FdmCallbackFun
a6' FunPtr FdmCallbackFun
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 CChar)
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 CChar) -> IO ()
errorCheck  Ptr (Ptr CChar)
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 851 "./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 C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CPathGenerator))))))))))

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

foreign import ccall safe "QuantLib/Method.chs.h qlSobolGaussianRsg"
  sobolGaussianRsg'_ :: (C2HSImp.CInt -> (C2HSImp.CUInt -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (IO ()))))))

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

foreign import ccall safe "QuantLib/Method.chs.h qlPathGeneratorAntithetic"
  antithetic'_ :: ((C2HSImp.Ptr (CPathGenerator)) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (IO ()))))))))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmRollback"
  fdmRollback'_ :: (C2HSImp.CUInt -> ((C2HSImp.FunPtr ((C2HSImp.Ptr ()) -> (IO ()))) -> ((C2HSImp.FunPtr ((C2HSImp.Ptr ()) -> (IO ()))) -> ((C2HSImp.FunPtr ((C2HSImp.Ptr ()) -> (IO ()))) -> ((C2HSImp.FunPtr ((C2HSImp.Ptr ()) -> (IO ()))) -> (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 C2HSImp.CChar)) -> (IO ()))))))))))))))))))

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

foreign import ccall safe "QuantLib/Method.chs.h qlUniform1dMesher"
  uniform1dMesher'_ :: (C2HSImp.CDouble -> (C2HSImp.CDouble -> (C2HSImp.CUInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (IO (C2HSImp.Ptr (CFdm1dMesher))))))))))))

foreign import ccall safe "QuantLib/Method.chs.h qlGluedMesher"
  gluedMesher'_ :: ((C2HSImp.Ptr (CFdm1dMesher)) -> ((C2HSImp.Ptr (CFdm1dMesher)) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (IO ()))))))

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

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

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

foreign import ccall safe "QuantLib/Method.chs.h qlFdmLogBasketInnerValue"
  fdmLogBasketInnerValue'_ :: ((QlBasketPayoff) -> ((C2HSImp.Ptr (CFdmMesher)) -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (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 C2HSImp.CChar)) -> (IO C2HSImp.CDouble)))))))

foreign import ccall safe "QuantLib/Method.chs.h qlFdmSolve"
  fdmSolve'_ :: ((C2HSImp.Ptr (CFdmMesher)) -> ((C2HSImp.Ptr (CFdmInnerValueCalculator)) -> (C2HSImp.CUInt -> ((C2HSImp.FunPtr ((C2HSImp.Ptr ()) -> (IO ()))) -> ((C2HSImp.FunPtr ((C2HSImp.Ptr ()) -> (IO ()))) -> ((C2HSImp.FunPtr ((C2HSImp.Ptr ()) -> (IO ()))) -> ((C2HSImp.FunPtr ((C2HSImp.Ptr ()) -> (IO ()))) -> (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 C2HSImp.CChar)) -> (IO ()))))))))))))))))))