Example #1
0
 public BrownianBridgePricer(Payoff payoff, Func <double> discounter, GBM stochasticDE, double step) : base(payoff, discounter)
 {
     price = sum = sum2 = 0.0; NSim = 0;
     rand  = new Random();
     dt    = step;
     sde   = stochasticDE;
 }
Example #2
0
    public static void Main()
    {
        // Choose which builder to use
        int choice = 1;
        Builder <ISde <double>, FdmBase <double>, IRng <double> > factory = ChooseBuilder(choice);

        // Create the parts of the object network
        Tuple <ISde <double>, FdmBase <double>, IRng <double> > parts2 = factory();

        int NSim = 1000000;

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

        MCMediator <double> mcp = new MCMediator <double>(parts2, NSim);

        /*    double v = 0.2;
         *  double r = 0.05;
         *  double div = 0.0;
         *  double IC = 100.0;
         *  double T = 1.0;
         *  double K = 100.0;
         *  double beta = 1.0;// 2.0 / 3.0;*/

        double r    = 0.08;
        double v    = 0.3;
        double div  = 0.0;
        double IC   = 60.0;
        double T    = 0.25;
        double K    = 65.0;
        double beta = 1.0;

        /*      double r = 0.08;
         *    double v = 0.3;
         *    double div = 0.0;
         *    double IC = 60.0;
         *    double T = 0.25;
         *    double K = 65.0;
         *    double beta = 1.0;*/

        // Events
        Payoff <double> payoff = x => Math.Max(0.0, K - x);
        //  Payoff<double> payoff = x => Math.Max(0.0, x - K);
        //    Console.WriteLine(payoff(75.0));


        Func <double> discounter = () => Math.Exp(-r * T);

        IPricer <double> op  = new EuropeanPricer <double>(payoff, discounter);
        IPricer <double> op2 = new BarrierPricer <double>(payoff, discounter);

        GBM <double>     sde = new GBM <double>(r, v, div, IC, T);
        int              NT  = 400;
        IPricer <double> op3 = new BrownianBridgePricer <double>(payoff, discounter, sde, NT);
        IPricer <double> op4 = new AsianPricer <double>(payoff, discounter);

        // Define slots for path information
        mcp.path += op.ProcessPath;
        //  mcp.path += op2.ProcessPath;
        //   mcp.path += op3.ProcessPath;
        //   mcp.path += op4.ProcessPath;

        // Signal end of simulation
        mcp.finish += op.PostProcess;
        //     mcp.finish += op2.PostProcess;
        //    mcp.finish += op3.PostProcess;
        //    mcp.finish += op4.PostProcess;

        mcp.start();
    }