3
$\begingroup$

I have some trouble with the following code. Some jump and a decentered path are present but it's not the case, normally for Black Scholes diffusion!

Is anyone see a problem in my code ?

import numpy as np
import matplotlib.pyplot as plt

mu  = 0
sig = 0.5

def generate(S0, T, nt, sig, mu):
    nt = int(nt)
    T = float(T)
    dt  = T / nt

    St  = [S0] * nt

    t   = linspace(0,T,nt)
    dWt = np.random.normal(0, 1, nt)
    dWt[0] = 0.
    Wt  = dWt.cumsum()

    return S0 * np.exp(sig * sqrt(float(dt)) * Wt + (mu - sig**2/2.) * t)

    for i in range(100):
    plt.plot(generate(180., 2., 252*2, sig, mu))

enter image description here

$\endgroup$
5
  • $\begingroup$ At a minimum, self is used for class methods in python. $\endgroup$
    – John
    Apr 14, 2014 at 22:37
  • $\begingroup$ @John: Yes, but this not change anything about the algorithm of the code ? $\endgroup$
    – Alexis G
    Apr 14, 2014 at 22:39
  • $\begingroup$ I just meant that if someone on this site tried to run the code themselves to figure out what's wrong with it, they would have problems because they couldn't get self.sig. So perhaps re-write it as a function and provide sufficient code to re-produce the chart (and make it clear what the problem is). Also, people who write python typically don't use int and float the way you're using them. Python's dynamically typed for a reason. $\endgroup$
    – John
    Apr 14, 2014 at 23:00
  • $\begingroup$ Modeling is good but must be seen in log plot since EDS works on return. Brownian part of BS is $B_t~\sigma~dW_t$ and not only $\sigma~dW_t$ like for OU process. !enter image description here $\endgroup$
    – Alexis G
    Apr 14, 2014 at 23:56
  • $\begingroup$ Did you fix your issue? $\endgroup$ Jul 5, 2017 at 14:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.