public static EliteQuant.DoubleVector VectorToEQVector(double[] v) { int row = v.Count(); EliteQuant.DoubleVector vec = new EliteQuant.DoubleVector(row); for (int i = 0; i < row; i++) vec[i] = v[i]; return vec; }
public static double[] EQVectorToVector(EliteQuant.DoubleVector v) { int row = v.Count(); double[] vec = new double[row]; for (int i = 0; i < row; i++) vec[i] = v[i]; return vec; }
public static string eqIRCurveLinearZero( [ExcelArgument(Description = "(String) id of curve (USDOIS, USDLIB3M) ")] string ObjectId, [ExcelArgument(Description = "array of rate helpers ")] object[] ratehelpers, [ExcelArgument(Description = "Interpolation Method (default LogLinear) ")] string interp, [ExcelArgument(Description = "trigger ")] object trigger) { if (ExcelUtil.CallFromWizard()) { return(""); } string callerAddress = ExcelUtil.getActiveCellAddress(); Xl.Range rng = ExcelUtil.getActiveCellRange(); try { string interpmethod; if (ExcelUtil.isNull(interp)) { interpmethod = "LOGLINEAR"; } else { interpmethod = interp.ToUpper(); } EliteQuant.RateHelperVector rhv = new EliteQuant.RateHelperVector(); EliteQuant.Date today = EliteQuant.Settings.instance().getEvaluationDate(); List <EliteQuant.Date> dates = new List <EliteQuant.Date>(); dates.Add(today); // today has discount 1 foreach (var rid in ratehelpers) { if (ExcelUtil.isNull(rid)) { continue; } try { EliteQuant.RateHelper rh = OHRepository.Instance.getObject <EliteQuant.RateHelper>((string)rid); rhv.Add(rh); dates.Add(rh.latestDate()); } catch (Exception) { // skip null instruments } } // set reference date to today. or discount to 1 EliteQuant.YieldTermStructure yth = new EliteQuant.PiecewiseLogLinearDiscount(today, rhv, dc_act_360); EliteQuant.DateVector dtv = new EliteQuant.DateVector(); EliteQuant.DoubleVector discv = new EliteQuant.DoubleVector(); foreach (var dt in dates) { double disc = yth.discount(dt); dtv.Add(dt); discv.Add(disc); } // reconstruct the discount curve // note that discount curve is LogLinear EliteQuant.YieldTermStructure yth2 = null; yth2 = new EliteQuant.DiscountCurve(dtv, discv, dc_act_360, ObjectId.Contains("OIS") ? cal_usd : cal_usd_gbp); if (!ObjectId.Contains('@')) { ObjectId = "CRV@" + ObjectId; } //string id = "IRCRV@" + ObjectId; string id = ObjectId; OHRepository.Instance.storeObject(id, yth2, callerAddress); return(id + "#" + DateTime.Now.ToString("HH:mm:ss")); } catch (Exception e) { ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message); return("#EQ_ERR!"); } }