/// <summary> /// Values at, overriding calibrated Wing Model with supplied parms /// </summary> /// <param name="stock"></param> /// <param name="expiry">The expiry.</param> /// <param name="strikes">The strikes.</param> /// <param name="parms">The parms.</param> /// <param name="oride"></param> /// <param name="cache">if set to <c>true</c> [cache].</param> /// <returns></returns> public ForwardExpiry ValueAt(Stock stock, DateTime expiry, List <Double> strikes, OrcWingParameters parms, bool oride, bool cache) { var fwdExpiry = new ForwardExpiry { ExpiryDate = expiry }; double forward = stock.GetForward(stock.Date, expiry); fwdExpiry.FwdPrice = Convert.ToDecimal(forward); foreach (double strike in strikes) { double val = OrcWingVol.Value(strike, parms); IVolatilityPoint vp = new VolatilityPoint(); vp.SetVolatility(Convert.ToDecimal(val), VolatilityState.Default()); bool node = VolatilitySurfaceHelper.IsMatch(strike, expiry, NodalExpiries); Strike newstrike; if (node & oride) { newstrike = VolatilitySurfaceHelper.GetStrike(strike, expiry, NodalExpiries); //new data points, derefernce fitting model newstrike.InterpModel = null; } else { //var wingModel = new WingInterp {WingParams = parms}; newstrike = new Strike { StrikePrice = strike, InterpModel = null }; //newstrike.InterpModel = wingModel; fwdExpiry.AddStrike(newstrike, node); } newstrike.SetVolatility(vp); } return(fwdExpiry); }
public void TestAmVega() { var stock = TestDataHelper.GetStock("ANZ"); Assert.AreEqual("ANZ", stock.Name); var stockObject = TestHelper.CreateStock(stock); var fwd = new ForwardExpiry(DateTime.Parse("23-12-2010"), 2220); var str = new Strike(2100, null, null, Units.Cents); var vp = new VolatilityPoint { Value = 0.30M }; str.SetVolatility(vp); fwd.AddStrike(str, true); stockObject.VolatilitySurface.AddExpiry(fwd); foreach (ForwardExpiry fwdExp in stockObject.VolatilitySurface.Expiries) { foreach (Strike strike in fwdExp.Strikes) { if ((strike.StrikePrice == 2100.0) && (fwdExp.ExpiryDate == DateTime.Parse("23-12-2010"))) { AmOptionAnalytics call = new AmOptionAnalytics(stockObject.Date, fwdExp.ExpiryDate, Convert.ToDouble(stockObject.Spot), strike.StrikePrice, Convert.ToDouble(strike.Volatility.Value), "A", "C", stockObject.RateCurve, stockObject.Dividends, 20); double callprice = call.Price(); Assert.AreEqual(callprice, 338.8661, 0.5); call.MakeVega(); Assert.AreEqual(call.Vega, 9.093, 0.02); AmOptionAnalytics put = new AmOptionAnalytics(stockObject.Date, fwdExp.ExpiryDate, Convert.ToDouble(stockObject.Spot), strike.StrikePrice, Convert.ToDouble(strike.Volatility.Value), "A", "P", stockObject.RateCurve, stockObject.Dividends, 20); double putprice = put.Price(); Assert.AreEqual(putprice, 239.6014, 0.5); put.MakeVega(); Assert.AreEqual(put.Vega, 9.093, 0.02); } } } }
/// <summary> /// Creates a test vol surface to test temporal and strike volatility interpolation /// </summary> /// <returns></returns> public IVolatilitySurface CreateTestVolSurface() { 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, true); volSurface.AddExpiry(expiry1); volSurface.AddExpiry(expiry2); return(volSurface); }
/// <summary> /// Creates a null volatility surface to be used in extrapolation tests that utilise /// the historical volatility ratio /// </summary> /// <returns></returns> public IVolatilitySurface CreateNullVolSurface() { IVolatilitySurface volSurface = new VolatilitySurface("BHP", 4500M, DateTime.Today); ForwardExpiry expiry0 = new ForwardExpiry(DateTime.Parse("14-9-2009"), 4700); ForwardExpiry expiry1 = new ForwardExpiry(DateTime.Parse("16-9-2009"), 4700); ForwardExpiry expiry2 = new ForwardExpiry(DateTime.Parse("30-9-2009"), 4750); OptionPosition call0 = new OptionPosition("1145", 104, PositionType.Call); OptionPosition put0 = new OptionPosition("1146", 1200, PositionType.Put); 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 strike0 = new Strike(1.00, 4599, call0, put0); Strike strike1 = new Strike(0.867, 4700, call1, put1); Strike strike2 = new Strike(1.00, 4750, call2, put2); Strike strike3 = new Strike(1.2, 4750, call2, put2); Strike strike4 = new Strike(0.30, 4750, call2, put2); IVolatilityPoint point0 = new VolatilityPoint(); point0.SetVolatility(0.00M, VolatilityState.Default()); put0.SetVolatility(point0); call0.SetVolatility(point0); strike0.SetVolatility(point0); IVolatilityPoint point1 = new VolatilityPoint(); point1.SetVolatility(0.00M, VolatilityState.Default()); put1.SetVolatility(point1); call1.SetVolatility(point1); strike1.SetVolatility(point1); IVolatilityPoint point2 = new VolatilityPoint(); point2.SetVolatility(0.00M, VolatilityState.Default()); strike2.SetVolatility(point2); call2.SetVolatility(point2); put2.SetVolatility(point2); IVolatilityPoint point3 = new VolatilityPoint(); point3.SetVolatility(0.00M, VolatilityState.Default()); strike3.SetVolatility(point3); IVolatilityPoint point4 = new VolatilityPoint(); point4.SetVolatility(0.00M, VolatilityState.Default()); strike4.SetVolatility(point4); expiry0.AddStrike(strike0, true); expiry1.AddStrike(strike1, true); expiry2.AddStrike(strike2, true); expiry2.AddStrike(strike3, true); expiry2.AddStrike(strike4, true); volSurface.AddExpiry(expiry0); volSurface.AddExpiry(expiry1); volSurface.AddExpiry(expiry2); return(volSurface); }
/// <summary> /// Values at. /// </summary> /// <param name="stock"></param> /// <param name="expiries">The expiries.</param> /// <param name="strikes">The strikes.</param> /// <param name="?">Cache to vol object</param> /// <param name="cache"></param> /// <returns></returns> public List <ForwardExpiry> ValueAt(Stock stock, List <DateTime> expiries, List <Double> strikes, bool cache) { var forwardExpiries = new List <ForwardExpiry>(); foreach (DateTime exp in expiries) { var fwdExpiry = new ForwardExpiry(); foreach (double str in strikes) { var wingModel = new WingInterp(); double forward = stock.GetForward(stock.Date, exp.Date); double spot = Convert.ToDouble(stock.Spot); fwdExpiry.FwdPrice = Convert.ToDecimal(forward); double y = str; double x = (exp.Subtract(Date)).Days / 365.0; IPoint point = new Point2D(x, y); InterpCurve.Forward = forward; InterpCurve.Spot = spot; var val = InterpCurve.Value(point); IVolatilityPoint vp = new VolatilityPoint(); vp.SetVolatility(Convert.ToDecimal(val), VolatilityState.Default()); fwdExpiry.ExpiryDate = exp; bool node = VolatilitySurfaceHelper.IsMatch(str, exp, NodalExpiries); // copy model used to return ForwardExpiry object var newstrike = new Strike { StrikePrice = str }; var wing = (WingModelInterpolation)InterpCurve.GetYAxisInterpolatingFunction(); //SABRModelInterpolation wing = (SABRModelInterpolation)_interpCurve.GetYAxisInterpolatingFunction(); wingModel.WingParams = wing.WingParameters; newstrike.InterpModel = wingModel; fwdExpiry.AddStrike(newstrike, node); newstrike.SetVolatility(vp); } forwardExpiries.Add(fwdExpiry); } return(forwardExpiries); }