Bond() public method

Calculates the value of a Bond under the Pelsser model.
public Bond ( IReadOnlyMatrixSlice dynamic, double dates, int i, double t, double s ) : double
dynamic IReadOnlyMatrixSlice /// The simulated process. ///
dates double /// The vector of reference dates. ///
i int /// The index at which the state variables must be sampled. ///
t double /// The date in years/fractions at at which the state variables must be sampled. ///
s double /// The maturity of the bond. ///
return double
Esempio n. 1
0
        public void Test()
        {
            Engine.MultiThread = true;

            Document doc = new Document();
            ProjectROV rov = new ProjectROV(doc);
            doc.Part.Add(rov);

            AFunction zerorate = new AFunction(rov);
            zerorate.VarName = "zr";
            zerorate.m_IndependentVariables = 1;
            zerorate.m_Value = (RightValue)0.05;

            rov.Symbols.Add(zerorate);

            int n_sim = 5000;
            int n_steps = 900;
            SquaredGaussianModel process = new SquaredGaussianModel();
            process.a1 = (ModelParameter)0.1;
            process.sigma1 = (ModelParameter)0.01;
            process.zr = (ModelParameter)"@zr";

            StochasticProcessExtendible s = new StochasticProcessExtendible(rov, process);
            rov.Processes.AddProcess(s);

            // Set the discounting.
            RiskFreeInfo rfi = rov.GetDiscountingModel() as RiskFreeInfo;
            rfi.ActualizationType = EActualizationType.RiskFree;
            rfi.m_deterministicRF = 0.0;

            OptionTree op = new OptionTree(rov);
            op.PayoffInfo.PayoffExpression = "bond(t;10;@v1)";

            // Set the simulation maturity.
            op.PayoffInfo.Timing.EndingTime.m_Value = (RightValue)2.0;
            op.PayoffInfo.European = true;
            rov.Map.Root = op;

            rov.NMethods.Technology = ETechType.T_SIMULATION;
            rov.NMethods.PathsNumber = n_sim;
            rov.NMethods.SimulationSteps = n_steps;

            ROVSolver solver = new ROVSolver();
            solver.BindToProject(rov);
            solver.DoValuation(-1);

            if (rov.HasErrors)
            {
                Console.WriteLine(rov.m_RuntimeErrorList[0]);
            }

            Assert.IsFalse(rov.HasErrors);

            ResultItem price = rov.m_ResultList[0] as ResultItem;
            Console.WriteLine("Bond Test Value = " + price.value.ToString());

            Assert.LessOrEqual(Math.Abs(0.6702 - price.value), .01);

            // Try to do some simple tests and check the results.
            double b0_10 = process.Bond(DynamicParam(0, process), process.CacheDates, 0, 0, 10);
            Console.WriteLine("Bond(0,10) = " + b0_10);

            Assert.LessOrEqual(Math.Abs(b0_10 - 0.606513), .001);

            double b7_10 = process.Bond(DynamicParam(0.00427631, process), process.CacheDates, 0, 7, 10);
            Console.WriteLine("Bond(7,10) = " + b7_10);

            Assert.LessOrEqual(Math.Abs(b7_10 - 0.856374), .001);

            double b7_30 = process.Bond(DynamicParam(0.00427631, process), process.CacheDates, 0, 7, 30);
        }
Esempio n. 2
0
        public void Test()
        {
            Engine.MultiThread = true;

            Document   doc = new Document();
            ProjectROV rov = new ProjectROV(doc);

            doc.Part.Add(rov);

            AFunction zerorate = new AFunction(rov);

            zerorate.VarName = "zr";
            zerorate.m_IndependentVariables = 1;
            zerorate.m_Value = (RightValue)0.05;

            rov.Symbols.Add(zerorate);

            int n_sim   = 5000;
            int n_steps = 900;
            SquaredGaussianModel process = new SquaredGaussianModel();

            process.a1     = (ModelParameter)0.1;
            process.sigma1 = (ModelParameter)0.01;
            process.zr     = (ModelParameter)"@zr";

            StochasticProcessExtendible s = new StochasticProcessExtendible(rov, process);

            rov.Processes.AddProcess(s);

            // Set the discounting.
            RiskFreeInfo rfi = rov.GetDiscountingModel() as RiskFreeInfo;

            rfi.ActualizationType = EActualizationType.RiskFree;
            rfi.m_deterministicRF = 0.0;

            OptionTree op = new OptionTree(rov);

            op.PayoffInfo.PayoffExpression = "bond(t;10;@v1)";

            // Set the simulation maturity.
            op.PayoffInfo.Timing.EndingTime.m_Value = (RightValue)2.0;
            op.PayoffInfo.European = true;
            rov.Map.Root           = op;

            rov.NMethods.Technology      = ETechType.T_SIMULATION;
            rov.NMethods.PathsNumber     = n_sim;
            rov.NMethods.SimulationSteps = n_steps;

            ROVSolver solver = new ROVSolver();

            solver.BindToProject(rov);
            solver.DoValuation(-1);

            if (rov.HasErrors)
            {
                Console.WriteLine(rov.m_RuntimeErrorList[0]);
            }

            Assert.IsFalse(rov.HasErrors);

            ResultItem price = rov.m_ResultList[0] as ResultItem;

            Console.WriteLine("Bond Test Value = " + price.value.ToString());

            Assert.LessOrEqual(Math.Abs(0.6702 - price.value), .01);

            // Try to do some simple tests and check the results.
            double b0_10 = process.Bond(DynamicParam(0, process), process.CacheDates, 0, 0, 10);

            Console.WriteLine("Bond(0,10) = " + b0_10);

            Assert.LessOrEqual(Math.Abs(b0_10 - 0.606513), .001);

            double b7_10 = process.Bond(DynamicParam(0.00427631, process), process.CacheDates, 0, 7, 10);

            Console.WriteLine("Bond(7,10) = " + b7_10);

            Assert.LessOrEqual(Math.Abs(b7_10 - 0.856374), .001);

            double b7_30 = process.Bond(DynamicParam(0.00427631, process), process.CacheDates, 0, 7, 30);
        }