static public double CalcDeltaValue( InitialTerm.InitialParameter param, double forward, double strike, double volatility, InitialTerm.CallPutType type, InitialTerm.DeltaType deltaType) { var d1 = DFuncCalculator.CalcDValue(param, volatility, param.tau, forward, strike); var d2 = d1 - volatility * Math.Sqrt(param.tau); switch (deltaType) { case InitialTerm.DeltaType.PipsSpotDelta: return((int)type * Math.Exp(-param.rateOfForeign * param.tau) * CDF((int)type * d1)); case InitialTerm.DeltaType.PercentageSpotDelta: return((int)type * Math.Exp(-param.rateOfDomestic * param.tau) * strike / param.spotRate * CDF((int)type * d2)); default: return(0.0); } }
static public double CalcStrike( InitialTerm.InitialParameter param, double forward, double volatility, InitialTerm.DeltaType deltaType, InitialTerm.VolatilityType volatilityType) { switch (volatilityType) { case InitialTerm.VolatilityType.ATM: return(CalcAtmStrike(param, forward, volatility, deltaType)); case InitialTerm.VolatilityType.MS25Call: return(CalcInvCdf( param, volatility, forward, 0.25, Type, deltaType)); case InitialTerm.VolatilityType.MS25Put: return(CalcInvCdf( param, volatility, forward, -0.25, Type, deltaType)); case InitialTerm.VolatilityType.MS10Call: return(CalcInvCdf( param, volatility, forward, 0.1, Type, deltaType)); case InitialTerm.VolatilityType.MS10Put: return(CalcInvCdf( param, volatility, forward, -0.1, Type, deltaType)); default: return(0); } }
static public double CalcDValue( InitialTerm.InitialParameter param, double vol, double tau, double forward, double strike) { return((Math.Log(forward / strike) * 0.5 * Math.Pow(vol, 2.0) * tau) / (vol * Math.Sqrt(tau))); }
static public double CalcOptionPrice( InitialTerm.InitialParameter param, double forward, double strike, double d1, double d2, InitialTerm.CallPutType type) { return((int)type * forward * Math.Exp(-param.rateOfForeign * param.tau) * Normal.CDF(0, 1, (int)type * d1) - strike * Normal.CDF(0, 1, (int)type * d2)); }
public static List <double> PriceSetting(InitialTerm.InitialParameter param) { var priceList = new List <double>(); var forward = ForwardCalculator.CalcForwardRate(param); foreach (InitialTerm.VolatilityType volatilityType in Enum.GetValues(typeof(InitialTerm.VolatilityType))) { var type = JudgeMaterial.JudgeOfCallPut.CallOrPut(volatilityType); var volatility = JudgeMaterial.JudgeOfVolatility.Volatility(param, volatilityType); var strike = StrikrCalcultor.CalcStrike(param, forward, volatility, param.deltaType, volatilityType); var d1 = DFuncCalculator.CalcDValue(param, volatility, param.tau, forward, strike); var d2 = d1 - volatility * Math.Sqrt(param.tau); priceList.Add(FlyAdjustment.PriceCalculator.CalcOptionPrice(param, forward, strike, d1, d2, type)); } return(priceList); }
public static List <double> StrikeSetting(InitialTerm.InitialParameter param) { var strikeList = new List <double>(); var forward = ForwardCalculator.CalcForwardRate(param); foreach (InitialTerm.VolatilityType volatilityType in Enum.GetValues(typeof(InitialTerm.VolatilityType))) { var volatility = JudgeMaterial.JudgeOfVolatility.Volatility(param, volatilityType); strikeList.Add(StrikrCalcultor.CalcStrike( param, forward, volatility, param.deltaType, volatilityType)); } return(strikeList); }
private static double CalcAtmStrike( InitialTerm.InitialParameter param, double forward, double volatility, InitialTerm.DeltaType deltaType) { double strike = 0.0; if (deltaType == InitialTerm.DeltaType.PipsSpotDelta || deltaType == InitialTerm.DeltaType.PercentageForwardDelta) { strike = forward * Math.Exp(volatility * volatility * param.tau / 2.0); } else { strike = forward * Math.Exp(-volatility * volatility * param.tau / 2.0); } return(strike); }
public static double CalcInvCdf( InitialTerm.InitialParameter param, double volatility, double forward, double delta, InitialTerm.CallPutType type, InitialTerm.DeltaType deltaType) { Volatility = volatility; Forward = forward; DeltaType = deltaType; Number = delta; var strikeCalculator = new StrikrCalcultor(param); return(UseBisection.Calc( strikeCalculator.DeltaFunctionOfStrike, 0.5 * param.spotRate, 2.0 * param.spotRate)); }
static void CalcUSDJPY() { var spot = 106.925; var rateOfDomestic = -0.00085034363976; var rateOfForeign = 0.02216698493974; var tau = 1.0; var volAtm = 0.071; var vol25MS = 0.002; var vol10MS = 0.0105; var vol25RR = -0.021; var vol10RR = -0.042; var deltaType = InitialTerm.DeltaType.PercentageSpotDelta; var param = new InitialTerm.InitialParameter( spot, rateOfDomestic, rateOfForeign, tau, volAtm, vol25MS, vol10MS, vol25RR, vol10RR, deltaType ); var forward = ForwardCalculator.CalcForwardRate(param); var strikeList = InitialSetting.StrikeSetting(param); //var interpolationName = "PolynomialInDelta"; var interpolationName = "SABR"; var vTarget = 4.5; var Ans = Calibration.Solve( interpolationName, param, forward, vTarget, strikeList); Console.WriteLine(Ans); }
static public double CalcForwardRate(InitialTerm.InitialParameter param) { return(param.spotRate * Math.Exp((param.rateOfDomestic - param.rateOfForeign) * param.tau)); }
public static Vector <double> Solve( string interpolationName, InitialTerm.InitialParameter param, double forward, double vtarget, List <double> strikeList) { InterpolationName = interpolationName; Param = param; StrikeList = strikeList; K25Call = strikeList[3]; KATM = strikeList[2]; K25Put = strikeList[1]; VolSS25 = param.volMS25; var tol = 1.0E-5; var error = 1.0; var LowerVector = Vector <double> .Build.DenseOfArray(new double[] { 0.00001, 0.00001, -0.99999 }); var UpperVector = Vector <double> .Build.DenseOfArray(new double[] { 100, 100, 0.99999 }); VolParameter = Vector <double> .Build.DenseOfArray(new double[] { 0.1, 0.1, -0.1 }); while (Math.Abs(error) > tol) { if (InterpolationName == "SABR") { VolParameter = FindMinimum.OfFunctionConstrained( FuncOfVolCondtion, LowerVector, UpperVector, VolParameter); //VolParameter = FindMinimum.OfFunction(FuncOfVolCondtion, VolParameter); } else { VolParameter = FindMinimum.OfFunction(FuncOfVolCondtion, VolParameter); } CalcStrikeList(VolParameter); var vTrial = CalcValueTrial(VolParameter); error = vTrial - vtarget; if (error > 0) { VolSS25 -= tol / 100; } else { VolSS25 += tol / 100; } } var volRR25 = VolCalculator(K25Call, VolParameter) - VolCalculator(K25Put, VolParameter); var Ans = Vector <double> .Build.DenseOfArray(new double[] { VolParameter[0], VolParameter[1], VolParameter[2], K25Call, K25Put, VolSS25, volRR25 }); return(Ans); }
public StrikrCalcultor(InitialTerm.InitialParameter param) { this.Param = param; }