private void Read(IEnumerable <FixTag> tags) { foreach (FixTag tag in tags) { if (tag.Tag == this.tSymbol) { this.symbol = tag.Value; } else if (tag.Tag == this.tMaturity) { this.maturity = new DateTime( Convert.ToInt32(tag.Value.Substring(0, 4)), Convert.ToInt32(tag.Value.Substring(4, 2)), 1); } else if (tag.Tag == this.tStrikePx) { this.strikePx = Convert.ToDouble(tag.Value); } else if (tag.Tag == this.tCallPut) { this.callPut = tag.Value.Contains("OC") ? CallPut.Call : CallPut.Put; } else if (tag.Tag == this.tCurrency) { this.currency = tag.Value; } else if (tag.Tag == this.tQty) { this.qty = Convert.ToInt32(tag.Value); } } }
public BlackScholes(CallPut type, double t, double df, double vol, double divYield, double spot, double strike) { Option.Type tt = QLNet.Option.Type.Call; if (type == CallPut.Put) { tt = QLNet.Option.Type.Put; } T = Math.Max(0, t); double growthFactor = Math.Exp(-divYield * T); ActualType = type; Type = tt; DF = df; _Vol = vol; GrowthFactor = growthFactor; _Spot = spot; Strike = strike; vol *= Math.Sqrt(T); Option.Add(new BlackScholesCalculator(new PlainVanillaPayoff(tt, Strike), spot, growthFactor, vol, df)); if (ActualType == CallPut.Forward) { Option.Add(new BlackScholesCalculator(new PlainVanillaPayoff(QLNet.Option.Type.Put, Strike), spot, growthFactor, vol, df)); } }
public static object BSDelta(double Spot, double DivYield, double Vol, double T, double DF, double Strike, int PutCall) { CallPut cp = (CallPut)PutCall; CommonTypes.Maths.BlackScholes bb = new BlackScholes(cp, T, DF, Vol, DivYield, Spot, Strike); double delta = bb.Delta(); return(delta); }
public static object BSPremium(double Spot, double DivYield, double Vol, double T, double DF, double Strike, int PutCall) { CallPut cp = (CallPut)PutCall; CommonTypes.Maths.BlackScholes bb = new BlackScholes(cp, T, DF, Vol, DivYield, Spot, Strike); double premium = bb.Premium(); return(premium); }
public static object BSRho(double Spot, double DivYield, double Vol, double T, double DF, double Strike, int PutCall, object DaysOpt) { double days = Utils.GetOptionalParameter(DaysOpt, 1); CallPut cp = (CallPut)PutCall; CommonTypes.Maths.BlackScholes bb = new BlackScholes(cp, T, DF, Vol, DivYield, Spot, Strike); double rho = bb.Rho(days); return(rho); }
public static object BSVega(double Spot, double DivYield, double Vol, double T, double DF, double Strike, int PutCall) { CallPut cp = (CallPut)PutCall; CommonTypes.Maths.BlackScholes bb = new BlackScholes(cp, T, DF, Vol, DivYield, Spot, Strike); if (PutCall == 0) { return(0); } double vega = bb.Vega(); return(vega); }
public static object BSTheta(double Spot, double DivYield, double Vol, double T, double DF, double Strike, int PutCall, object DaysOpt) { double days = Utils.GetOptionalParameter(DaysOpt, 1); CallPut cp = (CallPut)PutCall; CommonTypes.Maths.BlackScholes bb = new BlackScholes(cp, T, DF, Vol, DivYield, Spot, Strike); if (PutCall == 0) { return(0); } double theta = bb.Theta(days); return(theta); }
public static object OptionVaR(double Spot, double DivYield, double Vol, double T, double DF, double Strike, int PutCall, object Skew90Minus110Opt, object PercentileOpt) { double skew = Utils.GetOptionalParameter(Skew90Minus110Opt, 0.0); double percentile = Utils.GetOptionalParameter(PercentileOpt, 0.95); CallPut cp = (CallPut)PutCall; CommonTypes.Maths.BlackScholes bb = new BlackScholes(cp, T, DF, Vol, DivYield, Spot, Strike); double nStdev = Normal.Inverse(percentile); double spotReturn = nStdev * PutCall * Math.Abs(Vol) * Math.Sqrt(T); double BumpedSpot = Spot * (1 + spotReturn); double BumpedVol = Vol + skew * spotReturn / 0.2; CommonTypes.Maths.BlackScholes bb2 = new BlackScholes(cp, T, DF, BumpedVol, DivYield, BumpedSpot, Strike); double VaR = bb2.Premium() - bb.Premium(); // This doesn't work - a 1+ sigma move is too big to do an infinitesimal expansion on with just 1st/2nd order greeks! //double VaR2 = bb.Delta() * spotReturn + 0.5 * bb.Gamma() * (spotReturn * spotReturn) + bb.Vega() * (BumpedVol - Vol) * 100; return(VaR); }
public static NArray BlackScholes(CallPut callPutFactor, NArray forward, double strike, NArray volatility, double deltaTime) { return(BlackScholes(callPutFactor == CallPut.Call ? 1 : -1, forward, strike, volatility, deltaTime)); }
public static NArray BlackScholes(CallPut callPutFactor, NArray forward, double strike, NArray volatility, double deltaTime) { return BlackScholes(callPutFactor == CallPut.Call ? 1 : -1, forward, strike, volatility, deltaTime); }
public static object BSValuation(double Spot, object[] DivYields, object[] Vols, object[] Ts, object[] DFs, object[] Strikes, object[] PutCalls, string ValuationOpt, object SpotShiftOpt, object TimeShiftOpt) { double[] divs = Utils.GetVector <double>(DivYields); double[] vols = Utils.GetVector <double>(Vols); double[] ts = Utils.GetVector <double>(Ts); double[] dfs = Utils.GetVector <double>(DFs); double[] strikes = Utils.GetVector <double>(Strikes); double[] putcalls = Utils.GetVector <double>(PutCalls); string val = Utils.GetOptionalParameter(ValuationOpt, "Premium"); double spotShift = Utils.GetOptionalParameter(SpotShiftOpt, 0.0); double timeShift = Utils.GetOptionalParameter(TimeShiftOpt, 0.0); int nOptions = vols.Length; if (/*nOptions != ts.Length || */ nOptions != dfs.Length || nOptions != strikes.Length || nOptions != putcalls.Length) { return("ERROR: inconsistent data lengths!"); } double[] values = new double[nOptions]; for (int i = 0; i < nOptions; ++i) { double value = 0; if (ts[i] <= 0) { value = 0; } else { CallPut cp = (CallPut)putcalls[i]; double adjustedSpot = Spot * (1 + spotShift); double adjustedT = ts[i] - timeShift / 365.25; CommonTypes.Maths.BlackScholes bb = new BlackScholes(cp, adjustedT, dfs[i], vols[i], divs[i], adjustedSpot, strikes[i]); if (val == "Premium" || val == "PnL") { value = bb.Premium() * (cp == 0 ? strikes[i] / Spot : adjustedSpot / Spot); } else if (val == "Delta") { value = bb.Delta(); } else if (val == "Gamma") { if (cp == 0) { value = 0; } else { value = bb.Gamma() * (cp == 0 ? strikes[i] / Spot : adjustedSpot / Spot); } } else if (val == "Vega") { if (cp == 0) { value = 0; } else { value = bb.Vega() * (cp == 0 ? strikes[i] / Spot : adjustedSpot / Spot); } } else if (val == "Rho") { value = bb.Rho(1) * (cp == 0 ? strikes[i] / Spot : adjustedSpot / Spot); } else if (val == "Theta") { if (cp == 0) { value = 0; } else { value = bb.Theta(1) * (cp == 0 ? strikes[i] / Spot : adjustedSpot / Spot); } } } values[i] = value; } return(values); }