コード例 #1
0
ファイル: PriceCurveFunctions.cs プロジェクト: biqueta/qwack
        public static object CreateFixingDictionary(
            [ExcelArgument(Description = "Object name")] string ObjectName,
            [ExcelArgument(Description = "Asset Id")] string AssetId,
            [ExcelArgument(Description = "Fixings array, 1st column dates / 2nd column fixings")] object[,] Fixings,
            [ExcelArgument(Description = "Type, Asset or FX - default Asset")] object FixingType,
            [ExcelArgument(Description = "Fx pair (optional)")] string FxPair)
        {
            return(ExcelHelper.Execute(_logger, () =>
            {
                var fixTypeStr = FixingType.OptionalExcel("Asset");
                if (!Enum.TryParse <FixingDictionaryType>(fixTypeStr, out var fixType))
                {
                    throw new Exception($"Unknown fixing dictionary type {fixTypeStr}");
                }
                var dict = new FixingDictionary
                {
                    Name = AssetId,
                    AssetId = AssetId,
                    FixingDictionaryType = fixType,
                    FxPair = FxPair
                };

                var dictData = Fixings.RangeToDictionary <DateTime, double>();
                foreach (var kv in dictData)
                {
                    dict.Add(kv.Key, kv.Value);
                }

                return ExcelHelper.PushToCache <IFixingDictionary>(dict, ObjectName);
            }));
        }
コード例 #2
0
ファイル: PriceCurveFunctions.cs プロジェクト: biqueta/qwack
        public static object CreateFixingDictionaryForRollingFuture(
            [ExcelArgument(Description = "Object name")] string ObjectName,
            [ExcelArgument(Description = "Asset Id")] string AssetId,
            [ExcelArgument(Description = "Futures code, e.g. QS or CO")] string FuturesCode,
            [ExcelArgument(Description = "1st month fixings array, 1st column dates / 2nd column fixings")] object[,] Fixings1m,
            [ExcelArgument(Description = "2nd month fixings array, 1st column dates / 2nd column fixings")] object[,] Fixings2m)
        {
            return(ExcelHelper.Execute(_logger, () =>
            {
                var dict = new FixingDictionary
                {
                    Name = AssetId,
                    AssetId = AssetId,
                    FixingDictionaryType = FixingDictionaryType.Asset
                };
                var futuresProvider = ContainerStores.SessionContainer.GetRequiredService <IFutureSettingsProvider>();
                var dictData1m = Fixings1m.RangeToDictionary <DateTime, double>();
                var dictData2m = Fixings2m.RangeToDictionary <DateTime, double>();
                var fc = new FutureCode(FuturesCode, futuresProvider);
                fc.YearBeforeWhich2DigitDatesAreUsed = DateTime.Today.Year - 2;

                foreach (var kv in dictData1m)
                {
                    var currentFM = fc.GetFrontMonth(kv.Key, true);
                    var cfm = new FutureCode(currentFM, DateTime.Today.Year - 2, futuresProvider);
                    if (kv.Key <= cfm.GetRollDate())
                    {
                        dict.Add(kv.Key, kv.Value);
                    }
                    else
                    {
                        dict.Add(kv.Key, dictData2m[kv.Key]);
                    }
                }
                return ExcelHelper.PushToCache <IFixingDictionary>(dict, ObjectName);
            }));
        }
コード例 #3
0
ファイル: PriceCurveFunctions.cs プロジェクト: biqueta/qwack
        public static object CreateFixingDictionaryFromVectors(
            [ExcelArgument(Description = "Object name")] string ObjectName,
            [ExcelArgument(Description = "Asset Id")] string AssetId,
            [ExcelArgument(Description = "Fixings dates")] double[] FixingDates,
            [ExcelArgument(Description = "Fixings dates")] double[] Fixings,
            [ExcelArgument(Description = "Type, Asset or FX - default Asset")] object FixingType,
            [ExcelArgument(Description = "Fx pair (optional)")] string FxPair)
        {
            return(ExcelHelper.Execute(_logger, () =>
            {
                if (FixingDates.Length != Fixings.Length)
                {
                    throw new Exception("Fixings and FixingDates must be of same length");
                }

                var fixTypeStr = FixingType.OptionalExcel("Asset");
                if (!Enum.TryParse <FixingDictionaryType>(fixTypeStr, out var fixType))
                {
                    throw new Exception($"Unknown fixing dictionary type {fixTypeStr}");
                }

                var dict = new FixingDictionary
                {
                    Name = AssetId,
                    AssetId = AssetId,
                    FixingDictionaryType = fixType,
                    FxPair = FxPair
                };
                for (var i = 0; i < FixingDates.Length; i++)
                {
                    if (FixingDates[i] != 0)
                    {
                        dict.Add(DateTime.FromOADate(FixingDates[i]), Fixings[i]);
                    }
                }

                return ExcelHelper.PushToCache <IFixingDictionary>(dict, ObjectName);
            }));
        }