public static object eqModelGetSVICalibratedParameters( [ExcelArgument(Description = "id of SVI model ")] string ObjectId, [ExcelArgument(Description = "trigger ")] object trigger) { if (ExcelUtil.CallFromWizard()) { return(""); } string callerAddress = ""; callerAddress = ExcelUtil.getActiveCellAddress(); try { Xl.Range rng = ExcelUtil.getActiveCellRange(); SVIInterpolation option = OHRepository.Instance.getObject <SVIInterpolation>(ObjectId); object[,] ret = new object[7, 2]; ret[0, 0] = "a:"; ret[0, 1] = option.a(); ret[1, 0] = "b:"; ret[1, 1] = option.b(); ret[2, 0] = "rho:"; ret[2, 1] = option.rho(); ret[3, 0] = "m:"; ret[3, 1] = option.m(); ret[4, 0] = "sigma:"; ret[3, 1] = option.sigma(); ret[5, 0] = "rmsError:"; ret[4, 1] = option.rmsError(); ret[6, 0] = "maxError:"; ret[5, 1] = option.maxError(); return(ret); } catch (Exception e) { ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message); return(e.Message); } }
public static object eqModelGetSVIInterpolatedValue( [ExcelArgument(Description = "id of SVI model ")] string ObjectId, [ExcelArgument(Description = "strik value ")] double x) { if (ExcelUtil.CallFromWizard()) { return(""); } string callerAddress = ""; callerAddress = ExcelUtil.getActiveCellAddress(); try { Xl.Range rng = ExcelUtil.getActiveCellRange(); SVIInterpolation option = OHRepository.Instance.getObject <SVIInterpolation>(ObjectId); return(option.call(x)); } catch (Exception e) { ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message); return(e.Message); } }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SVIInterpolation obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public static string eqModelSVI( [ExcelArgument(Description = "id of option to be constructed ")] string ObjectId, [ExcelArgument(Description = "ATM forward ")] double forward, [ExcelArgument(Description = "expiry (years of fraction ")] double tenor, [ExcelArgument(Description = "Strikes ")] double[] strikes, [ExcelArgument(Description = "implied vols ")] double[] volatilities, [ExcelArgument(Description = "initial parameters ")] double[] initials, [ExcelArgument(Description = "trigger ")] object trigger) { if (ExcelUtil.CallFromWizard()) { return(""); } string callerAddress = ""; callerAddress = ExcelUtil.getActiveCellAddress(); try { if (strikes.Length != volatilities.Length) { throw new Exception("SABR input lengths don't match."); } if (initials.Length != 5) { throw new Exception("SVI has five parameters."); } int[] idx = volatilities.Select((v, Index) => new { V = v, idx = Index }) .Where(x => x.V == 0) .Select(x => x.idx) .ToArray(); QlArray xx = new QlArray((uint)strikes.Length - (uint)idx.Length); QlArray yy = new QlArray((uint)volatilities.Length - (uint)idx.Length); for (uint i = 0, j = 0; i < strikes.Length; i++) { if (volatilities[i] == 0) // empty { continue; } xx.set(j, strikes[i]); yy.set(j, volatilities[i]); j++; } EndCriteria endcriteria = new EndCriteria(100000, 100, 1e-8, 1e-8, 1e-8); OptimizationMethod opmodel = new Simplex(0.01); // alpha: ATM Vol, beta: CEV param, rho: underlying/vol correlation, nu: vol of vol SVIInterpolation svi = new SVIInterpolation(xx, yy, tenor, forward, initials[0], initials[1], initials[2], initials[3], initials[4], endcriteria, opmodel, true); double err = 0; err = svi.update(); // Store the option and return its id string id = "MODEL@" + ObjectId; OHRepository.Instance.storeObject(id, svi, callerAddress); id += "#" + (String)DateTime.Now.ToString(@"HH:mm:ss"); return(id); } catch (Exception e) { ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message); return(e.Message); } }