Esempio n. 1
0
 public FittedMidpointPredictorCorrectorFdm(ISde stochasticEquation, int numSubdivisions, double a, double b)
     : base(stochasticEquation, numSubdivisions)
 {
     A = a;
     B = b;
     Console.WriteLine("Fitted midpoint Adjusted PC");
 }
Esempio n. 2
0
 public ModifiedPredictorCorrectorFdm(ISde stochasticEquation, int numSubdivisions, double a, double b)
     : base(stochasticEquation, numSubdivisions)
 {
     A = a;
     B = b;
     Console.WriteLine("Modified PC");
 }
Esempio n. 3
0
 public ExactFdm(ISde stochasticEquation, int numSubdivisions,
                 double S0, double vol, double drift) : base(stochasticEquation, numSubdivisions)
 {
     this.S0 = S0;
     sig     = vol;
     mu      = drift;
 }
Esempio n. 4
0
    public KarhunenLoeve(ISde <double> stochasticEquation, int numSubdivisions, int nTruncated, IRng <double> randomGen)
        : base(stochasticEquation, numSubdivisions)
    {
        N   = nTruncated;
        rng = randomGen;

        tmp = Math.Sqrt(2.0 * sde.Expiry);
    }
Esempio n. 5
0
    public Tuple <ISde <double>, FdmBase <double>, IRng <double> > Parts()
    { // V2, parts initialised from the inside
        // Get the SDE
        ISde <double>    sde = GetSde();
        IRng <double>    rng = GetRng();
        FdmBase <double> fdm = GetFdm(sde);

        return(new Tuple <ISde <double>, FdmBase <double>, IRng <double> >(sde, fdm, rng));
    }
    public event EndOfSimulation <double> finish;    // Signals that all paths are complete

    public MCMediator(Tuple <ISde, FdmBase, IRng> parts, int numberSimulations)
    {
        sde = parts.Item1;
        fdm = parts.Item2;
        rng = parts.Item3;

        NSim = numberSimulations;
        res  = new double[fdm.NT];
    }
    private FdmBase GetFdm(ISde sde)
    {
        int NT = 500;

        Console.Write("How many NT? ");
        NT = Convert.ToInt32(Console.ReadLine());

        return(new EulerFdm(sde, NT));
    }
    public Tuple <ISde, FdmBase, IRng> Parts()
    { // V2, parts initialised from the inside
        // Get the SDE
        ISde    sde = GetSde();
        IRng    rng = GetRng();
        FdmBase fdm = GetFdm(sde);

        return(new Tuple <ISde, FdmBase, IRng>(sde, fdm, rng));
    }
Esempio n. 9
0
    public Tuple <ISde, FdmBase, IRng> Parts()
    { // V2, parts initialised from the inside
        // Get the SDE
        ISde    sde = GetSde();
        IRng    rng = GetRng();
        FdmBase fdm = GetFdm(sde);

        Payoff payoff = x => Math.Max(0.0, K - x);
        //Payoff payoff = x => Math.Max(0.0, x - K);
        Func <double> discounter = () => Math.Exp(-r * T);
        IPricer       pricer     = GetPricer(payoff, discounter);

        return(new Tuple <ISde, FdmBase, IRng>(sde, fdm, rng));
    }
Esempio n. 10
0
    public FdmBase(ISde stochasticEquation, int numSubdivisions)
    {
        sde    = stochasticEquation;
        NT     = numSubdivisions;
        k      = sde.Expiry / (double)NT;
        dtSqrt = Math.Sqrt(k);
        x      = new double[NT + 1];

        // Create the mesh array
        x[0] = 0.0;
        for (int n = 1; n < x.Length; n++)
        {
            x[n] = x[n - 1] + k;
        }
    }
Esempio n. 11
0
    public dynamic k;      // Mesh size

    public FdmBase(ISde <T> stochasticEquation, int numSubdivisions)
    {
        sde = stochasticEquation;
        NT  = numSubdivisions;
        k   = (dynamic)sde.Expiry / (dynamic)NT;
        //       Console.WriteLine("{0},{1},{2} k", k, sde.Expiry, NT);
        x = new T[NT + 1];

        // Create the mesh array
        x[0] = (dynamic)0.0;
        for (int n = 1; n < x.Length; n++)
        {
            x[n] = x[n - 1] + k;
        }
        for (int j = 0; j < x.Length; j++)
        {
            //  Console.Write("{0}, ", x[j]);
        }
        //      string s = Console.ReadLine();
    }
Esempio n. 12
0
    public MCMediator(Tuple <ISde, FdmBase, IRng> parts, PathEvent <double> optionPaths,
                      EndOfSimulation <double> finishOptions, int numberSimulations)
    {
        sde = parts.Item1;
        fdm = parts.Item2;
        rng = parts.Item3;

        // Define slots for path information
        path = optionPaths;
        // Signal end of simulation
        finish = finishOptions;

        NSim = numberSimulations;
        res  = new double[fdm.NT + 1];

        mis = i => { if ((i / 10000) * 10000 == i)
                     {
                         Console.WriteLine("Iteration # {0}", i);
                     }
        };
    }
Esempio n. 13
0
 public MilsteinFdm(ISde <T> stochasticEquation, int numSubdivisions) : base(stochasticEquation, numSubdivisions)
 {
 }
Esempio n. 14
0
{ //
    public Platen_01_Explicit(ISde stochasticEquation, int numSubdivisions)
        : base(stochasticEquation, numSubdivisions)
    {
        Console.WriteLine("Platen 1.0");
    }
Esempio n. 15
0
 public MidpointPredictorCorrectorFdm(ISde <T> stochasticEquation, int numSubdivisions, T a, T b)
     : base(stochasticEquation, numSubdivisions)
 {
     A = a;
     B = b;
 }
Esempio n. 16
0
 public ExtrapolatedEulerFdm(ISde <T> stochasticEquation, int numSubdivisions) : base(stochasticEquation, numSubdivisions)
 {
 }
Esempio n. 17
0
{ // Npt consistent with Ito calculus
    public Heun(ISde <double> stochasticEquation, int numSubdivisions)
        : base(stochasticEquation, numSubdivisions)
    {
    }
Esempio n. 18
0
    private FdmBase GetFdm(ISde sde)
    {
        Console.WriteLine("Create FDM");
        Console.WriteLine("1. Euler, 2. Extrapolated Euler, 3. Milstein, 4. Predictor-Corrector (PC),");
        Console.WriteLine("5. PC adjusted, 6. PC midpoint, 7. Exact, 8. Discrete Milstein,");
        Console.WriteLine("9. Karhunen Loeve, 10. Platen 1.0 strong scheme, 11. Heun");
        Console.WriteLine("12. Derivative Free, 13. FRKI (Runge Kutta), 14. Heun2: ");
        int c = Convert.ToInt32(Console.ReadLine());

        FdmBase fdm;

        int NT = 500;

        Console.Write("How many NT? ");
        NT = Convert.ToInt32(Console.ReadLine());

        double a, b;

        switch (c)
        {
        case 1:

            fdm = new EulerFdm(sde, NT);
            break;

        case 2:

            fdm = new ExtrapolatedEulerFdm(sde, NT);
            break;

        case 3:

            fdm = new MilsteinFdm(sde, NT);
            break;

        case 4:
            a   = 0.5;
            b   = 0.5;
            fdm = new PredictorCorrectorFdm(sde, NT, a, b);
            break;

        case 5:
            a   = 0.5;
            b   = 0.5;
            fdm = new ModifiedPredictorCorrectorFdm(sde, NT, a, b);
            break;

        case 6:
            a   = 0.5;
            b   = 0.5;
            fdm = new MidpointPredictorCorrectorFdm(sde, NT, a, b);
            break;

        case 7:
            fdm = new ExactFdm(sde, NT);
            break;

        case 8:
            fdm = new DiscreteMilsteinFdm(sde, NT);
            break;

        case 9:
            int N = 100;     // Series truncation value
            // IRng rng = new PolarMarsagliaSitmo();

            //     fdm = new KarhunenLoeve(sde, NT, N, rng);
            fdm = new Platen_01_Explicit(sde, NT);
            break;

        case 10:
            fdm = new Platen_01_Explicit(sde, NT);
            break;

        case 11:
            fdm = new Heun(sde, NT);
            break;

        case 12:
            fdm = new DerivativeFree(sde, NT);
            break;

        case 13:
            fdm = new FRKI(sde, NT);
            break;

        case 14:
            fdm = new Heun2(sde, NT);
            break;

        default:
            fdm = new ExtrapolatedEulerFdm(sde, NT);
            break;
        }

        return(fdm);
    }
Esempio n. 19
0
 public ExactFdm(ISde <T> stochasticEquation, int numSubdivisions) : base(stochasticEquation, numSubdivisions)
 {
 }
Esempio n. 20
0
    private FdmBase GetFdm(ISde sde)
    {
        Console.WriteLine("Create FDM");
        Console.WriteLine("1. Euler, 2. Extrapolated Euler, 3. Milstein, 4. Predictor-Corrector (PC),");
        Console.WriteLine("5. PC adjusted, 6. PC midpoint, 7. Exact, 8. Discrete Milstein,");
        Console.WriteLine("9. Platen 1.0 strong scheme, 10. Platen 1.0 strong scheme, 11. Heun");
        Console.WriteLine("12. Derivative Free, 13. FRKI (Runge Kutta), 14. Heun2, 15. Fitted PC: ");
        int c = Convert.ToInt32(Console.ReadLine());

        FdmBase fdm;

        int NT;

        Console.Write("How many NT? ");
        NT = Convert.ToInt32(Console.ReadLine());

        double a, b;

        switch (c)
        {
        case 1:

            fdm = new EulerFdm(sde, NT);
            break;

        case 2:

            fdm = null;    // new ExtrapolatedEulerFdm(sde, NT);
            break;

        case 3:

            fdm = new MilsteinFdm(sde, NT);
            break;

        case 4:
            a   = 0.5;
            b   = 0.5;
            fdm = new PredictorCorrectorFdm(sde, NT, a, b);
            break;

        case 5:
            a   = 0.5;
            b   = 0.5;
            fdm = new ModifiedPredictorCorrectorFdm(sde, NT, a, b);
            break;

        case 6:
            a   = 0.5;
            b   = 0.5;
            fdm = new MidpointPredictorCorrectorFdm(sde, NT, a, b);
            break;

        case 7:
            fdm = new ExactFdm(sde, NT, IC, v, r);
            break;

        case 8:
            fdm = new DiscreteMilsteinFdm(sde, NT);
            break;

        case 9:

            fdm = new Platen_01_Explicit(sde, NT);
            break;

        case 10:
            fdm = new Platen_01_Explicit(sde, NT);
            break;

        case 11:
            fdm = new Heun(sde, NT);
            break;

        case 12:
            fdm = new DerivativeFree(sde, NT);
            break;

        case 13:
            fdm = new FRKI(sde, NT);
            break;

        case 14:
            fdm = new Heun2(sde, NT);
            break;

        case 15:
            a   = 0.5;
            b   = 0.5;
            fdm = new FittedMidpointPredictorCorrectorFdm(sde, NT, a, b);
            break;

        default:
            fdm = null;    // new ExtrapolatedEulerFdm(sde, NT);
            break;
        }

        return(fdm);
    }
Esempio n. 21
0
 public EulerFdm(ISde stochasticEquation, int numSubdivisions) : base(stochasticEquation, numSubdivisions)
 {
 }
Esempio n. 22
0
 public DiscreteMilsteinFdm(ISde stochasticEquation, int numSubdivisions) : base(stochasticEquation, numSubdivisions)
 {
 }
Esempio n. 23
0
 // Code ported from C++
 public Heun2(ISde stochasticEquation, int numSubdivisions) : base(stochasticEquation, numSubdivisions)
 {
 }
Esempio n. 24
0
 // Code ported from C++
 public DerivativeFree(ISde stochasticEquation, int numSubdivisions) : base(stochasticEquation, numSubdivisions)
 {
 }
Esempio n. 25
0
 public PredictorCorrectorFdm(ISde stochasticEquation, int numSubdivisions, double a, double b)
     : base(stochasticEquation, numSubdivisions)
 {
     A = a;
     B = b;
 }