|
| 1 | +from cython.operator cimport dereference as deref |
| 2 | +from libcpp cimport bool |
| 3 | +from quantlib.stochastic_process cimport StochasticProcess |
| 4 | +from quantlib.time_grid cimport TimeGrid |
| 5 | +from quantlib.math.randomnumbers.rngtraits cimport PseudoRandom, LowDiscrepancy, FastPseudoRandom |
| 6 | +from ._sample cimport Sample |
| 7 | +from .multipath cimport MultiPath |
| 8 | +from . cimport _multipath as _mp |
| 9 | + |
| 10 | +cdef class PseudoRandomMultiPathGenerator: |
| 11 | + def __init__(self, StochasticProcess process, TimeGrid time_grid, PseudoRandom gen, bool brownian_bridge): |
| 12 | + self._thisptr = new _mpg.MultiPathGenerator[QlPseudoRandom.rsg_type](process._thisptr, time_grid._thisptr, deref(gen._thisptr), brownian_bridge) |
| 13 | + |
| 14 | + def __next__(self): |
| 15 | + cdef Sample[_mp.MultiPath]* r = <Sample[_mp.MultiPath]*>&self._thisptr.next() |
| 16 | + cdef MultiPath mp = MultiPath.__new__(MultiPath) |
| 17 | + mp._thisptr = new _mp.MultiPath(r.value) |
| 18 | + return (r.weight, mp) |
| 19 | + |
| 20 | + def __dealloc__(self): |
| 21 | + del self._thisptr |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +cdef class LowDiscrepancyMultiPathGenerator: |
| 26 | + def __init__(self, StochasticProcess process, TimeGrid time_grid, LowDiscrepancy gen, bool brownian_bridge): |
| 27 | + self._thisptr = new _mpg.MultiPathGenerator[QlLowDiscrepancy.rsg_type](process._thisptr, time_grid._thisptr, deref(gen._thisptr), brownian_bridge) |
| 28 | + |
| 29 | + def __next__(self): |
| 30 | + cdef Sample[_mp.MultiPath]* r = <Sample[_mp.MultiPath]*>&self._thisptr.next() |
| 31 | + cdef MultiPath mp = MultiPath.__new__(MultiPath) |
| 32 | + mp._thisptr = new _mp.MultiPath(r.value) |
| 33 | + return (r.weight, mp) |
| 34 | + |
| 35 | + def __dealloc__(self): |
| 36 | + del self._thisptr |
| 37 | + |
| 38 | + |
| 39 | +cdef class ZigguratMultiPathGenerator: |
| 40 | + def __init__(self, StochasticProcess process, TimeGrid time_grid, FastPseudoRandom gen, bool brownian_bridge): |
| 41 | + self._thisptr = new _mpg.MultiPathGenerator[ZigguratPseudoRandom](process._thisptr, time_grid._thisptr, deref(gen._thisptr), brownian_bridge) |
| 42 | + |
| 43 | + def __next__(self): |
| 44 | + cdef Sample[_mp.MultiPath]* r = <Sample[_mp.MultiPath]*>&self._thisptr.next() |
| 45 | + cdef MultiPath mp = MultiPath.__new__(MultiPath) |
| 46 | + mp._thisptr = new _mp.MultiPath(r.value) |
| 47 | + return (r.weight, mp) |
| 48 | + |
| 49 | + def __dealloc__(self): |
| 50 | + del self._thisptr |
0 commit comments