Esempio n. 1
0
        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);
            }));
        }
Esempio n. 2
0
 public static object TurnbullWakemanFuturesPV(
     [ExcelArgument(Description = "Fixing dates")] double[] FixingDates,
     [ExcelArgument(Description = "Eval date")] DateTime EvalDate,
     [ExcelArgument(Description = "Pay date")] DateTime PayDate,
     [ExcelArgument(Description = "Forward curve")] string Curve,
     [ExcelArgument(Description = "Fixings")] string FixingDictionary,
     [ExcelArgument(Description = "Vol surface")] string Surface,
     [ExcelArgument(Description = "Strike")] double K,
     [ExcelArgument(Description = "Discounting rate")] double R,
     [ExcelArgument(Description = "Call or Put")] string CP)
 {
     return(ExcelHelper.Execute(_logger, () =>
     {
         if (!Enum.TryParse(CP, out OptionType optType))
         {
             return $"Could not parse call or put flag - {CP}";
         }
         var curve = ContainerStores.GetObjectCache <IPriceCurve>().GetObjectOrThrow(Curve, $"Curve {Curve} not found");
         var surface = ContainerStores.GetObjectCache <IVolSurface>().GetObjectOrThrow(Surface, $"Surface {Surface} not found");
         var fd = new FixingDictionary();
         var dates = FixingDates.ToDateTimeArray();
         if (dates.First() < EvalDate)
         {
             fd = ContainerStores.GetObjectCache <FixingDictionary>().GetObjectOrThrow(FixingDictionary, $"Fixing dictionary {FixingDictionary} not found").Value;
         }
         var fwds = dates.Select(d => d > EvalDate?curve.Value.GetPriceForDate(d): fd.GetFixing(d)).ToArray();
         var vols = dates.Select((d, ix) => surface.Value.GetVolForAbsoluteStrike(K, d, fwds[ix])).ToArray();
         return Qwack.Options.Asians.TurnbullWakeman.PV(fwds, dates, EvalDate, PayDate, vols, K, R, optType);
     }));
 }
Esempio n. 3
0
        public static object TurnbullWakemanStrikeForPVFutures(
            [ExcelArgument(Description = "Evaluation Date")] DateTime EvalDate,
            [ExcelArgument(Description = "Fixing dates")] double[] FixingDates,
            [ExcelArgument(Description = "Settlement Date")] DateTime PayDate,
            [ExcelArgument(Description = "Target PV")] double PV,
            [ExcelArgument(Description = "Forward curve")] string FwdCurve,
            [ExcelArgument(Description = "Fixing dictionary")] string FixingDictionary,
            [ExcelArgument(Description = "Discounting rate")] double R,
            [ExcelArgument(Description = "Volatility Surface")] string VolSurface,
            [ExcelArgument(Description = "Call or Put")] string CP)
        {
            return(ExcelHelper.Execute(_logger, () =>
            {
                var surface = ContainerStores.GetObjectCache <IVolSurface>().GetObjectOrThrow(VolSurface, $"Could not parse find vol surface {VolSurface} in the cache");
                var curve = ContainerStores.GetObjectCache <IPriceCurve>().GetObjectOrThrow(FwdCurve, $"Fwd curve {FwdCurve} not found");

                var fd = new FixingDictionary();
                var dates = FixingDates.ToDateTimeArray();
                if (dates.First() < EvalDate)
                {
                    fd = ContainerStores.GetObjectCache <FixingDictionary>().GetObjectOrThrow(FixingDictionary, $"Fixing dictionary {FixingDictionary} not found").Value;
                }
                var F = dates.Select(d => d > EvalDate ? curve.Value.GetPriceForDate(d) : fd.GetFixing(d)).ToArray();

                if (!Enum.TryParse(CP, out OptionType optType))
                {
                    return $"Could not parse call or put flag - {CP}";
                }
                return Qwack.Options.Asians.TurnbullWakeman.StrikeForPV(PV, F, FixingDates.ToDateTimeArray(), surface.Value, EvalDate, PayDate, R, optType);
            }));
        }
Esempio n. 4
0
        public void FixingDictionaryFact()
        {
            IFixingDictionary z = new FixingDictionary();

            z = new FixingDictionary(new Dictionary <DateTime, double>()
            {
                { DateTime.Today, 1.0 }
            });
            var zz  = new FixingDictionary(z);
            var zzz = zz.Clone();

            Assert.Throws <Exception>(() => zzz.GetFixing(DateTime.MinValue));
            Assert.Equal(1.0, zzz.GetFixing(DateTime.Today));
            Assert.True(zzz.TryGetFixing(DateTime.Today, out var f));
        }
Esempio n. 5
0
        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);
            }));
        }
Esempio n. 6
0
        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);
            }));
        }