示例#1
0
        public static DateTime eqOpLibXllBuildTime()
        {
            DateTime buildTime = new DateTime();

            try
            {
                buildTime = getXllBuildTime();
            }
            catch (Exception ex)
            {
                ExcelUtil.logError("", "", ex.Message);
            }
            return(buildTime);
        }
示例#2
0
        public static object eqModelGetDoubleExponentialTermVol(
            [ExcelArgument(Description = "id of double exponential atm model ")] string ObjectId,
            [ExcelArgument(Description = "from t ")] double tfrom,
            [ExcelArgument(Description = "to t ")] double tto,        // 0 to t
            [ExcelArgument(Description = "T value ")] double maturityT,
            [ExcelArgument(Description = "T Vol ")] double TQuoteVol) // for T
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                if (ExcelUtil.isNull(tfrom))
                {
                    tfrom = 0.0;
                }

                bool bigT = true;
                if (ExcelUtil.isNull(TQuoteVol) || (TQuoteVol == 0.0))
                {
                    bigT = false;
                }

                Xl.Range rng = ExcelUtil.getActiveCellRange();
                DoubleExponentialCalibration atmvol = OHRepository.Instance.getObject <DoubleExponentialCalibration>(ObjectId);

                double scaler = 1.0;
                if (bigT)
                {
                    DoubleVector tv = new DoubleVector(); tv.Add(maturityT);
                    DoubleVector vv = new DoubleVector(); vv.Add(TQuoteVol);

                    scaler = atmvol.k(tv, vv)[0];
                }

                return(scaler * atmvol.value(tfrom, tto, maturityT));
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }
示例#3
0
        public static string eqOpLibXllBuiltBy()
        {
            string user;

            try
            {
                user = getBuildUser();
            }
            catch (Exception ex)
            {
                ExcelUtil.logError("", "", ex.Message);
                user = ex.Message;
            }
            return(user);
        }
示例#4
0
        public static string eqIndexesSetHistory(
            [ExcelArgument(Description = "index name (USDOIS, USDLIB3M) ")] string name,
            [ExcelArgument(Description = "historical dates ")] object[] dates,
            [ExcelArgument(Description = "historical fixings ")] double[] quotes,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                if (dates.Length != quotes.Length)
                {
                    return("size mismatch");
                }

                DateVector   dt = new DateVector(dates.Length);
                DoubleVector qs = new DoubleVector(dates.Length);

                for (int i = 0; i < dates.Length; i++)
                {
                    dt.Add(new Date(Convert.ToInt32(dates[i])));
                    qs.Add(quotes[i]);
                }

                if (!name.Contains('@'))
                {
                    name = "IDX@" + name;
                }

                string name2 = EliteQuant.Curves.IndexMapping.ExtIndexName2EQName(name);

                RealTimeSeries fixings = new RealTimeSeries(dt, qs);
                IndexManager.instance().setHistory(name2, fixings);

                return(name);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }
示例#5
0
        public static object eqInstCommodityFuture(
            [ExcelArgument(Description = "id of instrument ")] string ObjectId,
            [ExcelArgument(Description = "name of instrument ")] string name,       // given by user, could be the same as objectid
            [ExcelArgument(Description = "buy/sell (1/-1) ")] int buysell,
            [ExcelArgument(Description = "trade price ")] double tradePrice,
            [ExcelArgument(Description = "trade quantity ")] double quantity,
            [ExcelArgument(Description = "start date ")] DateTime startdate,
            [ExcelArgument(Description = "end date ")] DateTime enddate,
            [ExcelArgument(Description = "id of commodity index ")] string indexid,
            [ExcelArgument(Description = "id of discount curve ")] string discountId,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                Xl.Range                 rng           = ExcelUtil.getActiveCellRange();
                CommodityIndexExt        idx           = OHRepository.Instance.getObject <CommodityIndexExt>(indexid);
                YieldTermStructureHandle discountcurve = OHRepository.Instance.getObject <YieldTermStructureHandle>(discountId);
                Date refDate = discountcurve.referenceDate();

                EliteQuant.Date sd = EliteQuant.EQConverter.ConvertObject <EliteQuant.Date>(startdate);
                EliteQuant.Date ed = EliteQuant.EQConverter.ConvertObject <EliteQuant.Date>(enddate);

                PricingPeriodExt pp = new PricingPeriodExt(sd, ed, sd, quantity);         // pay at start date
                EnergyFutureExt  ef = new EnergyFutureExt(buysell, pp, tradePrice, idx, name, discountcurve);

                // Store the futures and return its id
                string id = "Fut@" + ObjectId;
                OHRepository.Instance.storeObject(id, ef, 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("#EQ_ERR!");
            }
        }
示例#6
0
        public static string eqIRCurveFuturesRateHelper(
            [ExcelArgument(Description = "(String) id of rate helper object ")] String ObjectId,
            [ExcelArgument(Description = "(double) quote of ED futures e.g. 99.5 ")] double price,
            [ExcelArgument(Description = "(double) convexity adjustment default 0 ")] double convadj,
            [ExcelArgument(Description = "order of ED futures start from 1 ")] int order,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                // use default value
                EliteQuant.IborIndex idx = new EliteQuant.USDLibor(new EliteQuant.Period(3, EliteQuant.TimeUnit.Months));

                EliteQuant.Date today          = EliteQuant.Settings.instance().getEvaluationDate();
                EliteQuant.Date settlementdate = idx.fixingCalendar().advance(today, (int)idx.fixingDays(), EliteQuant.TimeUnit.Days);

                EliteQuant.QuoteHandle quote_ = new EliteQuant.QuoteHandle(new EliteQuant.SimpleQuote(price));
                EliteQuant.QuoteHandle conv_  = new EliteQuant.QuoteHandle(new EliteQuant.SimpleQuote(convadj));

                EliteQuant.Date imm_startdate = EliteQuant.IMM.nextDate(settlementdate, false);
                for (int i = 0; i < order - 1; i++)
                {
                    imm_startdate = EliteQuant.IMM.nextDate(cal_usd_gbp.advance(imm_startdate, 1, EliteQuant.TimeUnit.Days), false);
                }

                EliteQuant.Date enddate = imm_startdate + 90;

                EliteQuant.RateHelper rh = new EliteQuant.FuturesRateHelper(quote_, imm_startdate, enddate, dc_act_360, conv_);

                string id = "RHED@" + ObjectId;
                OHRepository.Instance.storeObject(id, rh, 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!");
            }
        }
示例#7
0
        public static bool eqTimeIsBusinessDay(
            [ExcelArgument(Description = "Date ")] DateTime date,
            [ExcelArgument(Description = "Calendar (default NYC) ")] string calendar)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return(false);
            }

            string callerAddress = "";

            try
            {
                callerAddress = ExcelUtil.getActiveCellAddress();

                OHRepository.Instance.removeErrorMessage(callerAddress);
            }
            catch (Exception)
            {
            }
            try
            {
                if (date == DateTime.MinValue)
                {
                    throw new Exception("Date must not be empty. ");
                }
                EliteQuant.Date d = EliteQuant.EQConverter.ConvertObject <EliteQuant.Date>(date);

                if (string.IsNullOrEmpty(calendar))
                {
                    calendar = "NYC";
                }
                EliteQuant.Calendar can = EliteQuant.EQConverter.ConvertObject <EliteQuant.Calendar>(calendar);

                return(can.isBusinessDay(d));
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(false);
            }
        }
        public static object eqInstSaveIRSwapToDisk(
            [ExcelArgument(Description = "id of IR Swap ")] string tradeid,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                Xl.Range rng = ExcelUtil.getActiveCellRange();

                string genswaptplid_ = tradeid;
                if (!genswaptplid_.Contains('@'))
                {
                    genswaptplid_ = "SWP@" + genswaptplid_;
                }
                if (!genswaptplid_.Contains("_TPL"))
                {
                    genswaptplid_ = genswaptplid_ + "_TPL";
                }

                EliteQuant.Instruments.InterestRateGenericSwap genswaptpl = OHRepository.Instance.getObject <EliteQuant.Instruments.InterestRateGenericSwap>(genswaptplid_);

                string path = EliteQuant.ConfigManager.Instance.IRRootDir + @"Trades\";

                EliteQuant.Instruments.InterestRateGenericSwap.Serialize(genswaptpl,
                                                                         path + tradeid + ".xml");
                return(tradeid);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }
示例#9
0
        public static string eqIRCurveDepositRateHelper(
            [ExcelArgument(Description = "(String) id of rate helper object ")] String ObjectId,
            [ExcelArgument(Description = "(double) quote of deposit rate ")] double Quote,
            [ExcelArgument(Description = "(String) forward start month, e.g. 7D, 3M ")] String Tenor,
            [ExcelArgument(Description = "int fixingDays ")] int fixingDays,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                // use default value
                // // "london stock exchange"; "Actual/360"; "fixingDays = 2", "MF", "eom = true"
                EliteQuant.IborIndex idx_usdlibor = new EliteQuant.USDLibor(new EliteQuant.Period(3, EliteQuant.TimeUnit.Months));
                if (ExcelUtil.isNull(fixingDays))
                {
                    fixingDays = (int)idx_usdlibor.fixingDays();
                }

                EliteQuant.QuoteHandle quote_ = new EliteQuant.QuoteHandle(new EliteQuant.SimpleQuote(Quote));
                EliteQuant.Period      tenor_ = EliteQuant.EQConverter.ConvertObject <EliteQuant.Period>(Tenor);

                EliteQuant.RateHelper rh = new EliteQuant.DepositRateHelper(quote_, tenor_, (uint)fixingDays, cal_usd,
                                                                            bdc_usd, eom_usd, dc_act_360);

                string id = "RHDEP@" + ObjectId;
                OHRepository.Instance.storeObject(id, rh, 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!");
            }
        }
示例#10
0
        public static bool TestExcelType(Object obj)
        {
            if (!(obj is object[, ]))
            {
                if (obj is ExcelError || ExcelUtil.isEQError(obj))
                {
                    return(false);
                }
            }
            else
            {
                foreach (Object o in (object[, ])obj)
                {
                    if (o is ExcelError || ExcelUtil.isEQError(o))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
示例#11
0
        public static object eqTimeGetEvaluationDate()
        {
            if (ExcelUtil.CallFromWizard())
            {
                return(false);
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                Date dt = EliteQuant.Settings.instance().getEvaluationDate();
                return(EliteQuant.EQConverter.ConvertObject <DateTime>(dt));
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }
示例#12
0
        public static string eqIRCurveOISFFBasisSwapHelper(
            [ExcelArgument(Description = "(String) id of rate helper object ")] String ObjectId,
            [ExcelArgument(Description = "(double) quote of swap rate ")] double quote,
            [ExcelArgument(Description = "(double) basis spread ")] double basisspread,
            [ExcelArgument(Description = "(String) forward start month, e.g. 7D, 3M ")] String Tenor,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                // use default value. Eonia and ois has same convention
                EliteQuant.OvernightIndex idx = new EliteQuant.Eonia();

                EliteQuant.QuoteHandle rate_   = new EliteQuant.QuoteHandle(new EliteQuant.SimpleQuote(quote));
                EliteQuant.QuoteHandle spread_ = new EliteQuant.QuoteHandle(new EliteQuant.SimpleQuote(basisspread));
                EliteQuant.Period      tenor_  = EliteQuant.EQConverter.ConvertObject <EliteQuant.Period>(Tenor);
                EliteQuant.DayCounter  dc      = new EliteQuant.Actual360();

                // arithmetic average, not compounded. USBG
                EliteQuant.RateHelper rh = new EliteQuant.FixedOISBasisRateHelper(2, tenor_, spread_, rate_,
                                                                                  EliteQuant.Frequency.Quarterly, EliteQuant.BusinessDayConvention.ModifiedFollowing,
                                                                                  dc, idx, EliteQuant.Frequency.Quarterly);

                string id = "RHFFB@" + ObjectId;
                OHRepository.Instance.storeObject(id, rh, 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!");
            }
        }
示例#13
0
        public static string eqOpVersion()
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();
            OHRepository.Instance.removeErrorMessage(callerAddress);

            try
            {
                return(getVerStr());
            }
            catch (Exception exception_)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), exception_.Message);
                return("");
            }
        }
示例#14
0
        public static object eqIndexeGetHistory(
            [ExcelArgument(Description = "index name (USDOIS, USDLIB3M) ")] String name,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                if (!name.Contains('@'))
                {
                    name = "IDX@" + name;
                }

                string name2;
                name2 = EliteQuant.Curves.IndexMapping.ExtIndexName2EQName(name);
                RealTimeSeries fixings = IndexManager.instance().getHistory(name2);

                double[,] ret = new double[fixings.size(), 2];

                for (int i = 0; i < ret.GetLength(0); i++)
                {
                    ret[i, 0] = fixings.dates()[i].serialNumber();
                    ret[i, 1] = fixings.values()[i];
                }

                return(ret);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }
示例#15
0
        public static object eqTimeBusinessDaysBetween(
            [ExcelArgument(Description = "Start Date ")] DateTime date1,
            [ExcelArgument(Description = "End Date ")] DateTime date2,
            [ExcelArgument(Description = "Calendar (default NYC) ")] string calendar)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();
            OHRepository.Instance.removeErrorMessage(callerAddress);

            try
            {
                if ((date1 == DateTime.MinValue) || (date2 == DateTime.MinValue))
                {
                    throw new Exception("Date must not be empty. ");
                }
                Date start = EliteQuant.EQConverter.ConvertObject <Date>(date1);
                Date end   = EliteQuant.EQConverter.ConvertObject <Date>(date2);

                if (string.IsNullOrEmpty(calendar))
                {
                    calendar = "NYC";
                }
                EliteQuant.Calendar can = EliteQuant.EQConverter.ConvertObject <EliteQuant.Calendar>(calendar);

                return(can.businessDaysBetween(start, end, false, false));
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("");
            }
        }
示例#16
0
        public static object eqCurveCommodDisplayForwardsCurve(
            [ExcelArgument(Description = "curve id ")] string ObjectId,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                if (!ObjectId.Contains('@'))
                {
                    ObjectId = "CRV@" + ObjectId;
                }

                CommodityCurveExt curve = OHRepository.Instance.getObject <CommodityCurveExt>(ObjectId);
                DateVector        dts   = curve.dates();
                DoubleVector      pts   = curve.prices();

                double[,] ret = new double[dts.Count, 2];
                for (int i = 0; i < dts.Count; i++)
                {
                    ret[i, 0] = dts[i].serialNumber();
                    ret[i, 1] = pts[i];
                }

                return(ret);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }
示例#17
0
        public static string eqCurveIRFlatForward(
            [ExcelArgument(Description = "curve id ")] string ObjectId,
            [ExcelArgument(Description = "flat rate ")] double forward,
            [ExcelArgument(Description = "settlement days ")] int settlementdays,
            [ExcelArgument(Description = "calendar ")] string calendar,
            [ExcelArgument(Description = "day counter ")] string daycounter,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                settlementdays = 0;
                calendar       = "NULL";
                daycounter     = "Actual365Fixed";

                YieldTermStructureHandle handle = new YieldTermStructureHandle(
                    new FlatForward(0, new NullCalendar(), forward, new Actual365Fixed()));

                // Store the option and return its id
                string id = "CRV@" + ObjectId;
                OHRepository.Instance.storeObject(id, handle, 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("#EQ_ERR!");
            }
        }
示例#18
0
        public static T ConvertObject <T>(Object obj, Object defaultValue)
        {
            try
            {
                if (ExcelUtil.isNull(obj))
                {
                    if (defaultValue != null)
                    {
                        return((T)defaultValue);
                    }
                    else
                    {
                        throw new Exception(" Conversion failed. " + typeof(T).FullName);
                    }
                }

                return(EliteQuant.EQConverter.ConvertObject <T>(obj, defaultValue));
                // return default(T);
            }
            catch (System.Exception e)
            {
                throw new Exception(" Conversion failed: " + typeof(T).FullName + ", " + e.Message);
            }
        }
示例#19
0
        public static object eqTimeDateFromFuturesSymbol(
            [ExcelArgument(Description = "futures symbol (e.g. F16 ")] string fsymbol)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();
            OHRepository.Instance.removeErrorMessage(callerAddress);

            try
            {
                DateTime ret = EliteQuant.Utils.DateFromFuturesSymbol(fsymbol);
                return(ret);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("");
            }
        }
示例#20
0
        public static string eqIRCurveLiborBasisSwapHelper(
            [ExcelArgument(Description = "(String) id of rate helper object ")] String ObjectId,
            [ExcelArgument(Description = "(String) base leg (usually USDLIB3M) ")] String baseLeg,
            [ExcelArgument(Description = "(String) basis leg (USDLIB1M, USDLIB6M, etc) ")] String basisLeg,
            [ExcelArgument(Description = "(double) basis spread ")] double basis,
            [ExcelArgument(Description = "(String) basis swap tenor (1Y, 2Y, etc) ")] String tenor,
            [ExcelArgument(Description = "Discount Curve (USDLIB3M or USDOIS) ")] String discount,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                // use default value. Eonia and ois has same convention
                if (!baseLeg.Contains('@'))
                {
                    baseLeg = "IDX" + baseLeg;
                }
                EliteQuant.IborIndex baseidx  = OHRepository.Instance.getObject <EliteQuant.IborIndex>(baseLeg);
                EliteQuant.IborIndex basisidx = null;
                switch (basisLeg.ToUpper())
                {
                case "USDLIB1M":
                    basisidx = new EliteQuant.USDLibor(new EliteQuant.Period(1, EliteQuant.TimeUnit.Months));
                    break;

                case "USDLIB6M":
                    basisidx = new EliteQuant.USDLibor(new EliteQuant.Period(6, EliteQuant.TimeUnit.Months));
                    break;

                case "USDLIB12M":
                    basisidx = new EliteQuant.USDLibor(new EliteQuant.Period(12, EliteQuant.TimeUnit.Months));
                    break;

                default:
                    break;
                }

                EliteQuant.YieldTermStructure       curve = null;
                EliteQuant.YieldTermStructureHandle yth   = null;

                if (!discount.Contains('@'))
                {
                    discount = "CRV@" + discount;
                }
                if (!ExcelUtil.isNull(discount))
                {
                    curve = OHRepository.Instance.getObject <EliteQuant.YieldTermStructure>(discount);
                    yth   = new EliteQuant.YieldTermStructureHandle(curve);
                }

                EliteQuant.QuoteHandle basis_ = new EliteQuant.QuoteHandle(new EliteQuant.SimpleQuote(basis));
                EliteQuant.Period      tenor_ = EliteQuant.EQConverter.ConvertObject <EliteQuant.Period>(tenor);

                // arithmetic average, not compounded. USBG
                EliteQuant.RateHelper rh = new EliteQuant.IBORBasisRateHelper(2, tenor_, basis_, baseidx, basisidx, yth);

                string id = "RHBAS@" + ObjectId;
                OHRepository.Instance.storeObject(id, rh, 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!");
            }
        }
示例#21
0
        public static string eqCurveIRIndex(
            [ExcelArgument(Description = "index id (USDOIS, USDLIB3M, USDLIB1M ")] string ObjectId,
            [ExcelArgument(Description = "currency (USD, GBP, CAD, EUR, JPY ) ")] string Curncy,
            [ExcelArgument(Description = "id or name of discount curve ")] string discountId,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                if (!discountId.Contains('@'))
                {
                    discountId = "CRV@" + discountId;
                }
                EliteQuant.YieldTermStructure curve = OHRepository.Instance.getObject <EliteQuant.YieldTermStructure>(discountId);
                YieldTermStructureHandle      h     = new YieldTermStructureHandle(curve);

                // market defaults
                IborIndex idx_default;
                if (ObjectId == "USDOIS")       //
                {
                    // Eonia and ois shares defaults
                    //idx_default = new Eonia(h);
                    //idx_default = new OvernightIndex("USDOIS", 0, new USDCurrency(), new TARGET(), new Actual360(), h);
                    idx_default = new FedFunds(h);
                }
                else
                {
                    Period tenor = null;
                    switch (ObjectId)
                    {
                    case "USDLIB3M":
                        tenor = new Period(3, TimeUnit.Months);
                        break;

                    case "USDLIB1M":
                        tenor = new Period(1, TimeUnit.Months);
                        break;

                    case "USDLIB6M":
                        tenor = new Period(6, TimeUnit.Months);
                        break;

                    case "USDLIB12M":
                        tenor = new Period(12, TimeUnit.Months);
                        break;
                    }
                    idx_default = new USDLibor(tenor, h);
                }

                // Store the option and return its id
                string id = "IDX@" + ObjectId;
                OHRepository.Instance.storeObject(id, idx_default, 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("#EQ_ERR!");
            }
        }
示例#22
0
        public static string eqIRCurveSwapRateHelper(
            [ExcelArgument(Description = "(String) id of rate helper object ")] String ObjectId,
            [ExcelArgument(Description = "(double) quote of swap rate ")] double quote,
            [ExcelArgument(Description = "(String) forward start month, e.g. 7D, 3M ")] String Tenor,
            [ExcelArgument(Description = " spread ")] double spread,
            [ExcelArgument(Description = " name of swap curve(USDLIB3M, USDLIB1M, USDLIB6M, USDLIB12M) ")] string idx,
            [ExcelArgument(Description = " id of discount curve (USDOIS) ")] string discount,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                // use default value
                EliteQuant.IborIndex idx_usdlibor = null;

                EliteQuant.QuoteHandle rate_  = new EliteQuant.QuoteHandle(new EliteQuant.SimpleQuote(quote));
                EliteQuant.Period      tenor_ = EliteQuant.EQConverter.ConvertObject <EliteQuant.Period>(Tenor);

                if (ExcelUtil.isNull(spread))
                {
                    spread = 0.0;
                }
                EliteQuant.QuoteHandle spread_ = new EliteQuant.QuoteHandle(new EliteQuant.SimpleQuote(spread));

                EliteQuant.RateHelper rh = null;

                if (ExcelUtil.isNull(idx))
                {
                    idx_usdlibor = new EliteQuant.USDLibor(new EliteQuant.Period(3, EliteQuant.TimeUnit.Months));
                }
                else
                {
                    switch (idx)
                    {
                    case "USDLIB1M":
                        idx_usdlibor = new EliteQuant.USDLibor(new EliteQuant.Period(1, EliteQuant.TimeUnit.Months));
                        break;

                    case "USDLIB6M":
                        idx_usdlibor = new EliteQuant.USDLibor(new EliteQuant.Period(6, EliteQuant.TimeUnit.Months));
                        break;

                    case "USDLIB12M":
                        idx_usdlibor = new EliteQuant.USDLibor(new EliteQuant.Period(12, EliteQuant.TimeUnit.Months));
                        break;

                    default:
                        idx_usdlibor = new EliteQuant.USDLibor(new EliteQuant.Period(3, EliteQuant.TimeUnit.Months));
                        break;
                    }
                }

                if (ExcelUtil.isNull(discount))
                {
                    rh = new EliteQuant.SwapRateHelper(rate_, tenor_,
                                                       cal_usd_gbp, EliteQuant.Frequency.Semiannual, bdc_usd, dc_30_360, idx_usdlibor);
                }
                else
                {
                    if (!discount.Contains('@'))
                    {
                        discount = "CRV@" + discount;
                    }

                    EliteQuant.YieldTermStructure       curve = OHRepository.Instance.getObject <EliteQuant.YieldTermStructure>(discount);
                    EliteQuant.YieldTermStructureHandle yth   = new EliteQuant.YieldTermStructureHandle(curve);
                    rh = new EliteQuant.SwapRateHelper(rate_, tenor_,
                                                       cal_usd_gbp, EliteQuant.Frequency.Semiannual, bdc_usd, dc_30_360,
                                                       idx_usdlibor, spread_, new EliteQuant.Period(0, EliteQuant.TimeUnit.Days), yth);
                }

                string id = "RHSWP@" + ObjectId;
                OHRepository.Instance.storeObject(id, rh, 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!");
            }
        }
示例#23
0
        public static string eqCurveIRIndex2(
            [ExcelArgument(Description = "index id (USDOIS, USDLIB3M, USDLIB1M ")] string ObjectId,
            [ExcelArgument(Description = "currency (USD, GBP, CAD, EUR, JPY ) ")] string Curncy,
            [ExcelArgument(Description = "tenors ")] object[] dates,
            [ExcelArgument(Description = "discounts ")] double[] discounts,
            [ExcelArgument(Description = "calendar ")] string calendar,
            [ExcelArgument(Description = "day counter ")] string daycounter,
            [ExcelArgument(Description = "id of discount curve ")] string discountId,
            [ExcelArgument(Description = "Interpolation Method (Linear, LogLinear) ")] string interp,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                calendar   = "NULL";
                daycounter = "Actual365Fixed";

                if (dates.Length != discounts.Length)
                {
                    return("size mismatch");
                }

                string interpmethod;
                if (ExcelUtil.isNull(interp))
                {
                    interpmethod = "LOGLINEAR";
                }
                else
                {
                    interpmethod = interp.ToUpper();
                }

                DateVector   datesvector     = new DateVector(dates.Length);
                DoubleVector discountsvector = new DoubleVector(dates.Length);

                for (int i = 0; i < dates.Length; i++)
                {
                    //datesvector.Add(Conversion.ConvertObject<Date>((DateTime)dates[i], "NA"));
                    datesvector.Add(new Date(Convert.ToInt32(dates[i])));
                    discountsvector.Add(discounts[i]);
                }

                YieldTermStructureHandle handle = null;
                if (interpmethod == "LINEAR")
                {
                    handle = new YieldTermStructureHandle(
                        new LinearDiscountCurve(datesvector, discountsvector, new Actual365Fixed(), new NullCalendar()));
                }
                else
                {
                    handle = new YieldTermStructureHandle(
                        new DiscountCurve(datesvector, discountsvector, new Actual365Fixed(), new NullCalendar()));
                }

                // Store the option and return its id
                string id = "CRV@" + ObjectId;
                OHRepository.Instance.storeObject(id, handle, 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("#EQ_ERR!");
            }
        }
示例#24
0
        public static object eqIRCurveSaveCurveToDisk(
            [ExcelArgument(Description = "asofdate ")] DateTime asofdate,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                Xl.Range rng = ExcelUtil.getActiveCellRange();
                if (ExcelUtil.isNull(asofdate))
                {
                    asofdate = DateTime.Today;
                }

                string[] curves = new string[] { "USDOIS", "USDLIB3M", "USDLIB1M", "USDLIB6M", "USDLIB12M" };
                string   path;
                foreach (var s in curves)
                {
                    string targetcurve;
                    if (s.Contains("@"))
                    {
                        targetcurve = s;
                    }
                    else
                    {
                        targetcurve = "CRV@" + s;
                    }

                    EliteQuant.YieldTermStructure curve = OHRepository.Instance.getObject <EliteQuant.YieldTermStructure>(targetcurve);
                    if (curve.GetType() == typeof(EliteQuant.DiscountCurve))
                    {
                        asofdate = EliteQuant.EQConverter.DateToDateTime((curve as DiscountCurve).dates()[0]);
                        string[] ret = new string[(curve as DiscountCurve).dates().Count];
                        for (int i = 0; i < (curve as DiscountCurve).dates().Count; i++)
                        {
                            ret[i] = (curve as DiscountCurve).dates()[i].serialNumber() + "," + (curve as DiscountCurve).discounts()[i].ToString();
                        }

                        path = EliteQuant.ConfigManager.Instance.IRRootDir + @"Curves\"
                               + EliteQuant.EQConverter.DateTimeToString(EliteQuant.EQConverter.DateToDateTime((curve as DiscountCurve).dates()[0])) + "\\";
                        if (!System.IO.Directory.Exists(path))
                        {
                            System.IO.Directory.CreateDirectory(path);
                        }

                        System.IO.File.WriteAllLines(path + s + ".csv", ret);
                    }
                    else if (curve.GetType() == typeof(EliteQuant.LinearDiscountCurve))
                    {
                        asofdate = EliteQuant.EQConverter.DateToDateTime((curve as LinearDiscountCurve).dates()[0]);
                        string[] ret = new string[(curve as LinearDiscountCurve).dates().Count];
                        for (int i = 0; i < (curve as LinearDiscountCurve).dates().Count; i++)
                        {
                            ret[i] = (curve as LinearDiscountCurve).dates()[i].serialNumber() + "," + (curve as LinearDiscountCurve).discounts()[i].ToString();
                        }

                        path = EliteQuant.ConfigManager.Instance.IRRootDir + @"Curves\"
                               + EliteQuant.EQConverter.DateTimeToString(EliteQuant.EQConverter.DateToDateTime((curve as LinearDiscountCurve).dates()[0])) + "\\";
                        if (!System.IO.Directory.Exists(path))
                        {
                            System.IO.Directory.CreateDirectory(path);
                        }

                        System.IO.File.WriteAllLines(path + s + ".csv", ret);
                    }
                }

                return(asofdate);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }
示例#25
0
        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);
            }
        }
示例#26
0
        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!");
            }
        }
示例#27
0
        public static object eqInstCommodityVanillaSwap(
            [ExcelArgument(Description = "id of instrument ")] string ObjectId,
            [ExcelArgument(Description = "name of instrument ")] string name,
            [ExcelArgument(Description = "payer/receiver (1/0) ")] bool payer,
            [ExcelArgument(Description = "trade price ")] double fixedPrice,
            [ExcelArgument(Description = "trade quantity ")] double[] quantities,
            [ExcelArgument(Description = "start date ")] object[] startdates,
            [ExcelArgument(Description = "end date ")] object[] enddates,
            [ExcelArgument(Description = "id of commodity index ")] string indexid,
            [ExcelArgument(Description = "id of discount curve ")] string discountId,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                //bool ispayer = string.Compare(payer.ToUpper(), "PAYER") == 0 ? true : false;
                bool ispayer = payer;
                if (startdates.Length != enddates.Length)
                {
                    return("size mismatch");
                }

                Xl.Range                 rng           = ExcelUtil.getActiveCellRange();
                CommodityIndexExt        idx           = OHRepository.Instance.getObject <CommodityIndexExt>(indexid);
                YieldTermStructureHandle discountcurve = OHRepository.Instance.getObject <YieldTermStructureHandle>(discountId);
                Date refDate = discountcurve.referenceDate();

                PricingPeriodExts pps = new PricingPeriodExts(startdates.Length);

                for (int i = 0; i < startdates.Length; i++)
                {
                    if (ExcelUtil.isNull(startdates[i]))
                    {
                        continue;
                    }

                    //EliteQuant.Date sd = Conversion.ConvertObject<EliteQuant.Date>((DateTime)startdates[i], "date");
                    //EliteQuant.Date ed = Conversion.ConvertObject<EliteQuant.Date>((DateTime)enddates[i], "date");
                    Date sd = new Date(Convert.ToInt32(startdates[i]));
                    Date ed = new Date(Convert.ToInt32(enddates[i]));

                    PricingPeriodExt pp = new PricingPeriodExt(sd, ed, sd, quantities[i]);
                    pps.Add(pp);
                }

                EnergyVanillaSwapExt evs = new EnergyVanillaSwapExt(ispayer, fixedPrice, idx, pps, name, discountcurve, discountcurve,
                                                                    Frequency.Monthly, new NullCalendar());

                // Store the futures and return its id
                string id = "Swp@" + ObjectId;
                OHRepository.Instance.storeObject(id, evs, 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("#EQ_ERR!");
            }
        }
示例#28
0
        public static object eqIRCurveLoadCurveFromDisk(
            [ExcelArgument(Description = "asofdate ")] DateTime asofdate,
            [ExcelArgument(Description = "Interpolation Method (Linear, LogLinear) ")] string interp,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                Xl.Range rng = ExcelUtil.getActiveCellRange();
                if (ExcelUtil.isNull(asofdate))
                {
                    asofdate = DateTime.Today;
                }

                string[]             curves = new string[] { "USDOIS", "USDLIB3M", "USDLIB1M", "USDLIB6M", "USDLIB12M" };
                string               path;
                EliteQuant.IborIndex idx = new EliteQuant.USDLibor(new EliteQuant.Period(3, EliteQuant.TimeUnit.Months));

                foreach (var s in curves)
                {
                    string targetcurve;
                    if (s.Contains("@"))
                    {
                        targetcurve = s;
                    }
                    else
                    {
                        targetcurve = "CRV@" + s;
                    }

                    string interpmethod;
                    if (ExcelUtil.isNull(interp))
                    {
                        interpmethod = "LOGLINEAR";
                    }
                    else
                    {
                        interpmethod = interp.ToUpper();
                    }

                    path = EliteQuant.ConfigManager.Instance.IRRootDir + @"Curves\"
                           + EliteQuant.EQConverter.DateTimeToString(asofdate) + "\\";

                    string[] crv = System.IO.File.ReadAllLines(path + s + ".csv");

                    EliteQuant.DateVector   dtv   = new EliteQuant.DateVector();
                    EliteQuant.DoubleVector discv = new EliteQuant.DoubleVector();
                    foreach (var c in crv)
                    {
                        string[] cc = c.Split(',');
                        Date     dt = new Date(Convert.ToInt32(cc[0]));
                        dtv.Add(dt);
                        discv.Add(Convert.ToDouble(cc[1]));
                    }

                    YieldTermStructure yth = null;

                    if (interpmethod == "LINEAR")
                    {
                        yth = new EliteQuant.LinearDiscountCurve(dtv, discv, idx.dayCounter(), idx.fixingCalendar());
                    }
                    else
                    {
                        yth = new EliteQuant.DiscountCurve(dtv, discv, idx.dayCounter(), idx.fixingCalendar());
                    }

                    string targetcrvid = "CRV@" + s;
                    OHRepository.Instance.storeObject(targetcrvid, yth, callerAddress);     // callerAddress or null ?
                }

                return(asofdate);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }
示例#29
0
        public static object eqTimeSchedule(
            [ExcelArgument(Description = "Start Date ")] DateTime date1,
            [ExcelArgument(Description = "End Date ")] DateTime date2,
            [ExcelArgument(Description = "Tenor (e.g. '3D' or '2Y') ")] string tenor,
            [ExcelArgument(Description = "Calendar (default NYC) ")] string calendar,
            [ExcelArgument(Description = "BusinessDayConvention (default ModifiedFollowing) ")] string bdc,
            [ExcelArgument(Description = "DateGenerationRule (default Backward) ")] string rule,
            [ExcelArgument(Description = "is endofmonth ")] bool eom)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();
            OHRepository.Instance.removeErrorMessage(callerAddress);

            try
            {
                if ((date1 == DateTime.MinValue) || (date2 == DateTime.MinValue))
                {
                    throw new Exception("Date must not be empty. ");
                }
                Date start = EliteQuant.EQConverter.ConvertObject <Date>(date1);
                Date end   = EliteQuant.EQConverter.ConvertObject <Date>(date2);

                EliteQuant.Period period = EliteQuant.EQConverter.ConvertObject <EliteQuant.Period>(tenor);

                if (string.IsNullOrEmpty(calendar))
                {
                    calendar = "NYC";
                }
                EliteQuant.Calendar can = EliteQuant.EQConverter.ConvertObject <EliteQuant.Calendar>(calendar);

                if (string.IsNullOrEmpty(bdc))
                {
                    bdc = "MF";
                }
                BusinessDayConvention bdc2 = EliteQuant.EQConverter.ConvertObject <BusinessDayConvention>(bdc);

                if (string.IsNullOrEmpty(rule))
                {
                    rule = "BACKWARD";
                }
                DateGeneration.Rule rule2 = EliteQuant.EQConverter.ConvertObject <DateGeneration.Rule>(rule);

                Schedule sch = new Schedule(start, end, period, can, bdc2, bdc2, rule2, eom);

                object[,] ret = new object[sch.size(), 1];
                for (uint i = 0; i < sch.size(); i++)
                {
                    ret[i, 0] = sch.date(i).serialNumber();
                }

                return(ret);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("");
            }
        }
示例#30
0
        public static string eqModelDoubleExponentialATM(
            [ExcelArgument(Description = "id of option to be constructed ")] string ObjectId,
            [ExcelArgument(Description = "expiry (years of fraction ")] double[] tenors,
            [ExcelArgument(Description = "implied vols ")] double[] volatilities,
            [ExcelArgument(Description = "initial parameters ")] double[] initials,
            [ExcelArgument(Description = "calibrate or not ")] bool calibrate,
            [ExcelArgument(Description = "parameter fixed? ")] bool issigmafixed,
            [ExcelArgument(Description = "parameter fixed? ")] bool isb1fixed,
            [ExcelArgument(Description = "parameter fixed? ")] bool isb2fixed,
            [ExcelArgument(Description = "parameter fixed? ")] bool islambdafixed,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                if (tenors.Length != volatilities.Length)
                {
                    throw new Exception("double exponential input lengths don't match.");
                }

                if (ExcelUtil.isNull(calibrate))
                {
                    calibrate = true;
                }
                if (ExcelUtil.isNull(issigmafixed))
                {
                    issigmafixed = false;
                }
                if (ExcelUtil.isNull(isb1fixed))
                {
                    isb1fixed = false;
                }
                if (ExcelUtil.isNull(isb2fixed))
                {
                    isb2fixed = false;
                }
                if (ExcelUtil.isNull(islambdafixed))
                {
                    islambdafixed = false;
                }

                DoubleVector tt   = new DoubleVector(tenors.Length);
                DoubleVector vols = new DoubleVector(volatilities.Length);

                for (uint i = 0; i < tenors.Length; i++)
                {
                    if ((ExcelUtil.isNull(tenors[i])) || (tenors[i] == 0))
                    {
                        continue;
                    }

                    tt.Add(tenors[i]);
                    vols.Add(volatilities[i]);
                }

                DoubleExponentialCalibration atmvol;
                if ((initials.Length == 4) && (initials != null))
                {
                    atmvol = new DoubleExponentialCalibration(tt, vols, initials[0], initials[1], initials[2], initials[3],
                                                              issigmafixed, isb1fixed, isb2fixed, islambdafixed);
                }
                else
                {
                    atmvol = new DoubleExponentialCalibration(tt, vols);
                }

                if (calibrate)
                {
                    atmvol.compute();
                }

                // Store the option and return its id
                string id = "MODEL@" + ObjectId;
                OHRepository.Instance.storeObject(id, atmvol, 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);
            }
        }