Beispiel #1
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 #2
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);
            }
        }
Beispiel #3
0
        public static string eqCurveIRIndex(
            [ExcelArgument(Description = "index id (USDOIS, USDLIB3M, USDLIB1M ")] string ObjectId,
            [ExcelArgument(Description = "currency (USD, GBP, CAD, EUR, JPY ) ")] string Curncy,
            [ExcelArgument(Description = "id or name of discount curve ")] string discountId,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

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

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

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

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

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

                // Store the option and return its id
                string id = "IDX@" + ObjectId;
                OHRepository.Instance.storeObject(id, idx_default, callerAddress);
                id += "#" + (String)DateTime.Now.ToString(@"HH:mm:ss");
                return(id);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }