Ejemplo n.º 1
0
    def test_simulate(self):

        daycounter = ActualActual()

        risk_free_ts = flat_rate(0.1, daycounter)
        dividend_ts = flat_rate(0.04, daycounter)

        s0 = s0 = SimpleQuote(100.0)
        v0 = 0.05
        kappa = 5.0
        theta = 0.05
        sigma = 1.0e-4
        rho = 0.0

        process = HestonProcess(risk_free_ts, dividend_ts, s0, v0, kappa, theta, sigma, rho)

        # simulate and plot Heston paths
        nbPaths = 4
        nbSteps = 100
        horizon = 1
        seed = 12345
        res = simulate(process, nbPaths, nbSteps, horizon, seed)

        self.assertAlmostEqual(res[1, -1], 152.50, delta=0.1)
Ejemplo n.º 2
0
# <markdowncell>

# The simulation
# --------------
# 
# The *simulate* function is not part of Quantlib. It has been added to the pyQL interface (see folder quantlib/sim). This illustrates how to crerate extensions to Quantlib and expose them to python.

# <codecell>

import pylab as pl
from quantlib.sim.simulate import simulate

# simulate and plot Heston paths
paths = 20
steps = 100
horizon = 2
seed = 12345

res = simulate(process, paths, steps, horizon, seed)

time = res[0,:]
simulations = res[1:, :].T
pl.plot(time, simulations)
pl.xlabel('Time')
pl.ylabel('Stock Price')
pl.title('Heston Process Simulation')
show()


Ejemplo n.º 3
0
# <markdowncell>

# The simulation
# --------------
#
# The *simulate* function is not part of Quantlib. It has been added
# to the pyQL interface (see folder quantlib/sim). This illustrates
# how to create extensions to Quantlib and expose them to python.

# <codecell>

import pylab as pl
from quantlib.sim.simulate import simulate

# simulate and plot Heston paths
paths = 20
steps = 100
horizon = 2
seed = 12345

res = simulate(process, paths, steps, horizon, seed)

time = res[0, :]
simulations = res[1:, :].T
pl.plot(time, simulations)
pl.xlabel('Time')
pl.ylabel('Stock Price')
pl.title('Heston Process Simulation')
pl.show()