Esempio n. 1
0
        public void TestVolSurface()
        {
            IVolatilitySurface volSurface = new VolatilitySurface("BHP", 4500M, DateTime.Today);
            ForwardExpiry      expiry1    = new ForwardExpiry(DateTime.Parse("01-Jan-2010"), 4200);
            ForwardExpiry      expiry2    = new ForwardExpiry(DateTime.Parse("01-Jan-2011"), 4400);
            OptionPosition     call1      = new OptionPosition("1245", 104, PositionType.Call);
            OptionPosition     put1       = new OptionPosition("1246", 1200, PositionType.Put);
            OptionPosition     call2      = new OptionPosition("1645", 180, PositionType.Call);
            OptionPosition     put2       = new OptionPosition("1646", 1300, PositionType.Put);
            Strike             strike1    = new Strike(4200, call1, put1);
            Strike             strike2    = new Strike(4000, call2, put2);
            IVolatilityPoint   point1     = new VolatilityPoint();

            point1.SetVolatility(0.30M, VolatilityState.Default());
            put1.SetVolatility(point1);
            call1.SetVolatility(point1);
            IVolatilityPoint point2 = new VolatilityPoint();

            point2.SetVolatility(0.40M, VolatilityState.Default());
            call2.SetVolatility(point2);
            put2.SetVolatility(point2);
            expiry1.AddStrike(strike1, true);
            expiry2.AddStrike(strike2, false);
            volSurface.AddExpiry(expiry1);
            volSurface.AddExpiry(expiry2);
            List <ForwardExpiry> forwardExpiries = volSurface.NodalExpiries.ToList();
            int n1 = forwardExpiries[0].Strikes.Count(item => item.NodalPoint);
            // int n2 = forwardExpiries[1].Strikes.Count(delegate(Strike item) { return item.NodalPoint == true; });
            int n2 = 0;

            Assert.AreEqual(1, n1 + n2);
        }
Esempio n. 2
0
        public static Stock CreateStock(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);
        }
Esempio n. 3
0
        private static VolatilitySurface CreateSurface(Stock stock)
        {
            VolatilitySurface surface = new VolatilitySurface(stock.AssetId, stock.Spot, stock.Date);
            List <DateTime>   dates   = new List <DateTime>
            {
                new DateTime(2009, 9, 16),
                new DateTime(2009, 10, 05),
                new DateTime(2009, 10, 10),
                new DateTime(2009, 11, 9),
                new DateTime(2009, 11, 26),
                new DateTime(2009, 12, 9),
                new DateTime(2010, 3, 10),
                new DateTime(2010, 6, 9),
                new DateTime(2010, 9, 8),
                new DateTime(2011, 3, 12),
                new DateTime(2011, 9, 7),
                new DateTime(2012, 9, 9),
                new DateTime(2013, 9, 9),
                new DateTime(2014, 9, 9),
            };
            IList <double> moneynesses = new List <double> {
                0.5, 0.9, 1, 1.1, 1.5
            };

            foreach (DateTime date in dates)
            {
                var expiry = new ForwardExpiry
                {
                    FwdPrice   = (decimal)stock.GetForward(stock.Date, date),
                    ExpiryDate = date
                };
                foreach (double moneyness in moneynesses)
                {
                    Strike           str = new Strike(Math.Round(Convert.ToDouble(expiry.FwdPrice) * moneyness, 2), null, null, Units.Cents);
                    IVolatilityPoint vp  = new VolatilityPoint();
                    vp.SetVolatility(Convert.ToDecimal(Math.Exp(moneyness) / 3 * 0.32), VolatilityState.Default());
                    str.SetVolatility(vp);
                    expiry.AddStrike(str, true);
                }
                surface.AddExpiry(expiry);
            }
            return(surface);
        }
Esempio n. 4
0
        private static VolatilitySurface CreateSurface(Stock stock)
        {
            VolatilitySurface surface = new VolatilitySurface(stock.AssetId, stock.Spot, stock.Date);
            List <DateTime>   dates   = new List <DateTime>
            {
                new DateTime(2014, 9, 9),
                new DateTime(2016, 9, 9)
            };
            IList <double> strikes = new List <double> {
                2261,
                2638,
                2827,
                3015,
                3204,
                3298,
                3392,
                3467,
                3543,
                3581,
                3618,
                3694,
                3769,
                3844,
                3920,
                3957,
                3995,
                4071,
                4146,
                4240,
                4334,
                4523,
                4711,
                4900,
                5277,
                5465,
                5654,
                5842,
                6030,
                6219,
                6407,
                6596,
                6784,
                6973,
                7161,
                7350,
                7538
            };

            IList <double> vols1 = new List <double> {
                0.4162,
                0.4094,
                0.4062,
                0.4031,
                0.4,
                0.3985,
                0.3972,
                0.3961,
                0.3949,
                0.3944,
                0.3938,
                0.3925,
                0.3912,
                0.3899,
                0.3886,
                0.388,
                0.3874,
                0.3862,
                0.385,
                0.3835,
                0.382,
                0.3792,
                0.3764,
                0.3738,
                0.3688,
                0.3665,
                0.3643,
                0.3622,
                0.3602,
                0.3584,
                0.3566,
                0.3549,
                0.3533,
                0.3518,
                0.3503,
                0.3489,
                0.3476
            };

            IList <double> vols2 = new List <double> {
                0.4085,
                0.4021,
                0.399,
                0.3961,
                0.3932,
                0.3918,
                0.3906,
                0.3897,
                0.3888,
                0.3883,
                0.3878,
                0.3866,
                0.3853,
                0.384,
                0.3828,
                0.3822,
                0.3816,
                0.3803,
                0.3792,
                0.3777,
                0.3763,
                0.3734,
                0.3707,
                0.3681,
                0.3631,
                0.3608,
                0.3585,
                0.3564,
                0.3544,
                0.3525,
                0.3506,
                0.3489,
                0.3472,
                0.3456,
                0.344,
                0.3425,
                0.3411
            };


            var expiry1 = new ForwardExpiry
            {
                FwdPrice   = (decimal)stock.GetForward(stock.Date, dates[0]),
                ExpiryDate = dates[0]
            };
            var expiry2 = new ForwardExpiry
            {
                FwdPrice   = (decimal)stock.GetForward(stock.Date, dates[1]),
                ExpiryDate = dates[1]
            };

            for (int idx = 0; idx < strikes.Count; idx++)
            {
                Strike           str = new Strike(strikes[idx], null, null, Units.Cents);
                IVolatilityPoint vp  = new VolatilityPoint();
                vp.SetVolatility(Convert.ToDecimal(vols1[idx]), VolatilityState.Default());
                str.SetVolatility(vp);
                expiry1.AddStrike(str, true);
            }
            surface.AddExpiry(expiry1);
            for (int idx = 0; idx < strikes.Count; idx++)
            {
                Strike           str = new Strike(strikes[idx], null, null, Units.Cents);
                IVolatilityPoint vp  = new VolatilityPoint();
                vp.SetVolatility(Convert.ToDecimal(vols2[idx]), VolatilityState.Default());
                str.SetVolatility(vp);
                expiry2.AddStrike(str, true);
            }
            surface.AddExpiry(expiry2);
            return(surface);
        }