Example #1
0
        public void TestImpliedVol2()
        {
            var stock = TestDataHelper.GetStock("ANZ");

            Assert.AreEqual("ANZ", stock.Name);
            Stock         stockObject = TestHelper.CreateStock(stock);
            ForwardExpiry fwd         = new ForwardExpiry(DateTime.Parse("29-10-2009"), 3676);
            Strike        str         = new Strike(3650, null, null, Units.Cents);

            fwd.AddStrike(str, true);
            stockObject.VolatilitySurface.AddExpiry(fwd);
            foreach (ForwardExpiry fwdExp in stockObject.VolatilitySurface.Expiries)
            {
                foreach (Strike strike in fwdExp.Strikes)
                {
                    if (strike.StrikePrice == 3650 && (fwdExp.ExpiryDate == DateTime.Parse("29-10-2009")))
                    {
                        stockObject.Spot = 3676;
                        var vol0 = OptionHelper.GetImpliedVol(stockObject, fwdExp.ExpiryDate, strike.StrikePrice, true, "A", 224.5, 120);
                        AmOptionAnalytics call = new AmOptionAnalytics(stockObject.Date, fwdExp.ExpiryDate, Convert.ToDouble(stockObject.Spot), strike.StrikePrice, vol0, "A", "C", stockObject.RateCurve, stockObject.Dividends, 120);
                        Assert.AreEqual(call.Price(), 224.5, 0.01);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Loads the stock.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        private static IStock LoadStock(String name)
        {
            var stock = TestDataHelper.GetStock(name);

            Assert.AreEqual(name, stock.Name);
            Stock stockObject = TestHelper.CreateStock(stock);

            return(stockObject);
        }
Example #3
0
        public void TestHistoricalExtrapolate()
        {
            IStock             stockASXParent = LoadStock("AGK");
            IVolatilitySurface stockASXChild  = CreateNullVolSurface();
            IVolatilitySurface targetChild    = CreateNullVolSurface();
            IStock             stockSDParent  = LoadStock("AGK");

            stockASXParent.Valuations.Add(new Valuation(new DateTime(2008, 8, 28), 1208));
            stockASXParent.Valuations.Add(new Valuation(new DateTime(2008, 8, 29), 1221));
            stockASXParent.Valuations.Add(new Valuation(new DateTime(2008, 8, 30), 1218));
            stockASXParent.Valuations.Add(new Valuation(new DateTime(2008, 8, 31), 1207));
            stockASXParent.Valuations.Add(new Valuation(new DateTime(2008, 9, 1), 1250));
            RateCurve       rateCurve    = CreateRateCurve();
            List <Dividend> divCurve     = CreateDividends();
            IStock          nullASXChild = new Stock(new DateTime(2009, 9, 9), 200.0M, "ZZZ", "ZZZ", rateCurve, divCurve);

            nullASXChild.VolatilitySurface = stockASXChild;
            nullASXChild.Valuations.Add(new Valuation(new DateTime(2008, 12, 12), 208));
            nullASXChild.Valuations.Add(new Valuation(new DateTime(2008, 12, 13), 221));
            nullASXChild.Valuations.Add(new Valuation(new DateTime(2008, 12, 14), 218));
            nullASXChild.Valuations.Add(new Valuation(new DateTime(2008, 12, 15), 207));
            nullASXChild.Valuations.Add(new Valuation(new DateTime(2008, 12, 16), 201));
            ExtrapolationHelper extrap   = new ExtrapolationHelper();
            decimal             histvol1 = extrap.DoHistVolCalc(stockASXParent);
            decimal             histvol2 = extrap.DoHistVolCalc(nullASXChild);

            Assert.AreEqual(0.375846, Convert.ToDouble(histvol1), 0.0001);
            Assert.AreEqual(0.770018, Convert.ToDouble(histvol2), 0.0001);
            extrap.PopulateHistoricalVols(stockASXParent, nullASXChild, targetChild);
            double scalFactor = Convert.ToDouble(extrap.GetHistoricalScalFactor(stockASXParent, nullASXChild));

            Assert.AreEqual(scalFactor, 2.0487573, 0.0001);
            //Spreadsheet fit SD parent to (5d, 1.000 * F) point, flatline endpoints.
            decimal SDParentVol0 = 0.296175M;
            // Spreadsheet fit SD parent to (7d,0.867 * F) point
            decimal SDParentVol1 = 0.320240M;
            // Spreadsheet fit SD parent to (21d,1.00 * F) point
            decimal SDParentVol2    = 0.287656M;
            double  childExtrapVol0 = scalFactor * Convert.ToDouble(SDParentVol0);
            double  childExtrapVol1 = scalFactor * Convert.ToDouble(SDParentVol1);
            double  childExtrapVol2 = scalFactor * Convert.ToDouble(SDParentVol2);

            Assert.AreEqual(Convert.ToDouble(SDParentVol0 * histvol2 / histvol1), childExtrapVol0, 0.001);
            Assert.AreEqual(Convert.ToDouble(SDParentVol1 * histvol2 / histvol1), childExtrapVol1, 0.001);
            Assert.AreEqual(Convert.ToDouble(SDParentVol2 * histvol2 / histvol1), childExtrapVol2, 0.001);
        }
Example #4
0
        public void TestFitter()
        {
            var stock = TestDataHelper.GetStock("AGK");

            Assert.AreEqual("AGK", stock.Name);
            Stock stockObject = TestHelper.CreateStock(stock);

            stockObject.VolatilitySurface.Calibrate();
            decimal spot   = stockObject.Spot;
            var     fwdexp = ForwardExpiryHelper.FindExpiry(new DateTime(2016, 9, 9), stockObject.VolatilitySurface.NodalExpiries.ToList());
            int     i      = -1;
            var     str    = StrikeHelper.FindStrikeWithPrice(1404, new List <Strike>(fwdexp.Strikes), out i);

            Assert.AreNotEqual(i, -1);
            double fwd    = Math.Round(fwdexp.Strikes[i].InterpModel.WingParams.AtmForward, 7);
            double cc     = Math.Round(fwdexp.Strikes[i].InterpModel.WingParams.CallCurve, 7);
            double vc     = Math.Round(fwdexp.Strikes[i].InterpModel.WingParams.CurrentVol, 7);
            double dc     = Math.Round(fwdexp.Strikes[i].InterpModel.WingParams.DnCutoff, 7);
            double dsr    = Math.Round(fwdexp.Strikes[i].InterpModel.WingParams.Dsr, 7);
            double pc     = Math.Round(fwdexp.Strikes[i].InterpModel.WingParams.PutCurve, 7);
            double reffwd = Math.Round(fwdexp.Strikes[i].InterpModel.WingParams.RefFwd, 7);
            double refvol = Math.Round(fwdexp.Strikes[i].InterpModel.WingParams.RefVol, 7);
            double scr    = Math.Round(fwdexp.Strikes[i].InterpModel.WingParams.Scr, 7);
            double sr     = Math.Round(fwdexp.Strikes[i].InterpModel.WingParams.SlopeRef, 7);
            double ssr    = Math.Round(fwdexp.Strikes[i].InterpModel.WingParams.Ssr, 7);
            double uc     = Math.Round(fwdexp.Strikes[i].InterpModel.WingParams.UpCutoff, 7);
            double usr    = Math.Round(fwdexp.Strikes[i].InterpModel.WingParams.Usr, 7);
            double vcr    = Math.Round(fwdexp.Strikes[i].InterpModel.WingParams.Vcr, 7);

            Assert.AreNotEqual(spot, 0);
            Assert.AreEqual(fwd, 1682);
            Assert.AreEqual(cc, 0.0705147);
            Assert.AreEqual(vc, 0.2933592);
            Assert.AreEqual(dc, Math.Round(-0.5 - Math.Log(Convert.ToDouble(fwdexp.FwdPrice / spot))), 7);
            Assert.AreEqual(uc, Math.Round(0.5 - Math.Log(Convert.ToDouble(fwdexp.FwdPrice / spot))), 7);
            Assert.AreEqual(dsr, 0.20);
            Assert.AreEqual(pc, 0.0025281);
            Assert.AreEqual(reffwd, 1682);
            Assert.AreEqual(refvol, vc);
            Assert.AreEqual(scr, 0);
            Assert.AreEqual(sr, -0.0565697);
            Assert.AreEqual(ssr, 100);
            Assert.AreEqual(usr, 0.20);
            Assert.AreEqual(vcr, 0.0);
        }
Example #5
0
        public static Stock CreateStock(Orion.EquityVolCalcTestData.Stock stock)
        {
            DateTime today    = XmlGetDate(stock.Date);
            decimal  spot     = Convert.ToDecimal(stock.Spot);
            DateTime baseDate = XmlGetDate(stock.RateCurve.BaseDate);

            DateTime[] rateDates = XmlGetDateArray(stock.RateCurve.DateArray);
            //Load rate curve
            String tp = stock.RateCurve.RateType;
            var    rc = new RateCurve(stock.RateCurve.Ccy, tp, baseDate, rateDates, stock.RateCurve.RateArray);
            // Load dividends
            var divs = (from div in stock.Dividends let exDate = XmlGetDate(div.ExDate) select new Dividend(exDate, Convert.ToDecimal(div.Amount))).ToList();
            //Load stock object
            var stock0 = new Stock(today, spot, stock.AssetId, stock.Name, rc, divs);
            var vol0   = new VolatilitySurface(stock.AssetId, spot, today);

            //Load vols
            stock0.VolatilitySurface = vol0;
            foreach (StockVolatilitySurfaceForwardExpiry exp in stock.VolatilitySurface.Expiries)
            {
                DateTime expDate = XmlGetDate(exp.ExpiryDate);
                Decimal  fwd     = Convert.ToDecimal(exp.FwdPrice);
                var      exp0    = new ForwardExpiry(expDate, fwd);
                // exp0.NodalPoint = System.Convert.ToBoolean(exp.NodalPoint);
                vol0.AddExpiry(exp0);

                foreach (StockVolatilitySurfaceForwardExpiryStrike str in exp.Strikes)
                {
                    var    call         = new OptionPosition();
                    var    put          = new OptionPosition();
                    double strikeprice0 = Convert.ToDouble(str.StrikePrice);
                    var    str0         = new Strike(strikeprice0, call, put, Units.Cents)
                    {
                        Moneyness = Convert.ToDouble(str.Moneyness)
                    };
                    exp0.AddStrike(str0, true);
                    var     vp  = new VolatilityPoint();
                    decimal vol = Convert.ToDecimal(str.Volatility.Value);
                    vp.SetVolatility(vol, VolatilityState.Default());
                    str0.SetVolatility(vp);
                }
            }
            return(stock0);
        }
Example #6
0
 public void TestImpliedVol4()
 {
     DateTime        today    = new DateTime(2010, 07, 14);
     RateCurve       rc       = new RateCurve("AUD", "Continuous", DateTime.Parse("14-Jul-2010"), new[] { DateTime.Parse("14-Jul-2010"), DateTime.Parse("28-Jun-2012") }, new[] { 0.045507, 0.050645 });
     Dividend        d1       = new Dividend(DateTime.Parse("6-9-2010"), 49.90M);
     Dividend        d2       = new Dividend(DateTime.Parse("28-2-2011"), 54.43M);
     Dividend        d3       = new Dividend(DateTime.Parse("5-9-2011"), 58.97M);
     Dividend        d4       = new Dividend(DateTime.Parse("27-2-2012"), 61.24M);
     Dividend        d5       = new Dividend(DateTime.Parse("3-9-2012"), 65.78M);
     Dividend        d6       = new Dividend(DateTime.Parse("25-2-2013"), 68.05M);
     Dividend        d7       = new Dividend(DateTime.Parse("2-9-2013"), 72.58M);
     Dividend        d8       = new Dividend(DateTime.Parse("2-9-2013"), 72.58M);
     Dividend        d9       = new Dividend(DateTime.Parse("24-2-2014"), 73.72M);
     Dividend        d10      = new Dividend(DateTime.Parse("1-9-2014"), 75.99M);
     List <Dividend> divCurve = new List <Dividend>()
     {
         d1, d2, d3, d4, d5, d6, d7, d8, d9, d10
     };
     var    stockObject0 = new Stock(today, 3840, "BHP12JUN4100P.WY", "BHP_Vanilla_ETO_Jun12_41.00_Put", rc, divCurve);
     double vol          = OptionHelper.GetImpliedVol(stockObject0, DateTime.Parse("28-Jun-2012"), 4100, false, "American", 719, 120);
 }
Example #7
0
        public void TestImpliedVolPut()
        {
            DateTime date0    = DateTime.Today;
            DateTime exp      = date0.AddDays(90);
            DateTime ex       = date0.AddDays(20);
            double   spot     = 100;
            double   strike   = 100;
            double   vol      = 0.50;
            string   paystyle = "P";

            DateTime[]      dates = { date0, exp };
            double[]        rates = { 0.05, 0.05 };
            RateCurve       rc    = new RateCurve("AUD", "Continuous", date0, dates, rates);
            List <Dividend> divs  = new List <Dividend> {
                new Dividend(ex, 20)
            };
            AmOptionAnalytics amInstr  = new AmOptionAnalytics(date0, exp, spot, strike, vol, "A", paystyle, rc, divs, 120);
            AmOptionAnalytics euInstr  = new AmOptionAnalytics(date0, exp, spot, strike, 2 * vol, "E", paystyle, rc, divs, 120);
            double            am       = amInstr.Price();
            double            eu       = euInstr.Price();
            AmOptionAnalytics amInstr0 = new AmOptionAnalytics(date0, exp, spot, strike, 0.20, "A", paystyle, rc, divs, 120);
            AmOptionAnalytics euInstr0 = new AmOptionAnalytics(date0, exp, spot, strike, 0.80, "E", paystyle, rc, divs, 120);
            double            avol0    = amInstr0.OptSolveVol(am, 100);
            double            evol0    = euInstr0.OptSolveVol(eu, 100);
            Stock             stock    = new Stock(date0, 100, "dummy", "BHP", rc, divs);
            double            vol1     = OptionHelper.GetImpliedVol(stock, exp, strike, false, "A", am, 120);
            double            vol11    = OptionHelper.GetImpliedVol(stock, exp, strike, false, "American", am, 120);
            double            vol0     = OptionHelper.GetImpliedVol(stock, exp, strike, false, "E", eu, 120);
            double            vol00    = OptionHelper.GetImpliedVol(stock, exp, strike, false, "European", eu, 120);

            Assert.AreEqual(avol0, 0.50, 0.001);
            Assert.AreEqual(evol0, 1.00, 0.001);
            Assert.AreEqual(vol1, avol0, 0.001);
            Assert.AreEqual(vol11, avol0, 0.001);
            Assert.AreEqual(vol0, evol0, 0.001);
            Assert.AreEqual(vol00, evol0, 0.001);
        }
Example #8
0
        public void TestPricevsORCExample()
        {
            DateTime[] rtDates = { DateTime.Parse("17-Aug-2010"),
                                   DateTime.Parse("17-Sep-2010"),
                                   DateTime.Parse("18-Oct-2010"),
                                   DateTime.Parse("17-Nov-2010"),
                                   DateTime.Parse("10-Dec-2010") };

            double[]  rates = { 0.045507232,
                                0.046609656,
                                0.047336042,
                                0.047655159,
                                0.047737236 };
            RateCurve rc = new RateCurve("AUD", "Semi-Annual", DateTime.Parse("16-Aug-2010"), rtDates, rates);
            //Dividend d1 = new Dividend(DateTime.Parse("16-8-2010"),  11.745786M);
            Dividend        d2       = new Dividend(DateTime.Parse("17-8-2010"), 0.893295M);
            Dividend        d3       = new Dividend(DateTime.Parse("23-8-2010"), 7.856689M);
            Dividend        d4       = new Dividend(DateTime.Parse("24-8-2010"), 2.898251M);
            Dividend        d5       = new Dividend(DateTime.Parse("25-8-2010"), 3.344721M);
            Dividend        d6       = new Dividend(DateTime.Parse("26-8-2010"), 0.485070M);
            Dividend        d7       = new Dividend(DateTime.Parse("27-8-2010"), 0.835305M);
            Dividend        d8       = new Dividend(DateTime.Parse("30-8-2010"), 3.952976M);
            Dividend        d9       = new Dividend(DateTime.Parse("31-8-2010"), 0.884255M);
            Dividend        d10      = new Dividend(DateTime.Parse("1-9-2010"), 2.013798M);
            Dividend        d11      = new Dividend(DateTime.Parse("2-9-2010"), 1.241407M);
            Dividend        d12      = new Dividend(DateTime.Parse("3-9-2010"), 0.613699M);
            Dividend        d13      = new Dividend(DateTime.Parse("6-9-2010"), 11.712946M);
            Dividend        d14      = new Dividend(DateTime.Parse("7-9-2010"), 3.775104M);
            Dividend        d15      = new Dividend(DateTime.Parse("8-9-2010"), 0.606597M);
            Dividend        d16      = new Dividend(DateTime.Parse("9-9-2010"), 0.268093M);
            Dividend        d17      = new Dividend(DateTime.Parse("10-9-2010"), 0.144851M);
            Dividend        d18      = new Dividend(DateTime.Parse("13-9-2010"), 1.600975M);
            Dividend        d19      = new Dividend(DateTime.Parse("14-9-2010"), 1.499946M);
            Dividend        d20      = new Dividend(DateTime.Parse("15-9-2010"), 0.238824M);
            Dividend        d21      = new Dividend(DateTime.Parse("16-9-2010"), 0.117931M);
            List <Dividend> divCurve = new List <Dividend>()
            {
                d2, d3, d4, d5, d6, d7, d8, d9, d10,
                d11, d12, d13, d14, d15, d16, d17, d18, d19, d20, d21
            };
            DateTime date0 = new DateTime(2010, 08, 16);
            DateTime exp   = new DateTime(2010, 9, 16);
            double   spot  = 4447.62;
            //double future = 4420;
            double strike      = 4200;
            string stockId     = "XJO_Spot";
            Stock  stock       = new Stock(date0, Convert.ToDecimal(spot), stockId, "XJO", rc, divCurve);
            double fwd         = stock.GetForward(date0, exp);
            var    wingParams1 = new OrcWingParameters
            {
                CurrentVol = 0.234828,
                RefVol     = 0.234828,
                SlopeRef   = -0.109109,
                PutCurve   = 1.235556,
                CallCurve  = 0.60895,
                DnCutoff   = -0.493791,
                UpCutoff   = 0.506209,
                RefFwd     = 4420.092383,
                AtmForward = 4420.092383,
                Vcr        = 0,
                Scr        = 0,
                Ssr        = 100,
                Dsr        = 0.2,
                Usr        = 0.2,
            };
            VolatilitySurface vs      = new VolatilitySurface(stockId, Convert.ToDecimal(spot), date0);
            ForwardExpiry     expiry  = new ForwardExpiry(exp, Convert.ToDecimal(fwd));
            OptionPosition    op      = new OptionPosition("XJO_Vanilla_ETO_Sep10_4200.000_Put", 30.237108, PositionType.Put);
            Strike            strike0 = new Strike(strike, null, op);

            expiry.AddStrike(strike0, true);
            List <double> strikes1 = new List <double> {
                4200
            };
            ForwardExpiry forwardexpiry = vs.ValueAt(stock, exp, strikes1, wingParams1, true, false);
            double        vol           = Convert.ToDouble(forwardexpiry.Strikes[0].Volatility.Value);
            var           utils         = new AmOptionAnalytics(date0, exp, spot, strike, vol, "European", "Put", rc, divCurve, 120);
            double        pr            = Math.Round(utils.Price(), 7);
        }
Example #9
0
        public void TestImpliedVolCall()
        {
            DateTime date0    = DateTime.Today;
            DateTime exp      = date0.AddDays(90);
            DateTime ex       = date0.AddDays(20);
            double   spot     = 100;
            double   strike   = 100;
            double   vol      = 0.50;
            string   paystyle = "C";

            DateTime[]      dates = { date0, exp };
            double[]        rates = { 0.05, 0.05 };
            RateCurve       rc    = new RateCurve("AUD", "Continuous", date0, dates, rates);
            List <Dividend> divs  = new List <Dividend> {
                new Dividend(ex, 20)
            };
            AmOptionAnalytics amInstr  = new AmOptionAnalytics(date0, exp, spot, strike, vol, "A", paystyle, rc, divs, 120);
            AmOptionAnalytics euInstr  = new AmOptionAnalytics(date0, exp, spot, strike, 2 * vol, "E", paystyle, rc, divs, 120);
            double            am       = amInstr.Price();
            double            eu       = euInstr.Price();
            AmOptionAnalytics amInstr0 = new AmOptionAnalytics(date0, exp, spot, strike, 0.20, "A", paystyle, rc, divs, 120);
            AmOptionAnalytics euInstr0 = new AmOptionAnalytics(date0, exp, spot, strike, 0.80, "E", paystyle, rc, divs, 120);
            double            avol0    = amInstr0.OptSolveVol(am, 100);
            double            evol0    = euInstr0.OptSolveVol(eu, 100);
            var      stock             = new Stock(date0, 100, "dummy", "BHP", rc, divs);
            DateTime start             = DateTime.Now;
            double   vol1 = OptionHelper.GetImpliedVol(stock, exp, 0.3, strike, true, "A", am, 120);
            DateTime end  = DateTime.Now;
            double   x1   = end.Subtract(start).Milliseconds;

            start = DateTime.Now;
            double vol11 = OptionHelper.GetImpliedVol(stock, exp, 0.2, strike, true, "American", am, 120);

            end = DateTime.Now;
            double x2 = end.Subtract(start).Milliseconds;

            start = DateTime.Now;
            double vol0 = OptionHelper.GetImpliedVol(stock, exp, 0.8, strike, true, "E", eu, 120);

            end = DateTime.Now;
            double x3 = end.Subtract(start).Milliseconds;

            start = DateTime.Now;
            double vol00 = OptionHelper.GetImpliedVol(stock, exp, 0.8, strike, true, "European", eu, 120);

            end = DateTime.Now;
            double x4 = end.Subtract(start).Milliseconds;

            Assert.AreEqual(avol0, 0.50, 0.001);
            Assert.AreEqual(evol0, 1.00, 0.001);

            Assert.AreEqual(vol1, avol0, 0.001);
            Assert.AreEqual(vol11, avol0, 0.001);

            Assert.AreEqual(vol0, evol0, 0.001);
            Assert.AreEqual(vol00, evol0, 0.001);

            Debug.Print("Time 1 : " + x1);
            Debug.Print("Time 2 : " + x2);
            Debug.Print("Time 3 : " + x3);
            Debug.Print("Time 4 : " + x4);
        }