示例#1
0
        public static string eqCurveCommodForwardsCurve(
            [ExcelArgument(Description = "curve id ")] string ObjectId,
            [ExcelArgument(Description = "curve name (eg. commod ng exchange) ")] string curvename,
            [ExcelArgument(Description = "tenors ")] object[] dates,
            [ExcelArgument(Description = "quotes ")] double[] quotes,
            [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
            {
                calendar   = "NULL";
                daycounter = "Actual365Fixed";

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

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

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

                    //datesvector.Add(Conversion.ConvertObject<Date>((DateTime)dates[i], "NA"));
                    datesvector.Add(new Date(Convert.ToInt32(dates[i])));
                    quotesvector.Add(quotes[i]);
                }

                CommodityCurveExt curve =
                    new CommodityCurveExt(curvename, datesvector, quotesvector, new NullCalendar(), new Actual365Fixed());

                // Store the curve and return its id
                string id = "CRV@" + ObjectId;
                OHRepository.Instance.storeObject(id, curve, 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!");
            }
        }
示例#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 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!");
            }
        }
示例#4
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);
            }
        }
示例#5
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!");
            }
        }
示例#6
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);
            }
        }
示例#7
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);
            }
        }
示例#8
0
        public static string eqInstAmericanOptionBaroneAdesiWhaley(
            [ExcelArgument(Description = "id of option to be constructed ")] string ObjectId,
            [ExcelArgument(Description = "Option type ")] string optype,
            [ExcelArgument(Description = "Spot price ")] double underlyingprice,
            [ExcelArgument(Description = "Strike price ")] double stirkeprice,
            [ExcelArgument(Description = "Expiry Date ")] DateTime date,
            [ExcelArgument(Description = "Risk free rate ")] double riskfreerate,
            [ExcelArgument(Description = "dividend/convenience rate ")] double dividendrate,
            [ExcelArgument(Description = "Black-Scholes Vol ")] double volatility,
            [ExcelArgument(Description = "DayCounter ")] string daycounter,
            [ExcelArgument(Description = "Calendar ")] string calendar,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                if (date == DateTime.MinValue)
                {
                    throw new Exception("Date must not be empty. ");
                }

                if (ExcelUtil.isNull(daycounter))
                {
                    daycounter = "ACTUAL365";
                }
                if (ExcelUtil.isNull(calendar))
                {
                    calendar = "NYC";
                }

                Option.Type optiontype;
                if (optype.ToUpper() == "CALL")
                {
                    optiontype = Option.Type.Call;
                }
                else if (optype.ToUpper() == "PUT")
                {
                    optiontype = Option.Type.Put;
                }
                else
                {
                    throw new Exception("Unknow option type");
                }

                EliteQuant.Calendar   cal          = EliteQuant.EQConverter.ConvertObject <EliteQuant.Calendar>(calendar);
                EliteQuant.DayCounter dc           = EliteQuant.EQConverter.ConvertObject <EliteQuant.DayCounter>(daycounter);
                EliteQuant.Date       maturitydate = EliteQuant.EQConverter.ConvertObject <EliteQuant.Date>(date);

                EliteQuant.Date today          = EliteQuant.Settings.instance().getEvaluationDate();
                EliteQuant.Date settlementdate = today;           // T+2
                if (maturitydate.serialNumber() <= today.serialNumber())
                {
                    throw new Exception("Option already expired.");
                }

                AmericanExercise americanExercise = new AmericanExercise(today, maturitydate);

                QuoteHandle underlyingQuoteH = new QuoteHandle(new EliteQuant.SimpleQuote(underlyingprice));

                YieldTermStructureHandle flatRateTSH = new YieldTermStructureHandle(
                    new FlatForward(settlementdate, riskfreerate, dc));
                YieldTermStructureHandle flatDividendTSH = new YieldTermStructureHandle(
                    new FlatForward(settlementdate, dividendrate, dc));

                BlackVolTermStructureHandle flatVolTSH = new BlackVolTermStructureHandle(
                    new BlackConstantVol(settlementdate, cal, volatility, dc));

                BlackScholesMertonProcess stochasticProcess = new BlackScholesMertonProcess(underlyingQuoteH,
                                                                                            flatDividendTSH, flatRateTSH, flatVolTSH);

                PlainVanillaPayoff payoff = new PlainVanillaPayoff(optiontype, stirkeprice);

                VanillaOption europeanOption = new VanillaOption(payoff, americanExercise);

                europeanOption.setPricingEngine(new BaroneAdesiWhaleyEngine(stochasticProcess));

                // Store the option and return its id
                string id = "OPTION@" + ObjectId;
                OHRepository.Instance.storeObject(id, europeanOption, 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!");
            }
        }
示例#9
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!");
            }
        }
示例#10
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);
            }
        }
示例#11
0
        public static object eqInstGetInstrumentNPV(
            [ExcelArgument(Description = "id of instrument ")] string ObjectId,
            [ExcelArgument(Description = "Greek type ")] string gtype,
            [ExcelArgument(Description = "is genericswap ")] bool isgenswap,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

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

                bool isgenswap_ = false;
                if (ExcelUtil.isNull(isgenswap))
                {
                    isgenswap_ = false;
                }
                else
                {
                    isgenswap_ = (bool)isgenswap;
                }

                Instrument inst = null;
                if (isgenswap_)
                {
                    EliteQuant.Instruments.InterestRateGenericSwap genswap = OHRepository.Instance.getObject <EliteQuant.Instruments.InterestRateGenericSwap>(ObjectId);
                    inst = genswap.eqswap_;
                }
                else
                {
                    inst = OHRepository.Instance.getObject <Instrument>(ObjectId);
                }


                double ret = inst.NPV();

                Type type = inst.GetType();
                if (type == typeof(VanillaSwap))
                {
                    if (gtype.ToUpper() == "FAIRRATE")
                    {
                        ret = (inst as VanillaSwap).fairRate();
                    }
                }
                else if (type == typeof(OvernightIndexedSwap))
                {
                    if (gtype.ToUpper() == "FAIRRATE")
                    {
                        ret = (inst as OvernightIndexedSwap).fairRate();
                    }
                }
                else if (type == typeof(EliteQuant.Instruments.InterestRateGenericSwap))
                {
                    if (gtype.ToUpper() == "FAIRRATE")
                    {
                        ret = (inst as GenericSwap).fairRate();
                    }
                    else if (gtype.ToUpper() == "FAIRSPREAD")
                    {
                        ret = (inst as GenericSwap).fairSpread();
                    }
                    else if (gtype.ToUpper() == "FIRSTLEGBPS")
                    {
                        ret = (inst as GenericSwap).firstLegBPS();
                    }
                    else if (gtype.ToUpper() == "SECONDLEGBPS")
                    {
                        ret = (inst as GenericSwap).secondLegBPS();
                    }
                }

                return(ret);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }
示例#12
0
        public static object eqInstGetOptionGreeks(
            [ExcelArgument(Description = "id of option ")] string ObjectId,
            [ExcelArgument(Description = "Greek type ")] string gtype,
            [ExcelArgument(Description = "Option type (VANILLA or MULTIASSET)")] string otype,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

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

                if (ExcelUtil.isNull(gtype))
                {
                    gtype = "NPV";
                }
                if (ExcelUtil.isNull(otype))
                {
                    otype = "VANILLA";
                }

                if (otype == "VANILLA")
                {
                    VanillaOption option = OHRepository.Instance.getObject <VanillaOption>(ObjectId);
                    switch (gtype.ToUpper())
                    {
                    case "NPV":
                        return(option.NPV());

                    case "DELTA":
                        return(option.delta());

                    case "GAMMA":
                        return(option.gamma());

                    case "VEGA":
                        return(option.vega());

                    case "THETA":
                        return(option.theta());

                    case "RHO":
                        return(option.rho());

                    default:
                        return(0);
                    }
                }
                else if (otype == "MULTIASSET")
                {
                    BasketOption option = OHRepository.Instance.getObject <BasketOption>(ObjectId);
                    switch (gtype.ToUpper())
                    {
                    case "NPV":
                        return(option.NPV());

                    case "DELTA":
                        return(option.delta());

                    case "GAMMA":
                        return(option.gamma());

                    case "VEGA":
                        return(option.vega());

                    case "THETA":
                        return(option.theta());

                    case "RHO":
                        return(option.rho());

                    default:
                        return(0);
                    }
                }
                else
                {
                    return("Unknown option type");
                }
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }
示例#13
0
        public static string eqInstSpreadOptionMonteCarlo(
            [ExcelArgument(Description = "id of option to be constructed ")] string ObjectId,
            [ExcelArgument(Description = "Option type (Call/Put) ")] string optype,
            [ExcelArgument(Description = "Spot price leg 1")] double spot1,
            [ExcelArgument(Description = "Spot price leg 2")] double spot2,
            [ExcelArgument(Description = "Strike price ")] double stirkeprice,
            [ExcelArgument(Description = "Expiry Date ")] DateTime exdate,
            [ExcelArgument(Description = "Risk free rate ")] double riskfreerate,
            [ExcelArgument(Description = "Black-Scholes Vol for leg 1 ")] double vol1,
            [ExcelArgument(Description = "Black-Scholes Vol for leg 2 ")] double vol2,
            [ExcelArgument(Description = "correlation between leg 1 and leg 2 ")] double corr,
            [ExcelArgument(Description = "DayCounter ")] string daycounter,
            [ExcelArgument(Description = "Calendar ")] string calendar,
            [ExcelArgument(Description = "Pseudorandom (pr) or lowdiscrepancy (ld) ")] string traits,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                if (exdate == DateTime.MinValue)
                {
                    throw new Exception("Date must not be empty. ");
                }

                if (ExcelUtil.isNull(daycounter))
                {
                    daycounter = "ACTUAL365";
                }
                if (ExcelUtil.isNull(calendar))
                {
                    calendar = "NYC";
                }
                if (ExcelUtil.isNull(traits))
                {
                    traits = "pr";
                }

                Option.Type optiontype;
                if (optype.ToUpper() == "CALL")
                {
                    optiontype = Option.Type.Call;
                }
                else if (optype.ToUpper() == "PUT")
                {
                    optiontype = Option.Type.Put;
                }
                else
                {
                    throw new Exception("Unknow option type");
                }

                EliteQuant.Calendar   cal          = EliteQuant.EQConverter.ConvertObject <EliteQuant.Calendar>(calendar);
                EliteQuant.DayCounter dc           = EliteQuant.EQConverter.ConvertObject <EliteQuant.DayCounter>(daycounter);
                EliteQuant.Date       maturitydate = EliteQuant.EQConverter.ConvertObject <EliteQuant.Date>(exdate);

                EliteQuant.Date today          = EliteQuant.Settings.instance().getEvaluationDate();
                EliteQuant.Date settlementdate = today;           // T+2
                if (maturitydate.serialNumber() <= today.serialNumber())
                {
                    throw new Exception("Option already expired.");
                }


                YieldTermStructureHandle rTSH = new YieldTermStructureHandle(
                    new FlatForward(settlementdate, riskfreerate, dc));
                BlackVolTermStructureHandle flatVolTSH1 = new BlackVolTermStructureHandle(
                    new BlackConstantVol(settlementdate, cal, vol1, dc));
                BlackVolTermStructureHandle flatVolTSH2 = new BlackVolTermStructureHandle(
                    new BlackConstantVol(settlementdate, cal, vol2, dc));

                Quote       qh1 = new SimpleQuote(spot1);
                Quote       qh2 = new SimpleQuote(spot2);
                QuoteHandle s1  = new QuoteHandle(qh1);
                QuoteHandle s2  = new QuoteHandle(qh2);

                BlackProcess p1 = new BlackProcess(s1, rTSH, flatVolTSH1);
                BlackProcess p2 = new BlackProcess(s2, rTSH, flatVolTSH2);

                StochasticProcessVector spv = new StochasticProcessVector(2);
                spv.Add(p1);
                spv.Add(p2);

                Matrix corrmtrx = new Matrix(2, 2);
                corrmtrx.set(0, 0, 1.0); corrmtrx.set(1, 1, 1.0);
                corrmtrx.set(0, 1, corr); corrmtrx.set(1, 0, corr);
                StochasticProcessArray spa = new StochasticProcessArray(spv, corrmtrx);

                PricingEngine engine = new MCEuropeanBasketEngine(spa, traits, 100, 1, false, true, 5000, 1e-6);

                Payoff payoff1 = new PlainVanillaPayoff(optiontype, stirkeprice);
                Payoff payoff2 = new SpreadBasketPayoff(payoff1);

                Exercise exercise = new EuropeanExercise(maturitydate);

                BasketOption bo = new BasketOption(payoff2, exercise);

                bo.setPricingEngine(engine);

                // Store the option and return its id
                string id = "OPTION@" + ObjectId;
                OHRepository.Instance.storeObject(id, bo, 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!");
            }
        }
示例#14
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!");
            }
        }
示例#15
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!");
            }
        }
示例#16
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!");
            }
        }
        public static object eqInstIRGenericSwap(
            // trade info

            /*[ExcelArgument(Description = "trade id ")] string tradeid,
             * [ExcelArgument(Description = "Entity ")] string entity,
             * [ExcelArgument(Description = "Entity ID ")] string entityid,
             * [ExcelArgument(Description = "Counterparty ")] string counterparty,
             * [ExcelArgument(Description = "Counterparty ID ")] string counterpartyid,
             * [ExcelArgument(Description = "swap type ")] string swaptype,
             * [ExcelArgument(Description = "Fixing Days ")] object fixingdays,        // use object to catch missing
             * [ExcelArgument(Description = "Trade Date ")] object tradedate,
             * [ExcelArgument(Description = "Start date ")] object startdate,
             * [ExcelArgument(Description = "Maturity date ")] object maturitydate,
             * [ExcelArgument(Description = "Tenor ")] string Tenor,
             * [ExcelArgument(Description = "is notional schedule given ")] bool isschedulegiven,*/
            [ExcelArgument(Description = "swap type ")] object[] tradeinfo,
            // first leg

            /*[ExcelArgument(Description = "id of first leg index ")] string firstlegindex,
             * [ExcelArgument(Description = "first leg frequency ")] string firstlegfreq,
             * [ExcelArgument(Description = "first leg convention ")] string firstlegconv,
             * [ExcelArgument(Description = "first leg calendar ")] string firstlegcalendar,
             * [ExcelArgument(Description = "first leg day counter ")] string firstlegdc,
             * [ExcelArgument(Description = "first leg date generation rule ")] string firstlegdgrule,
             * [ExcelArgument(Description = "first leg end of month ")] bool firstlegeom,
             * [ExcelArgument(Description = "first leg fixed rate ")] double firstlegrate,*/
            [ExcelArgument(Description = "first leg info ")] object[] firstleginfo,
            [ExcelArgument(Description = "first leg notional(s) ")] object[] firstlegnotionals,     // only object[] works
            [ExcelArgument(Description = "first leg schedule(s) ")] object[,] firstlegschedule,
            // second leg

            /*[ExcelArgument(Description = "id of second leg index ")] string secondlegindex,
             * [ExcelArgument(Description = "second leg frequency  ")] string secondlegfreq,
             * [ExcelArgument(Description = "second leg convention ")] string secondlegconv,
             * [ExcelArgument(Description = "second leg calendar ")] string secondlegcalendar,
             * [ExcelArgument(Description = "second leg day counter ")] string secondlegdc,
             * [ExcelArgument(Description = "second leg date generation rule ")] string secondlegdgrule,
             * [ExcelArgument(Description = "second leg end of month ")] bool secondlegeom,
             * [ExcelArgument(Description = "second leg spread ")] double secondlegspread,*/
            [ExcelArgument(Description = "second leg info ")] object[] secondleginfo,
            [ExcelArgument(Description = "second leg notional(s) ")] object[] secondlegnotionals,
            [ExcelArgument(Description = "second leg schedule(s) ")] object[,] secondlegschedule,
            [ExcelArgument(Description = "id of discount curve ")] string discountId
            )
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

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

                EliteQuant.Instruments.InterestRateGenericSwap genswap = new EliteQuant.Instruments.InterestRateGenericSwap();

                #region parameters
                if (ExcelUtil.isNull(tradeinfo[0]))
                {
                    return("#EQ_ERR!");
                }
                else
                {
                    genswap.ContractId = (string)tradeinfo[0];
                }

                if (ExcelUtil.isNull(tradeinfo[1]))
                {
                    genswap.Entity = "NA";
                }
                else
                {
                    genswap.Entity = (string)tradeinfo[1];
                }

                if (ExcelUtil.isNull(tradeinfo[2]))
                {
                    genswap.EntityID = "NA";
                }
                else
                {
                    genswap.EntityID = (string)tradeinfo[2];
                }

                if (ExcelUtil.isNull(tradeinfo[3]))
                {
                    genswap.Counterparty = "NA";
                }
                else
                {
                    genswap.Counterparty = (string)tradeinfo[3];
                }

                if (ExcelUtil.isNull(tradeinfo[4]))
                {
                    genswap.CounterpartyID = "NA";
                }
                else
                {
                    genswap.CounterpartyID = (string)tradeinfo[4];
                }

                if (ExcelUtil.isNull(tradeinfo[5]))
                {
                    genswap.SwapType = "Payer";
                }
                else
                {
                    genswap.SwapType = (string)tradeinfo[5];
                }

                if (ExcelUtil.isNull(tradeinfo[6]))
                {
                    genswap.FixingDays = 2;
                }
                else
                {
                    genswap.FixingDays = (int)(double)tradeinfo[6];
                }

                if (ExcelUtil.isNull(tradeinfo[7]))
                {
                    genswap.TradeDate = EliteQuant.EQConverter.DateTimeToString(DateTime.Today);
                }
                else
                {
                    genswap.TradeDate = EliteQuant.EQConverter.DateTimeToString(DateTime.FromOADate((double)tradeinfo[7]));
                }

                // set it temporarily to ""
                if (ExcelUtil.isNull(tradeinfo[8]))
                {
                    genswap.SettlementDate = string.Empty;
                }
                else
                {
                    genswap.SettlementDate = EliteQuant.EQConverter.DateTimeToString(DateTime.FromOADate((double)tradeinfo[8]));
                }

                // set it temporarily to today
                if (ExcelUtil.isNull(tradeinfo[9]))
                {
                    genswap.MaturityDate = string.Empty;
                }
                else
                {
                    genswap.MaturityDate = EliteQuant.EQConverter.DateTimeToString(DateTime.FromOADate((double)tradeinfo[9]));
                }

                // set it temporarily to blank
                if (ExcelUtil.isNull(tradeinfo[10]))
                {
                    genswap.Tenor = string.Empty;
                }
                else
                {
                    genswap.Tenor = (string)tradeinfo[10];
                }

                if (ExcelUtil.isNull(tradeinfo[11]))
                {
                    genswap.IsScheduleGiven = false;
                }
                else
                {
                    //genswap.IsScheduleGiven = Convert.ToBoolean((string)tradeinfo[11]);
                    genswap.IsScheduleGiven = (bool)tradeinfo[11];
                }
                genswap.IsScheduleGiven = false;        // set to false always, amortization currently not supported

                //***************  First Leg *************************//
                if (ExcelUtil.isNull(firstleginfo[0]))
                {
                    genswap.FirstLegIndex = "FIXED";
                }
                else
                {
                    genswap.FirstLegIndex = (string)firstleginfo[0];
                }

                if (ExcelUtil.isNull(firstleginfo[1]))
                {
                    genswap.FirstLegFrequency = "SEMIANNUAL";
                }
                else
                {
                    genswap.FirstLegFrequency = (string)firstleginfo[1];
                }

                if (ExcelUtil.isNull(firstleginfo[2]))
                {
                    genswap.FirstLegConvention = "MODIFIEDFOLLOWING";
                }
                else
                {
                    genswap.FirstLegConvention = (string)firstleginfo[2];
                }

                if (ExcelUtil.isNull(firstleginfo[3]))
                {
                    genswap.FirstLegCalendar = "NYC|LON";
                }
                else
                {
                    genswap.FirstLegCalendar = (string)firstleginfo[3];
                }

                if (ExcelUtil.isNull(firstleginfo[4]))
                {
                    genswap.FirstLegDayCounter = "ACTUAL360";
                }
                else
                {
                    genswap.FirstLegDayCounter = (string)firstleginfo[4];
                }

                if (ExcelUtil.isNull(firstleginfo[5]))
                {
                    genswap.FirstLegDateGenerationRule = "BACKWARD";
                }
                else
                {
                    genswap.FirstLegDateGenerationRule = (string)firstleginfo[5];
                }

                if (ExcelUtil.isNull(firstleginfo[6]))
                {
                    genswap.FirstLegEOM = true;
                }
                else
                {
                    genswap.FirstLegEOM = (bool)firstleginfo[6];
                }

                if (ExcelUtil.isNull(firstleginfo[7]))
                {
                    genswap.FirstLegSpread = 0.0;
                }
                else
                {
                    genswap.FirstLegSpread = (double)firstleginfo[7];
                }

                if (ExcelUtil.isNull(firstlegnotionals))
                {
                    genswap.FirstLegNotionals.Clear();
                    genswap.FirstLegNotionals.Add(0);       // size = 1
                }
                else
                {
                    genswap.FirstLegNotionals.Clear();
                    foreach (var nl in firstlegnotionals)
                    {
                        if (ExcelUtil.isNull(nl))
                        {
                            continue;
                        }

                        genswap.FirstLegNotionals.Add((double)nl);
                    }
                }

                if (ExcelUtil.isNull(firstlegschedule) || (!genswap.IsScheduleGiven))
                {
                    genswap.FirstLegSchedules.Clear();
                    genswap.FirstLegSchedules.Add(genswap.SettlementDate);
                    genswap.FirstLegSchedules.Add(genswap.MaturityDate);
                }
                else
                {
                    genswap.FirstLegSchedules.Clear();
                    for (int a = 0; a < firstlegschedule.GetLength(0); a++)
                    {
                        DateTime d;
                        if (ExcelUtil.isNull(firstlegschedule[a, 0]))
                        {
                            // add one more date
                            d = DateTime.FromOADate((double)firstlegschedule[a - 1, 1]);
                            genswap.FirstLegSchedules.Add(EliteQuant.EQConverter.DateTimeToString(d));
                            break;
                        }


                        d = DateTime.FromOADate((double)firstlegschedule[a, 0]);
                        genswap.FirstLegSchedules.Add(EliteQuant.EQConverter.DateTimeToString(d));
                    }
                }

                //***************  Second Leg *************************//

                if (ExcelUtil.isNull(secondleginfo[0]))
                {
                    genswap.SecondLegIndex = "USDLIB3M";
                }
                else
                {
                    genswap.SecondLegIndex = (string)secondleginfo[0];
                }

                if (ExcelUtil.isNull(secondleginfo[1]))
                {
                    genswap.SecondLegFrequency = "QUARTERLY";
                }
                else
                {
                    genswap.SecondLegFrequency = (string)secondleginfo[1];
                }

                if (ExcelUtil.isNull(secondleginfo[2]))
                {
                    genswap.SecondLegConvention = "MODIFIEDFOLLOWING";
                }
                else
                {
                    genswap.SecondLegConvention = (string)secondleginfo[2];
                }

                if (ExcelUtil.isNull(secondleginfo[3]))
                {
                    genswap.SecondLegCalendar = "NYC|LON";           // nor NYC|LON
                }
                else
                {
                    genswap.SecondLegCalendar = (string)secondleginfo[3];
                }

                if (ExcelUtil.isNull(secondleginfo[4]))
                {
                    genswap.SecondLegDayCounter = "ACTUAL360";
                }
                else
                {
                    genswap.SecondLegDayCounter = (string)secondleginfo[4];
                }

                if (ExcelUtil.isNull(secondleginfo[5]))
                {
                    genswap.SecondLegDateGenerationRule = "BACKWARD";
                }
                else
                {
                    genswap.SecondLegDateGenerationRule = (string)secondleginfo[5];
                }

                if (ExcelUtil.isNull(secondleginfo[6]))
                {
                    genswap.SecondLegEOM = true;
                }
                else
                {
                    genswap.SecondLegEOM = (bool)secondleginfo[6];
                }

                if (ExcelUtil.isNull(secondleginfo[7]))
                {
                    genswap.SecondLegSpread = 0.0;
                }
                else
                {
                    genswap.SecondLegSpread = (double)secondleginfo[7];
                }

                if (ExcelUtil.isNull(secondlegnotionals))
                {
                    genswap.SecondLegNotionals.Clear();
                    genswap.SecondLegNotionals.Add(0);
                }
                else
                {
                    genswap.SecondLegNotionals.Clear();
                    foreach (var nl in secondlegnotionals)
                    {
                        if (ExcelUtil.isNull(nl))
                        {
                            continue;
                        }

                        genswap.SecondLegNotionals.Add((double)nl);
                    }
                }

                if (ExcelUtil.isNull(secondlegschedule) || (!genswap.IsScheduleGiven))
                {
                    genswap.SecondLegSchedules.Clear();
                    genswap.SecondLegSchedules.Add(genswap.SettlementDate);
                    genswap.SecondLegSchedules.Add(genswap.MaturityDate);
                }
                else
                {
                    genswap.SecondLegSchedules.Clear();
                    for (int a = 0; a < secondlegschedule.GetLength(0); a++)
                    {
                        DateTime d;
                        if (ExcelUtil.isNull(secondlegschedule[a, 0]))
                        {
                            // add one more date
                            d = DateTime.FromOADate((double)secondlegschedule[a - 1, 1]);
                            genswap.SecondLegSchedules.Add(EliteQuant.EQConverter.DateTimeToString(d));
                            break;
                        }


                        d = DateTime.FromOADate((double)secondlegschedule[a, 0]);
                        genswap.SecondLegSchedules.Add(EliteQuant.EQConverter.DateTimeToString(d));
                    }
                }

                #endregion

                #region convert Interest rate generic swap to swap obj
                string firstidx = genswap.FirstLegIndex, secondidx = genswap.SecondLegIndex;
                string firstidx_id  = "IDX@" + firstidx;
                string secondidx_id = "IDX@" + secondidx;
                EliteQuant.IborIndex firstidx_obj = null;
                if (!firstidx.Contains("FIXED"))
                {
                    firstidx_obj = OHRepository.Instance.getObject <EliteQuant.IborIndex>(firstidx_id);
                }

                EliteQuant.IborIndex secondidx_obj = OHRepository.Instance.getObject <EliteQuant.IborIndex>(secondidx_id);

                genswap.ConstructSwap(firstidx_obj, secondidx_obj);

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

                DiscountingSwapEngine engine = new DiscountingSwapEngine(dch);
                genswap.eqswap_.setPricingEngine(engine);
                #endregion

                string id = "SWP@" + genswap.ContractId;
                OHRepository.Instance.storeObject(id, genswap, 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!");
            }
        }