Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] DivList divList)
        {
            if (id != divList.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(divList);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DivListExists(divList.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(divList));
        }
Пример #2
0
        public void DivTest()
        {
            DivList myDiv = new DivList();

            myDiv.Divpoints = 3;
            myDiv.MakeArrays();
            myDiv.SetD(0, 1.0, 1.0);
            myDiv.SetD(1, 1.0, 2.0);
            myDiv.SetD(2, 1.0, 3.0);


            //test 1.5 year sum

            double sum   = 0.0;
            double testT = 1.5;

            for (int idx = 0; idx < myDiv.Divpoints; idx++)
            {
                if (myDiv.GetT(idx) < testT)
                {
                    sum += myDiv.GetD(idx);
                }
            }
            Assert.IsTrue(sum > 0.9999999);
            Assert.IsTrue(sum < 1.0000001);


            //test 2.5 year sum

            sum   = 0.0;
            testT = 2.5;
            for (int idx = 0; idx < myDiv.Divpoints; idx++)
            {
                if (myDiv.GetT(idx) < testT)
                {
                    sum += myDiv.GetD(idx);
                }
            }
            Assert.IsTrue(sum > 1.9999999);
            Assert.IsTrue(sum < 2.0000001);

            //test 3.5 year sum

            sum   = 0.0;
            testT = 3.5;
            for (int idx = 0; idx < myDiv.Divpoints; idx++)
            {
                if (myDiv.GetT(idx) < testT)
                {
                    sum += myDiv.GetD(idx);
                }
            }
            Assert.IsTrue(sum > 2.9999999);
            Assert.IsTrue(sum < 3.0000001);
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("Id,Name")] DivList divList)
        {
            if (ModelState.IsValid)
            {
                _context.Add(divList);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(divList));
        }
Пример #4
0
        public void ADivSlopingZero()
        {
            DivList mydiv = new DivList();

            mydiv.Divpoints = 1;
            mydiv.MakeArrays();
            mydiv.SetD(0, 5, 0.5);

            ZeroCurve myZero = new ZeroCurve();

            myZero.Ratepoints = 2;
            myZero.MakeArrays();
            myZero.SetR(0, 0.075, 0.5);
            myZero.SetR(1, 0.05, 2);

            //create the tree
            Tree myTree = new Tree();

            myTree.Gridsteps = 100;
            myTree.Tau       = 1.0;
            myTree.Sig       = 0.25;
            myTree.Spot      = 100.0;
            //myTree.flatFlag = false;
            myTree.MakeGrid(myZero, mydiv);

            //create pricer
            Pricer myPrice = new Pricer();

            myPrice.Strike    = 100;
            myPrice.Payoff    = "c";
            myPrice.Smoothing = "y";
            myPrice.Style     = "a";

            myPrice.MakeGrid(myTree);
            double prc = myPrice.Price();

            myPrice.Payoff = "p";
            myPrice.MakeGrid(myTree);
            double prp = myPrice.Price();

            Assert.IsTrue(prc > 10.37); //Orc pr = 10.38
            Assert.IsTrue(prc < 10.39);

            Assert.IsTrue(prp > 9.42); //Orc pr = 9.43
            Assert.IsTrue(prp < 9.44);
        }
Пример #5
0
        public void ANoDivFlatZero()
        {
            DivList mydiv = new DivList();

            mydiv.Divpoints = 1;
            mydiv.MakeArrays();
            mydiv.SetD(0, 0.0, 1.0);

            ZeroCurve myZero = new ZeroCurve();

            myZero.Ratepoints = 1;
            myZero.MakeArrays();
            myZero.SetR(0, 0.05, 1.0);

            //create the tree
            Tree myTree = new Tree();

            myTree.Gridsteps = 100;
            myTree.Tau       = 1.0;
            myTree.Sig       = 0.25;
            myTree.Spot      = 100.0;
            //myTree.flatFlag = false;
            myTree.MakeGrid(myZero, mydiv);

            //create pricer
            Pricer myPrice = new Pricer();

            myPrice.Strike    = 100;
            myPrice.Payoff    = "c";
            myPrice.Smoothing = "y";
            myPrice.Style     = "a";

            myPrice.MakeGrid(myTree);
            double prc = myPrice.Price();

            myPrice.Payoff = "p";
            myPrice.MakeGrid(myTree);
            double prp = myPrice.Price();

            Assert.IsTrue(prc > 12.33); //Orc pr = 12.34
            Assert.IsTrue(prc < 12.35);

            Assert.IsTrue(prp > 7.98); //Orc pr = 7.99
            Assert.IsTrue(prp < 8.00);
        }
Пример #6
0
        public void EDivFlatZero()
        {
            DivList mydiv = new DivList();

            mydiv.Divpoints = 1;
            mydiv.MakeArrays();
            mydiv.SetD(0, 5, 0.5);

            ZeroCurve myZero = new ZeroCurve();

            myZero.Ratepoints = 1;
            myZero.MakeArrays();
            myZero.SetR(0, 0.05, 1.0);

            //create the tree
            Tree myTree = new Tree();

            myTree.Gridsteps = 100;
            myTree.Tau       = 1.0;
            myTree.Sig       = 0.25;
            myTree.Spot      = 100.0;
            //myTree.flatFlag = false;
            myTree.MakeGrid(myZero, mydiv);

            //create pricer
            Pricer myPrice = new Pricer();

            myPrice.Strike    = 100;
            myPrice.Payoff    = "c";
            myPrice.Smoothing = "y";
            myPrice.Style     = "e";

            myPrice.MakeGrid(myTree);
            double prc = myPrice.Price();

            myPrice.Payoff = "p";
            myPrice.MakeGrid(myTree);
            double prp = myPrice.Price();

            Assert.IsTrue(prc > 9.455); //BS pr = 9.46277
            Assert.IsTrue(prc < 9.475);

            Assert.IsTrue(prp > 9.462); //BS pr = 9.46226
            Assert.IsTrue(prp < 9.475);
        }
        public void DivFlatZero()
        {
            DivList mydiv = new DivList();

            mydiv.divpoints = 1;
            mydiv.makeArrays();
            mydiv.set_d(0, 5, 0.5);

            ZeroCurve myZero = new ZeroCurve();

            myZero.ratepoints = 1;
            myZero.makeArrays();
            myZero.set_r(0, 0.05, 1.0);

            //create the tree
            DiscreteTree myTree = new DiscreteTree();

            myTree.Gridsteps = 100;
            myTree.tau       = 1.0;
            myTree.sig       = 0.25;
            myTree.Spot      = 100.0;
            //myTree.flatFlag = false;
            myTree.MakeGrid(myZero, mydiv);

            //create pricer
            Pricer myPrice = new Pricer();

            myPrice.Strike    = 100;
            myPrice.Payoff    = "c";
            myPrice.Smoothing = "y";
            myPrice.Style     = "e";

            myPrice.MakeGrid(myTree);
            double prc = myPrice.Price();

            myPrice.Payoff = "p";
            myPrice.MakeGrid(myTree);
            double prp = myPrice.Price();

            Assert.Greater(prc, 9.455); //BS pr = 9.46277
            Assert.Less(prc, 9.475);

            Assert.Greater(prp, 9.462); //BS pr = 9.46226
            Assert.Less(prp, 9.475);
        }