Beispiel #1
0
        public static string eqCurveCommodIndex(
            [ExcelArgument(Description = "index id ")] string ObjectId,
            [ExcelArgument(Description = "index name ")] string indexname,
            [ExcelArgument(Description = "curve id ")] string curveId,
            [ExcelArgument(Description = "calendar")] string calendar,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                calendar = "NULL";

                CommodityCurveExt curve = OHRepository.Instance.getObject <CommodityCurveExt>(curveId);

                CommodityIndexExt idx = new CommodityIndexExt(indexname, curve, new NullCalendar());

                // Store the index and return its id
                string id = "IDX@" + ObjectId;
                OHRepository.Instance.storeObject(id, idx, 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!");
            }
        }
        public T getObject <T>(string objID)
        {
            if (objID == "")
            {
                throw new System.Exception("Empty ID");
            }
            if (objID == "#VALUE!" || objID == "#NA!" || objID == "#EQ_ERR!")
            {
                throw new System.Exception("Cannot identify object ID " + objID + " and get " + typeof(T).FullName);
            }

            string realID = stripObjID(objID);

            System.Threading.Monitor.Enter(lockobj_);
            try
            {
                if (objectInfo_.ContainsKey(realID))
                {
                    return((T)((List <object>)(objectInfo_[realID]))[0]);
                    // List<object> tmp = (List<object>)objectInfo_[realID];
                    // T ob = (T)tmp[0];
                    // return ob;
                }
            }
            catch (Exception e)
            {
                ExcelUtil.logError(objID, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
            }
            finally
            {
                System.Threading.Monitor.Exit(lockobj_);
            }

            throw new System.Exception("Cannot find object with ID: " + objID + " and get " + typeof(T).FullName);
        }
Beispiel #3
0
        public static object eqModelGetSVIInterpolatedValue(
            [ExcelArgument(Description = "id of SVI model ")] string ObjectId,
            [ExcelArgument(Description = "strik value ")] double x)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                Xl.Range         rng    = ExcelUtil.getActiveCellRange();
                SVIInterpolation option = OHRepository.Instance.getObject <SVIInterpolation>(ObjectId);
                return(option.call(x));
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }
Beispiel #4
0
        public static object eqModelGetDoubleExponentialCalibratedParameters(
            [ExcelArgument(Description = "id of double exponential ATM model ")] string ObjectId,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

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

                object[,] ret = new object[6, 2];
                ret[0, 0]     = "sigma:"; ret[0, 1] = atmvol.sigma();
                ret[1, 0]     = "b1:"; ret[1, 1] = atmvol.b1();
                ret[2, 0]     = "b2:"; ret[2, 1] = atmvol.b2();
                ret[3, 0]     = "lambda:"; ret[3, 1] = atmvol.lambda();
                ret[4, 0]     = "error:"; ret[4, 1] = atmvol.error();
                ret[5, 0]     = "maxerror:"; ret[5, 1] = atmvol.maxError();

                return(ret);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }
Beispiel #5
0
        public static object eqRatesDiscountFactor(
            [ExcelArgument(Description = "interest rate ")] double r,
            [ExcelArgument(Description = "time in years ")] double t,
            [ExcelArgument(Description = "DayCounter (default Actual365) ")] string dc,
            [ExcelArgument(Description = "Compounding (default Continuous) ")] string comp,
            [ExcelArgument(Description = "Frequency (default Actual365) ")] string freq,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                DayCounter  daycounter  = EliteQuant.EQConverter.ConvertObject <DayCounter>(dc);
                Compounding compounding = EliteQuant.EQConverter.ConvertObject <Compounding>(comp);
                Frequency   frequency   = EliteQuant.EQConverter.ConvertObject <Frequency>(freq);

                InterestRate ir = new InterestRate(r, daycounter, compounding, frequency);

                return(ir.discountFactor(t));
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }
        public static string eqIRCurveOISRateHelper(
            [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 = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                // "us settlement"; "Actual/360"; "fixingDays = 0", "F", "eom = true"
                EliteQuant.FedFunds idx_ff = new EliteQuant.FedFunds();

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

                // USSO
                EliteQuant.RateHelper rh = new EliteQuant.OISRateHelper((uint)fixingDays_usd, tenor_, rate_, idx_ff);

                string id = "RHOIS@" + 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!");
            }
        }
Beispiel #7
0
        public static object eqTimeSetEvaluationDate(
            [ExcelArgument(Description = "Evaluation Date ")] DateTime date)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return(false);
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            EliteQuant.Date todaysDate;
            try
            {
                if (date == DateTime.MinValue)
                {
                    todaysDate = EliteQuant.EQConverter.ConvertObject <EliteQuant.Date>(DateTime.Today);
                }
                else
                {
                    todaysDate = EliteQuant.EQConverter.ConvertObject <EliteQuant.Date>(date);
                }

                EliteQuant.Settings.instance().setEvaluationDate(todaysDate);

                return(EliteQuant.EQConverter.ConvertObject <DateTime>(todaysDate));
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(false);
            }
        }
Beispiel #8
0
        public static object eqCurveCommodForwardPrice(
            [ExcelArgument(Description = "index id ")] string ObjectId,
            [ExcelArgument(Description = "forward date ")] DateTime date,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

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

                CommodityIndexExt idx = OHRepository.Instance.getObject <CommodityIndexExt>(ObjectId);
                Date dt = EliteQuant.EQConverter.ConvertObject <Date>(date);

                // double price = idx.price(dt);
                double price = idx.forwardPrice(dt);

                return(price);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }
Beispiel #9
0
        public static string eqOpRootPath(
            [ExcelArgument(Description = "Method 1 or 2 ")] double method)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

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

            try
            {
                if (method == 1.0)
                {
                    return(getXllPath());
                }
                else
                {
                    return(EliteQuant.ConfigManager.Instance.RootDir);
                }
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("");
            }
        }
Beispiel #10
0
        public static object eqTimeYearFraction(
            [ExcelArgument(Description = "Start Date ")] DateTime date1,
            [ExcelArgument(Description = "End Date ")] DateTime date2,
            [ExcelArgument(Description = "Day Counter (default ActualActual) ")] string dc = "ActualActual")
        {
            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);
                DayCounter daycounter = EliteQuant.EQConverter.ConvertObject <DayCounter>(dc);
                return(daycounter.yearFraction(start, end));
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("");
            }
        }
Beispiel #11
0
        public static object eqCurveIRGetDiscountFactor(
            [ExcelArgument(Description = "curve id ")] string ObjectId,
            [ExcelArgument(Description = "tenors ")] DateTime dt,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

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

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

                YieldTermStructureHandle curve = OHRepository.Instance.getObject <YieldTermStructureHandle>(ObjectId);
                Date refDate = curve.referenceDate();

                Date   dt2      = EliteQuant.EQConverter.ConvertObject <Date>(dt);
                double discount = curve.discount(dt2);

                return(discount);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }
Beispiel #12
0
        public static object eqTimeNextIMMDate(
            [ExcelArgument(Description = "Date ")] DateTime date,
            [ExcelArgument(Description = "is main cycle ? ")] bool maincycle)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

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

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

                EliteQuant.Date immdate = EliteQuant.IMM.nextDate(d, maincycle);

                return(immdate.serialNumber());
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }
Beispiel #13
0
        public static string eqIndexesClearHistory(
            [ExcelArgument(Description = "index name ")] String name,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

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

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

                return(name);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }
Beispiel #14
0
        public static object eqModelGetSABRCalibratedParameters(
            [ExcelArgument(Description = "id of SABR model ")] string ObjectId,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                Xl.Range          rng    = ExcelUtil.getActiveCellRange();
                SABRInterpolation option = OHRepository.Instance.getObject <SABRInterpolation>(ObjectId);

                object[,] ret = new object[6, 2];
                ret[0, 0]     = "alpha:";  ret[0, 1] = option.alpha();
                ret[1, 0]     = "beta:"; ret[1, 1] = option.beta();
                ret[2, 0]     = "nu:"; ret[2, 1] = option.nu();
                ret[3, 0]     = "rho:"; ret[3, 1] = option.rho();
                ret[4, 0]     = "rmsError:"; ret[4, 1] = option.rmsError();
                ret[5, 0]     = "maxError:"; ret[5, 1] = option.maxError();

                return(ret);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }
Beispiel #15
0
        public static object eqIRCurveDisplayDiscountCurve(
            [ExcelArgument(Description = "id of discount curve ")] string ObjectId,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                Xl.Range rng = ExcelUtil.getActiveCellRange();
                if (!ObjectId.Contains('@'))
                {
                    ObjectId = "CRV@" + ObjectId;
                }

                EliteQuant.YieldTermStructure curve = OHRepository.Instance.getObject <EliteQuant.YieldTermStructure>(ObjectId);
                if (curve.GetType() == typeof(EliteQuant.DiscountCurve))
                {
                    object[,] ret = new object[(curve as DiscountCurve).dates().Count, 2];

                    for (int i = 0; i < (curve as DiscountCurve).dates().Count; i++)
                    {
                        ret[i, 0] = (curve as DiscountCurve).dates()[i].serialNumber();
                        ret[i, 1] = (curve as DiscountCurve).discounts()[i].ToString();
                    }

                    return(ret);
                }
                else if (curve.GetType() == typeof(EliteQuant.LinearDiscountCurve))
                {
                    object[,] ret = new object[(curve as LinearDiscountCurve).dates().Count, 2];

                    for (int i = 0; i < (curve as LinearDiscountCurve).dates().Count; i++)
                    {
                        ret[i, 0] = (curve as LinearDiscountCurve).dates()[i].serialNumber();
                        ret[i, 1] = (curve as LinearDiscountCurve).discounts()[i].ToString();
                    }

                    return(ret);
                }
                else
                {
                    return(0);
                }
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }
Beispiel #16
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!");
            }
        }
Beispiel #17
0
        public static object eqTimeAdjustDate(
            [ExcelArgument(Description = "Date ")] DateTime date,
            [ExcelArgument(Description = "Calendar (default NYC) ")] string calendar,
            [ExcelArgument(Description = "BusinessDayConvention (default ModifiedFollowing) ")] string bdc)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

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

            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);

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

                Date newday = can.adjust(d, bdc2);
                return(newday.serialNumber());
            }
            catch (TypeInitializationException e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                object[,] ret = new object[5, 1];
                ret[0, 1]     = e.ToString();
                ret[1, 1]     = e.Message;
                ret[2, 1]     = e.StackTrace;
                ret[3, 3]     = e.Source;
                ret[4, 1]     = e.InnerException.Message;
                return(ret);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }
Beispiel #18
0
        public static object eqIndexesLoadFixingFromFile(
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

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

                string[] curves = new string[] { "USDOIS", "USDLIB3M", "USDLIB1M", "USDLIB6M", "USDLIB12M" };
                string   path   = EliteQuant.ConfigManager.Instance.IRRootDir + @"Curves\";
                string   name;
                foreach (var s in curves)
                {
                    string[]     data = System.IO.File.ReadAllLines(path + s + "_Fixing.csv");
                    DateVector   dt   = new DateVector(data.Length);
                    DoubleVector qs   = new DoubleVector(data.Length);

                    foreach (var fixing in data)
                    {
                        if (fixing == "")
                        {
                            continue;
                        }

                        string[] ff = fixing.Split(',');
                        dt.Add(EliteQuant.EQConverter.DateTimeToDate(EliteQuant.EQConverter.StringToDateTime(ff[0])));
                        qs.Add(Convert.ToDouble(ff[1]));
                    }

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

                    string         name2   = EliteQuant.Curves.IndexMapping.ExtIndexName2EQName(name);
                    RealTimeSeries fixings = new RealTimeSeries(dt, qs);
                    IndexManager.instance().setHistory(name2, fixings);
                }

                return(asofdate);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }
Beispiel #19
0
        public static object eqTimeAdvanceDate(
            [ExcelArgument(Description = "Date ")] DateTime date,
            [ExcelArgument(Description = "Calendar (default NYC) ")] string calendar,
            [ExcelArgument(Description = "Tenor (e.g. '3D' or '2Y') ")] string tenor,
            [ExcelArgument(Description = "BusinessDayConvention (default ModifiedFollowing) ")] string bdc,
            [ExcelArgument(Description = "is endofmonth ")] bool eom)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

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

            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);

                if (string.IsNullOrEmpty(tenor))
                {
                    tenor = "1D";
                }
                EliteQuant.Period period = EliteQuant.EQConverter.ConvertObject <EliteQuant.Period>(tenor);

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

                Date newday = can.advance(d, period, bdc2, eom);
                return(newday.serialNumber());
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }
Beispiel #20
0
        public static DateTime eqOpLibXllBuildTime()
        {
            DateTime buildTime = new DateTime();

            try
            {
                buildTime = getXllBuildTime();
            }
            catch (Exception ex)
            {
                ExcelUtil.logError("", "", ex.Message);
            }
            return(buildTime);
        }
Beispiel #21
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);
            }
        }
Beispiel #22
0
        public static string eqOpLibXllBuiltBy()
        {
            string user;

            try
            {
                user = getBuildUser();
            }
            catch (Exception ex)
            {
                ExcelUtil.logError("", "", ex.Message);
                user = ex.Message;
            }
            return(user);
        }
Beispiel #23
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!");
            }
        }
Beispiel #24
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!");
            }
        }
Beispiel #25
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!");
            }
        }
Beispiel #26
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!");
            }
        }
Beispiel #28
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!");
            }
        }
Beispiel #29
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!");
            }
        }
Beispiel #30
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);
            }
        }