Пример #1
0
        public static string eqRiskPortfolio(
            [ExcelArgument(Description = "Portfolio Id ")] string ObjectId,
            [ExcelArgument(Description = "Instruments in portfolio ")] object[] instids,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                List <EnergyCommodityExt> port_ = new List <EnergyCommodityExt>();

                foreach (string sid in instids)
                {
                    EnergyCommodityExt inst = OHRepository.Instance.getObject <EnergyCommodityExt>(sid);
                    port_.Add(inst);
                }

                string id = "Port@" + ObjectId;
                OHRepository.Instance.storeObject(id, port_, 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);
            }
        }
Пример #2
0
        public static object eqRiskSimTwoBaseCurves(
            [ExcelArgument(Description = "as of date ")] DateTime asofdate,
            [ExcelArgument(Description = "curve 1 name ")] string curve1,
            [ExcelArgument(Description = "curve 2 name ")] string curve2,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                return(asofdate);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }
Пример #3
0
        public static object eqOpListFolders(
            [ExcelArgument(Description = "path ")] string path)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                //path = @"S:\All\Risk\Simulation\Pds\" + asofdate.ToString("yyyyMMdd");
                string[] dirs = System.IO.Directory.GetDirectories(path).OrderByDescending(x => x).ToArray();
                object[,] ret = new object[dirs.Count(), 1];

                int i = 0;
                foreach (var s in dirs)
                {
                    ret[i++, 0] = (new System.IO.DirectoryInfo(s)).Name;
                }

                return(ret);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }
Пример #4
0
        public static object eqOpGetRPath()
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                Microsoft.Win32.RegistryKey registryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\R-core\R");
                string rPath    = (string)registryKey.GetValue("InstallPath");
                string rVersion = (string)registryKey.GetValue("Current Version");
                registryKey.Dispose();

                object[,] ret = new object[2, 2];
                ret[0, 0]     = "R Version"; ret[0, 1] = rVersion;
                ret[1, 0]     = "R Path"; ret[1, 1] = rPath;

                return(ret);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }
Пример #5
0
        public static object eqMathGet2DInterpolation(
            [ExcelArgument(Description = "interpolation obj id")] string objId,
            [ExcelArgument(Description = "row variable x ")] double x,
            [ExcelArgument(Description = "col variable y ")] double y)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                BilinearInterpolation interp = OHRepository.Instance.getObject <BilinearInterpolation>(objId);

                double ret = interp.call(x, y);
                return(ret);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }
Пример #6
0
        public static object eqRiskCalibrateCurveATMVol(
            [ExcelArgument(Description = "as of date ")] DateTime asofdate,
            [ExcelArgument(Description = "curve 1 ")] string curve1,
            [ExcelArgument(Description = "(optional) curve 2 ")] string curve2,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                List <string> curves = new List <string>();
                curves.Add(curve1.ToUpper());

                if (!ExcelUtil.isNull(curve2) && (!string.IsNullOrEmpty(curve2)))
                {
                    curves.Add(curve2.ToUpper());
                }

                return(asofdate);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }
Пример #7
0
        public static object eqMathGenThreefryGaussianRng(
            [ExcelArgument(Description = "seed of the rng (can't be zero)")] int seed,
            [ExcelArgument(Description = "skip (jump forward) ")] int skip)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();
            Xl.Range range = ExcelUtil.getActiveCellRange();
            int      c     = range.Count; // range should be one column

            try
            {
                double[,] ret = new double[c, 1];
                double[] ret0 = new double[c];

                EliteQuant.NQuantLibc.normalthreefry(seed, skip, ret0, c);

                for (int i = 0; i < c; i++)
                {
                    ret[i, 0] = ret0[i];
                }

                return(ret);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }
Пример #8
0
        public static DateTime eqOpObjectUpdateTime(
            [ExcelArgument(Description = "id of object ")] string objID)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return(DateTime.MinValue);
            }

            return(OHRepository.Instance.getObjectUpdateTime(objID));
        }
Пример #9
0
        public static string eqOpObjectCallerAddress(
            [ExcelArgument(Description = "id of object ")] string objID)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            return(OHRepository.Instance.getCallerAddress(objID));
        }
Пример #10
0
        public static string eqOpObjectClassName(
            [ExcelArgument(Description = "id of object ")] string objID)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            return(OHRepository.Instance.getObjectType(objID).Name);
        }
Пример #11
0
        public static string eqMathBiLinearInterpolation(
            [ExcelArgument(Description = "interpolation obj id")] string objId,
            [ExcelArgument(Description = "row variable x ")] double[] x,
            [ExcelArgument(Description = "col variable y ")] double[] y,
            [ExcelArgument(Description = "variable z ")] double[,] z)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                if ((x.Length != z.GetLength(0)) || (y.Length != z.GetLength(1)))
                {
                    return("size mismatch");
                }

                QlArray xa = new QlArray((uint)x.Length);
                QlArray ya = new QlArray((uint)y.Length);
                for (uint i = 0; i < x.Length; i++)
                {
                    xa.set(i, x[i]);
                    ya.set(i, y[i]);
                }

                Matrix ma = new Matrix((uint)x.Length, (uint)y.Length);
                for (uint i = 0; i < x.Length; i++)
                {
                    for (uint j = 0; j < y.Length; j++)
                    {
                        ma.set(i, j, z[i, j]);
                    }
                }

                BilinearInterpolation interp = new BilinearInterpolation(xa, ya, ma);

                // Store the futures and return its id
                string id = "Int@" + objId;
                OHRepository.Instance.storeObject(id, interp, 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);
            }
        }
Пример #12
0
        public static object eqOpListEnvironmentVariable(
            [ExcelArgument(Description = "environment variable (e.g. Path or PythonPath)")] string evar)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                if (string.IsNullOrEmpty(evar))
                {
                    int env_count = Environment.GetEnvironmentVariables().Count;
                    object[,] ret = new object[env_count, 3];
                    int i = 0;
                    foreach (System.Collections.DictionaryEntry env in Environment.GetEnvironmentVariables())
                    {
                        ret[i, 0] = (i + 1).ToString() + "/" + env_count.ToString();
                        ret[i, 1] = (string)env.Key;
                        ret[i, 2] = (string)env.Value;
                        i++;
                    }
                    return(ret);
                }
                else
                {
                    var path       = System.Environment.GetEnvironmentVariable(evar);
                    var path_array = path.Split(';');
                    object[,] ret = new object[path_array.Count(), 2];
                    for (int i = 0; i < path_array.Count(); i++)
                    {
                        ret[i, 0] = (i + 1).ToString() + "/" + path_array.Count();
                        ret[i, 1] = path_array[i];
                    }

                    return(ret);
                }
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }
Пример #13
0
        public static object eqOpListObjects(
            [ExcelArgument(Description = "pattern ")] string pattern)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return(new string[0, 0]);
            }

            List <String> objids = OHRepository.Instance.listObjects(pattern);

            object[,] ret = new object[objids.Count, 1];
            int i = 0;

            foreach (string str in objids)
            {
                ret[i++, 0] = str;
            }

            return(ret);
        }
Пример #14
0
        public static object eqMathGet1DInterpolation(
            [ExcelArgument(Description = "interpolation obj id")] string objId,
            [ExcelArgument(Description = "variable x ")] double x,
            [ExcelArgument(Description = "Linear/LogLinear ")] string type)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                if (type.ToUpper() == "LINEAR")
                {
                    LinearInterpolation interp = OHRepository.Instance.getObject <LinearInterpolation>(objId);
                    double ret = interp.call(x, true);

                    return(ret);
                }
                else if (type.ToUpper() == "LOGLINEAR")
                {
                    LogLinearInterpolation interp = OHRepository.Instance.getObject <LogLinearInterpolation>(objId);
                    double ret = interp.call(x, true);

                    return(ret);
                }
                else
                {
                    return("Unknown interpolation type");
                }
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }
Пример #15
0
        public static object eqOpListFiles(
            [ExcelArgument(Description = "path ")] string path,
            [ExcelArgument(Description = "with file extensions ")] bool withext)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                string[] files = System.IO.Directory.GetFiles(path);
                object[,] ret = new object[files.Count(), 1];

                int i = 0;
                foreach (var f in files)
                {
                    if (withext)
                    {
                        ret[i++, 0] = System.IO.Path.GetFileName(f);
                    }
                    else
                    {
                        ret[i++, 0] = System.IO.Path.GetFileNameWithoutExtension(f);
                    }
                }

                return(ret);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return("#EQ_ERR!");
            }
        }
Пример #16
0
        public static string eqRiskGetTradePFE(
            [ExcelArgument(Description = "as of date ")] DateTime asofdate,
            [ExcelArgument(Description = "trade id ")] string tradeid,
            [ExcelArgument(Description = "trigger ")] object trigger)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                return(tradeid);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }
Пример #17
0
        public static object eqOpGetEnumerationList(
            [ExcelArgument(Description = "Enum Class Name (Daycounter, Calendar, BusinessDayConvention)")] string enumclassname)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                // by default ExcelDna is horizontal; make vertical
                object[,] ret = new object[10, 1];
                for (int i = 0; i < 10; i++)
                {
                    ret[i, 0] = "";
                }
                switch (enumclassname.ToUpper())
                {
                case "DAYCOUNTER":
                    ret[0, 0] = "ACTUAL360";
                    ret[1, 0] = "ACTUAL365";
                    ret[2, 0] = "ACTUALACTUAL";
                    break;

                case "CALENDAR":
                    ret[0, 0] = "NYC";
                    ret[1, 0] = "LON";
                    ret[2, 0] = "NYC|LON";
                    break;

                case "BUSINESSDAYCONVENTION":
                    ret[0, 0] = "F";
                    ret[1, 0] = "MF";
                    ret[2, 0] = "P";
                    ret[3, 0] = "MP";
                    ret[4, 0] = "NONE";
                    break;

                case "DGRULE":          // Date Generation Rule
                    ret[0, 0] = "Backward";
                    ret[1, 0] = "Forward";
                    ret[2, 0] = "Zero";
                    ret[3, 0] = "ThirdWednesday";
                    ret[4, 0] = "Twentieth";
                    ret[5, 0] = "TwentiethIMM";
                    ret[6, 0] = "CDS";
                    break;

                default:
                    ret[0, 0] = "unkown enum type";
                    break;
                }

                return(ret);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }