示例#1
0
文件: FxPair.cs 项目: zhangz/qwack
 public static FxPair FxPairFromString(this string pair, ICurrencyProvider currencyProvider, ICalendarProvider calendarProvider) => new FxPair
 {
     Domestic           = currencyProvider.GetCurrency(pair.Substring(0, 3)),
     Foreign            = currencyProvider.GetCurrency(pair.Substring(pair.Length - 3, 3)),
     SettlementCalendar = calendarProvider.Collection[pair.Substring(0, 3) + "+" + pair.Substring(pair.Length - 3, 3)],
     SpotLag            = 2.Bd()
 };
示例#2
0
文件: FxPair.cs 项目: wy6688/qwack
 public FxPair(TO_FxPair transportObject, ICurrencyProvider currencyProvider, ICalendarProvider calendarProvider)
 {
     Foreign           = currencyProvider.GetCurrency(transportObject.Foreign);
     Domestic          = currencyProvider.GetCurrency(transportObject.Domestic);
     SpotLag           = new Frequency(transportObject.SpotLag);
     PrimaryCalendar   = calendarProvider.Collection[transportObject.PrimaryCalendar];
     SecondaryCalendar = calendarProvider.Collection[transportObject.SecondaryCalendar];
 }
示例#3
0
文件: FxMatrix.cs 项目: wy6688/qwack
 public FxMatrix(TO_FxMatrix transportObject, ICurrencyProvider currencyProvider, ICalendarProvider calendarProvider) : this(currencyProvider)
 {
     BaseCurrency      = currencyProvider.GetCurrency(transportObject.BaseCurrency);
     BuildDate         = transportObject.BuildDate;
     SpotRates         = transportObject.SpotRates.ToDictionary(x => currencyProvider.GetCurrency(x.Key), y => y.Value);
     DiscountCurveMap  = transportObject.DiscountCurveMap.ToDictionary(x => currencyProvider.GetCurrency(x.Key), y => y.Value);
     FxPairDefinitions = transportObject.FxPairDefinitions.Select(x => new FxPair(x, currencyProvider, calendarProvider)).ToList();
 }
示例#4
0
        public static ICurrency FromISOCode(string code, IEnumerable <ICurrencyProvider> providers = null)
        {
            var found = DefaultProvider.GetCurrency(code);

            return(found ?? (providers ?? new List <ICurrencyProvider>())
                   .SelectMany(p => p.Currencies)
                   .FirstOrDefault(c => c.CurrencyIsoCode == code));
        }
示例#5
0
 public ConstantVolSurface(TO_ConstantVolSurface transportObject, ICurrencyProvider currencyProvider)
     : this(transportObject.OriginDate, transportObject.Volatility)
 {
     Currency = currencyProvider.GetCurrency(transportObject.Currency);
     AssetId  = transportObject.AssetId;
     Name     = transportObject.Name;
 }
示例#6
0
        public static RiskyFlySurface ToRiskyFlySurfaceStepFlat(this Dictionary <DateTime, IInterpolator1D> smiles, DateTime valDate, IPriceCurve priceCurve, List <DateTime> allExpiries, ICurrencyProvider currencyProvider)
        {
            var wingDeltas     = new[] { 0.25, 0.1 };
            var expiries       = smiles.Keys.ToArray();
            var expiriesDouble = expiries.Select(e => e.ToOADate()).ToArray();
            var atmVols        = smiles.Select(x => x.Value.Interpolate(0.5)).ToArray();
            var riskies        = smiles.Select(x =>
                                               wingDeltas.Select(w => x.Value.Interpolate(1.0 - w) - x.Value.Interpolate(w))
                                               .ToArray())
                                 .ToArray();
            var flies = smiles.Select((x, ix) =>
                                      wingDeltas.Select(w => (x.Value.Interpolate(1.0 - w) + x.Value.Interpolate(w)) / 2.0 - atmVols[ix])
                                      .ToArray())
                        .ToArray();

            SmoothSmiles(wingDeltas, smiles, ref riskies, ref flies);

            var fwds = allExpiries.Select(x => priceCurve.GetPriceForDate(x)).ToArray();

            var atmInterp    = InterpolatorFactory.GetInterpolator(expiriesDouble, atmVols, Interpolator1DType.LinearInVariance);
            var riskyInterps = wingDeltas.Select((w, ixw) => InterpolatorFactory.GetInterpolator(expiriesDouble, riskies.Select(r => r[ixw]).ToArray(), Interpolator1DType.LinearFlatExtrap)).ToArray();
            var flyInterps   = wingDeltas.Select((w, ixw) => InterpolatorFactory.GetInterpolator(expiriesDouble, flies.Select(f => f[ixw]).ToArray(), Interpolator1DType.LinearFlatExtrap)).ToArray();

            var expandedRiskies = allExpiries.Select(e => wingDeltas.Select((w, ixw) => riskyInterps[ixw].Interpolate(e.ToOADate())).ToArray()).ToArray();
            var expandedFlies   = allExpiries.Select(e => wingDeltas.Select((w, ixw) => flyInterps[ixw].Interpolate(e.ToOADate())).ToArray()).ToArray();
            var expandedAtms    = allExpiries.Select(e => atmInterp.Interpolate(e.ToOADate())).ToArray();
            var expandedFwds    = allExpiries.Select(e => priceCurve.GetPriceForDate(e)).ToArray();
            var o = new RiskyFlySurface(valDate, expandedAtms, allExpiries.ToArray(), wingDeltas, expandedRiskies, expandedFlies, expandedFwds, WingQuoteType.Arithmatic,
                                        AtmVolType.ZeroDeltaStraddle, Interpolator1DType.CubicSpline, Interpolator1DType.NextValue)
            {
                Currency = currencyProvider.GetCurrency("USD")
            };

            return(o);
        }
示例#7
0
        public Dictionary <string, IrCurve> ImplyContainedCurves(DateTime buildDate, Interpolator1DType interpType)
        {
            var o = new Dictionary <string, IrCurve>();

            foreach (var curveName in SolveCurves)
            {
                var pillars = this.Where(x => x.SolveCurve == curveName)
                              .Select(x => x.PillarDate)
                              .OrderBy(x => x)
                              .ToArray();
                if (pillars.Distinct().Count() != pillars.Count())
                {
                    throw new Exception($"More than one instrument has the same solve pillar on curve {curveName}");
                }

                var dummyRates = pillars.Select(x => 0.05).ToArray();
                var ccy        = _currencyProvider.GetCurrency(curveName.Split('.')[0]);
                var colSpec    = (curveName.Contains("[")) ? curveName.Split('[').Last().Trim("[]".ToCharArray()) : curveName.Split('.').Last();
                if (o.Values.Any(v => v.CollateralSpec == colSpec))
                {
                    colSpec = colSpec + "_" + curveName;
                }

                var irCurve = new IrCurve(pillars, dummyRates, buildDate, curveName, interpType, ccy, colSpec);
                o.Add(curveName, irCurve);
            }
            return(o);
        }
示例#8
0
 public BasicPriceCurve(TO_BasicPriceCurve transportObject, ICurrencyProvider currencyProvider) :
     this(transportObject.BuildDate, transportObject.PillarDates, transportObject.Prices, transportObject.CurveType, currencyProvider, transportObject.PillarLabels)
 {
     Currency       = currencyProvider.GetCurrency(transportObject.Currency);
     CollateralSpec = transportObject.CollateralSpec;
     Name           = transportObject.Name;
     AssetId        = transportObject.AssetId;
 }
示例#9
0
 public GridVolSurface(TO_GridVolSurface transportObject, ICurrencyProvider currencyProvider)
     : this(transportObject.OriginDate, transportObject.Strikes, transportObject.Expiries, transportObject.Volatilities, transportObject.StrikeType,
            transportObject.StrikeInterpolatorType, transportObject.TimeInterpolatorType, transportObject.TimeBasis, transportObject.PillarLabels)
 {
     Currency = currencyProvider.GetCurrency(transportObject.Currency);
     AssetId  = transportObject.AssetId;
     Name     = transportObject.Name;
 }
示例#10
0
        private static IFundingInstrument ToQwackIns(this CMEFileRecord record, string qwackCode, IFutureSettingsProvider futureSettingsProvider, ICurrencyProvider currencyProvider, Dictionary <string, FloatRateIndex> indices, Dictionary <string, string> forecastCurves)
        {
            switch (qwackCode)
            {
            case "ED":
                var edExp = FutureCode.GetExpiryFromCode(MmmYtoCode(record.MMY, qwackCode), futureSettingsProvider);
                return(new STIRFuture
                {
                    ContractSize = 1e6,
                    Currency = currencyProvider.GetCurrency("USD"),
                    DCF = 0.25,
                    ConvexityAdjustment = 0,
                    Price = record.SettlePrice.Value,
                    Index = indices["ED"],
                    Expiry = edExp,
                    PillarDate = edExp.AddMonths(3),
                    TradeId = qwackCode + record.MMY,
                    Position = 1,
                    SolveCurve = forecastCurves["ED"],
                    ForecastCurve = forecastCurves["ED"],
                });

            case "FF":
                var ffEnd   = FutureCode.GetExpiryFromCode(MmmYtoCode(record.MMY, qwackCode), futureSettingsProvider);
                var ffStart = ffEnd.FirstDayOfMonth();
                return(new OISFuture
                {
                    ContractSize = 1e6,
                    Currency = currencyProvider.GetCurrency("USD"),
                    DCF = ffStart.CalculateYearFraction(ffEnd, DayCountBasis.ACT360),
                    Price = record.SettlePrice.Value,
                    Index = indices["FF"],
                    PillarDate = ffEnd,
                    TradeId = qwackCode + record.MMY,
                    Position = 1,
                    SolveCurve = forecastCurves["FF"],
                    ForecastCurve = forecastCurves["FF"],
                    AverageStartDate = ffStart,
                    AverageEndDate = ffEnd,
                });

            default:
                throw new Exception($"No mapping found for code {qwackCode}");
            }
        }
示例#11
0
 public RiskyFlySurface(TO_RiskyFlySurface transportObject, ICurrencyProvider currencyProvider)
     : this(transportObject.OriginDate, transportObject.ATMs, transportObject.Expiries, transportObject.WingDeltas, transportObject.Riskies,
            transportObject.Flies, transportObject.Forwards, transportObject.WingQuoteType, transportObject.AtmVolType, transportObject.StrikeInterpolatorType,
            transportObject.TimeInterpolatorType, transportObject.PillarLabels)
 {
     Currency = currencyProvider.GetCurrency(transportObject.Currency);
     AssetId  = transportObject.AssetId;
     Name     = transportObject.Name;
 }
示例#12
0
        private ICube GetRisk(IPvModel model)
        {
            switch (Metric)
            {
            case RiskMetric.AssetCurveDelta:
                return(model.AssetDelta());

            //case RiskMetric.AssetCurveDeltaGamma:
            //    return portfolio.AssetDeltaGamma(model);
            case RiskMetric.FxDelta:
                return(model.FxDeltaSpecific(_currencyProvider.GetCurrency("ZAR"), FxPairsForDelta, _currencyProvider, false));

            //case RiskMetric.FxDeltaGamma:
            //    return portfolio.FxDelta(model, _currencyProvider.GetCurrency("ZAR"), _currencyProvider, true);
            default:
                throw new Exception($"Unable to process risk metric {Metric}");
            }
        }
示例#13
0
        public static RiskyFlySurface ToRiskyFlySurface(this Dictionary <DateTime, IInterpolator1D> smiles, DateTime valDate, double[] fwds, ICurrencyProvider currencyProvider)
        {
            var wingDeltas = new[] { 0.25, 0.1 };
            var expiries   = smiles.Keys.ToArray();
            var atmVols    = smiles.Select(x => x.Value.Interpolate(0.5)).ToArray();
            var riskies    = smiles.Select(x =>
                                           wingDeltas.Select(w => x.Value.Interpolate(1.0 - w) - x.Value.Interpolate(w))
                                           .ToArray())
                             .ToArray();
            var flies = smiles.Select((x, ix) =>
                                      wingDeltas.Select(w => (x.Value.Interpolate(1.0 - w) + x.Value.Interpolate(w)) / 2.0 - atmVols[ix])
                                      .ToArray())
                        .ToArray();

            SmoothSmiles(wingDeltas, smiles, ref riskies, ref flies);

            var o = new RiskyFlySurface(valDate, atmVols, expiries, wingDeltas, riskies, flies, fwds, WingQuoteType.Arithmatic,
                                        AtmVolType.ZeroDeltaStraddle, Interpolator1DType.CubicSpline, Interpolator1DType.LinearInVariance)
            {
                Currency = currencyProvider.GetCurrency("USD")
            };

            return(o);
        }
示例#14
0
        public static RiskyFlySurface GetMetalSurfaceForCode(string cmxSymbol, string cmxSettleFilename, ICurrencyProvider currency)
        {
            var blob   = CMEFileParser.Instance.GetBlob(cmxSettleFilename);
            var origin = blob.Batch.First().BizDt;

            var(optionExerciseType, optionMarginingType) = OptionTypeFromCode(cmxSymbol);
            var opts = blob.Batch.Where(b => b.Instrmt.Sym == cmxSymbol).Select(x => new ListedOptionSettlementRecord
            {
                Strike                = Convert.ToDouble(x.Instrmt.StrkPx),
                PV                    = Convert.ToDouble(x.Full.Where(x => x.Typ == "6").First().Px),
                CallPut               = x.Instrmt.PutCall ? OptionType.C : OptionType.P, //x.Instrmt.PutCall == 1 ? OptionType.C : OptionType.P,
                ExerciseType          = optionExerciseType,
                MarginType            = optionMarginingType,
                UnderlyingFuturesCode = $"{x.Undly.ID}~{x.Undly.MMY}",
                ExpiryDate            = x.Instrmt.MatDt,
                ValDate               = origin
            }).Where(z => z.ExpiryDate > origin).ToList();

            var underlyings = opts.Select(x => x.UnderlyingFuturesCode).Distinct().ToArray();
            var ulCodes     = underlyings.Select(x => x.Split('~')[0]).Distinct().ToArray();

            var futRecords = blob.Batch.Where(b => b.Instrmt.SecTyp == "FUT" && ulCodes.Contains(b.Instrmt.ID));
            var priceDict  = futRecords.ToDictionary(x => $"{x.Instrmt.ID}~{x.Instrmt.MMY}", x => Convert.ToDouble(x.Full.Where(x => x.Typ == "6").First().Px));

            ListedSurfaceHelper.ImplyVols(opts, priceDict, new ConstantRateIrCurve(0.0, origin, "dummy", currency.GetCurrency("USD")));
            var smiles = ListedSurfaceHelper.ToDeltaSmiles(opts, priceDict);

            var expiries    = smiles.Keys.OrderBy(x => x).ToArray();
            var ulByExpiry  = expiries.ToDictionary(x => x, x => opts.Where(qq => qq.ExpiryDate == x).First().UnderlyingFuturesCode);
            var fwdByExpiry = ulByExpiry.ToDictionary(x => x.Key, x => priceDict[x.Value]);
            var fwds        = expiries.Select(e => fwdByExpiry[e]).ToArray();
            var surface     = ListedSurfaceHelper.ToRiskyFlySurface(smiles, origin, fwds, currency);

            return(surface);
        }
示例#15
0
        public static IrCurve GetCurveForCode(string cmeId, string cmeFilename, string qwackCode, string curveName, Dictionary <string, FloatRateIndex> indices, Dictionary <string, string> curves, IFutureSettingsProvider futureSettingsProvider, ICurrencyProvider currencyProvider, ICalendarProvider calendarProvider)
        {
            var parsed      = CMEFileParser.Parse(cmeFilename).Where(r => r.ID == cmeId && r.SecTyp == "FUT");
            var q           = parsed.ToDictionary(x => DateTime.ParseExact(x.MatDt, "yyyy-MM-dd", CultureInfo.InvariantCulture), x => x.SettlePrice);
            var origin      = DateTime.ParseExact(parsed.First().BizDt, "yyyy-MM-dd", CultureInfo.InvariantCulture);
            var instruments = parsed.Select(p => ToQwackIns(p, qwackCode, futureSettingsProvider, currencyProvider, indices, curves)).ToList();
            var pillars     = instruments.Select(x => x.PillarDate).OrderBy(x => x).ToArray();
            var fic         = new FundingInstrumentCollection(currencyProvider);

            fic.AddRange(instruments);
            var curve = new IrCurve(pillars, pillars.Select(p => 0.01).ToArray(), origin, curveName, Interpolator1DType.Linear, currencyProvider.GetCurrency("USD"));
            var fm    = new FundingModel(origin, new[] { curve }, currencyProvider, calendarProvider);

            var solver = new NewtonRaphsonMultiCurveSolverStaged();

            solver.Solve(fm, fic);
            return(curve);
        }
示例#16
0
        public AssetFxModel BuildModel(DateTime valDate, ModelBuilderSpec spec, IFutureSettingsProvider futureSettingsProvider, ICurrencyProvider currencyProvider, ICalendarProvider calendarProvider)
        {
            var indices     = spec.RateIndices.ToDictionary(x => x.Key, x => new FloatRateIndex(x.Value, calendarProvider, currencyProvider));
            var fxPairs     = spec.FxPairs.Select(x => new FxPair(x, currencyProvider, calendarProvider)).ToList();
            var priceCurves = new List <IPriceCurve>();
            var surfaces    = new List <IVolSurface>();
            var fxSurfaces  = new List <IVolSurface>();

            foreach (var c in spec.NymexSpecs)
            {
                var curve = NYMEXModelBuilder.GetCurveForCode(c.NymexCodeFuture, Path.Combine(_filepath, FilenameNymexFuture), c.QwackCode, futureSettingsProvider, currencyProvider);
                priceCurves.Add(curve);
                if (!string.IsNullOrWhiteSpace(c.NymexCodeOption))
                {
                    var surface = NYMEXModelBuilder.GetSurfaceForCode(c.NymexCodeOption, Path.Combine(_filepath, FilenameNymexOption), c.QwackCode, curve, calendarProvider, currencyProvider, futureSettingsProvider);
                    surface.AssetId = c.QwackCode;
                    surfaces.Add(surface);
                }
            }
            var irCurves = new Dictionary <string, IrCurve>();

            foreach (var c in spec.CmeBaseCurveSpecs)
            {
                var ixForThis = new Dictionary <string, FloatRateIndex> {
                    { c.QwackCode, indices[c.FloatRateIndex] }
                };
                var curve = CMEModelBuilder.GetCurveForCode(c.CmeCode, Path.Combine(_filepath, c.IsCbot? FilenameCbot:FilenameCme), c.QwackCode, c.CurveName, ixForThis,
                                                            new Dictionary <string, string>()
                {
                    { c.QwackCode, c.CurveName }
                }, futureSettingsProvider, currencyProvider, calendarProvider);
                irCurves.Add(c.CurveName, curve);
            }
            foreach (var c in spec.CmeBasisCurveSpecs)
            {
                var fxPair = fxPairs.Single(x => $"{x.Domestic}{x.Foreign}" == c.FxPair);
                var curve  = CMEModelBuilder.StripFxBasisCurve(Path.Combine(_filepath, FilenameCmeFwdsXml), fxPair, c.CmeFxPair, currencyProvider.GetCurrency(c.Currency), c.CurveName, valDate, irCurves[c.BaseCurveName], currencyProvider, calendarProvider);
                irCurves.Add(c.CurveName, curve);
            }
            foreach (var c in spec.CmeFxFutureSpecs)
            {
                var curve   = CMEModelBuilder.GetFuturesCurveForCode(c.CmeCodeFut, Path.Combine(_filepath, FilenameCme), currencyProvider);
                var surface = CMEModelBuilder.GetFxSurfaceForCode(c.CmeCodeOpt, Path.Combine(_filepath, FilenameCme), curve, currencyProvider);
                surface.AssetId = c.FxPair;
                fxSurfaces.Add(surface);
            }

            var pairMap     = spec.CmeBasisCurveSpecs.ToDictionary(x => x.FxPair, x => x.CmeFxPair);
            var pairCcyMap  = spec.CmeBasisCurveSpecs.ToDictionary(x => x.FxPair, x => currencyProvider.GetCurrency(x.Currency));
            var spotRates   = CMEModelBuilder.GetSpotFxRatesFromFwdFile(Path.Combine(_filepath, FilenameCmeFwdsXml), valDate, pairMap, currencyProvider, calendarProvider);
            var discountMap = spec.CmeBasisCurveSpecs.ToDictionary(x => pairCcyMap[x.FxPair], x => x.CurveName);

            foreach (var c in spec.CmxMetalCurves)
            {
                var fxPair = fxPairs.Single(x => $"{x.Domestic}{x.Foreign}" == c.MetalPair);
                var(curve, spotPrice) = COMEXModelBuilder.GetMetalCurveForCode(Path.Combine(_filepath, FilenameCmxFwdsXml), c.CmxSymbol, fxPair, c.CurveName, valDate, irCurves[c.BaseCurveName], currencyProvider, calendarProvider);
                irCurves.Add(c.CurveName, curve);
                spotRates.Add(c.MetalPair, spotPrice);
                discountMap.Add(currencyProvider.GetCurrency(c.Currency), c.CurveName);
                pairCcyMap.Add(c.MetalPair, currencyProvider.GetCurrency(c.Currency));
                if (!string.IsNullOrWhiteSpace(c.CmxOptCode))
                {
                    var surface = COMEXModelBuilder.GetMetalSurfaceForCode(c.CmxOptCode, Path.Combine(_filepath, FilenameCmxXml), currencyProvider);
                    surface.AssetId = c.MetalPair;
                    fxSurfaces.Add(surface);
                }
            }

            var fm = new FundingModel(valDate, irCurves, currencyProvider, calendarProvider);

            var spotRatesByCcy = spotRates.ToDictionary(x => pairCcyMap[x.Key], x => x.Key.StartsWith("USD") ? x.Value : 1.0 / x.Value);

            var fxMatrix = new FxMatrix(currencyProvider);

            fxMatrix.Init(
                baseCurrency: currencyProvider.GetCurrency("USD"),
                buildDate: valDate,
                spotRates: spotRatesByCcy,
                fXPairDefinitions: fxPairs,
                discountCurveMap: discountMap);
            fm.SetupFx(fxMatrix);
            foreach (var fxs in fxSurfaces)
            {
                fm.VolSurfaces.Add(fxs.AssetId, fxs);
            }
            var o = new AssetFxModel(valDate, fm);

            o.AddVolSurfaces(surfaces.ToDictionary(s => s.AssetId, s => s));
            o.AddPriceCurves(priceCurves.ToDictionary(c => c.AssetId, c => c));
            return(o);
        }
示例#17
0
        public static RiskyFlySurface GetFxSurfaceForCode(string cmeSymbol, string cmeFutureFilename, BasicPriceCurve priceCurve, ICurrencyProvider currency)
        {
            var parsed = CMEFileParser.Instance.Parse(cmeFutureFilename).Where(r => r.Sym == cmeSymbol && r.SecTyp == "OOF" && r.SettlePrice.HasValue);

            var(optionExerciseType, optionMarginingType) = OptionTypeFromCode(cmeSymbol);
            var origin = DateTime.ParseExact(parsed.First().BizDt, "yyyy-MM-dd", CultureInfo.InvariantCulture);

            var q = parsed.Where(x => x.SettlePrice > 0).Select(x => new ListedOptionSettlementRecord
            {
                CallPut               = x.PutCall == 1 ? OptionType.C : OptionType.P,
                ExerciseType          = optionExerciseType,
                MarginType            = optionMarginingType,
                PV                    = x.SettlePrice.Value,
                Strike                = x.StrkPx.Value,
                UnderlyingFuturesCode = x.UndlyMMY,
                ExpiryDate            = DateTime.ParseExact(x.MatDt, "yyyy-MM-dd", CultureInfo.InvariantCulture),
                ValDate               = origin
            }).Where(z => z.ExpiryDate > origin).ToList();

            var priceDict = priceCurve.PillarLabels.ToDictionary(x => x, x => priceCurve.GetPriceForDate(priceCurve.PillarDatesForLabel(x)));

            ListedSurfaceHelper.ImplyVols(q, priceDict, new ConstantRateIrCurve(0.0, origin, "dummy", currency.GetCurrency("USD")));
            var smiles = ListedSurfaceHelper.ToDeltaSmiles(q, priceDict);

            var expiries    = smiles.Keys.OrderBy(x => x).ToArray();
            var ulByExpiry  = expiries.ToDictionary(x => x, x => q.Where(qq => qq.ExpiryDate == x).First().UnderlyingFuturesCode);
            var fwdByExpiry = ulByExpiry.ToDictionary(x => x.Key, x => priceCurve.GetPriceForDate(priceCurve.PillarDatesForLabel(x.Value)));
            var fwds        = expiries.Select(e => fwdByExpiry[e]).ToArray();
            var surface     = ListedSurfaceHelper.ToRiskyFlySurface(smiles, origin, fwds, currency);

            return(surface);
        }
示例#18
0
 public Currency GetCurrency(string currency) => _currencyProvider.GetCurrency(currency);
示例#19
0
        public static RiskyFlySurface GetSurfaceForCode(string nymexSymbol, string nymexOptionFilename, string qwackCode, BasicPriceCurve priceCurve, ICalendarProvider calendarProvider, ICurrencyProvider currency, IFutureSettingsProvider futureSettingsProvider)
        {
            var parsed = NYMEXOptionParser.Instance.Parse(nymexOptionFilename).Where(r => r.Symbol == nymexSymbol);

            var(optionExerciseType, optionMarginingType) = OptionTypeFromCode(nymexSymbol);
            var origin = DateTime.ParseExact(parsed.First().TradeDate, "MM/dd/yyyy", CultureInfo.InvariantCulture);

            var q = parsed.Where(x => x.Settle > 0).Select(x => new ListedOptionSettlementRecord
            {
                CallPut               = x.PutCall == "C"?OptionType.C:OptionType.P,
                ExerciseType          = optionExerciseType,
                MarginType            = optionMarginingType,
                PV                    = x.Settle,
                Strike                = x.Strike,
                UnderlyingFuturesCode = Year2to1(x.Contract.Split(' ')[0].Replace(nymexSymbol, qwackCode)),
                ExpiryDate            = OptionExpiryFromNymexRecord(x, calendarProvider),
                ValDate               = origin
            }).Where(z => z.ExpiryDate > origin).ToList();

            var priceDict = priceCurve.PillarLabels.ToDictionary(x => x, x => priceCurve.GetPriceForDate(priceCurve.PillarDatesForLabel(x)));

            ListedSurfaceHelper.ImplyVols(q, priceDict, new ConstantRateIrCurve(0.0, origin, "dummy", currency.GetCurrency("USD")));
            var smiles = ListedSurfaceHelper.ToDeltaSmiles(q, priceDict);

            var allOptionExpiries = new List <DateTime>();
            var lastDate          = q.Max(x => x.ExpiryDate);

            var dummyFutureCode = $"{qwackCode}Z{DateExtensions.SingleDigitYear(DateTime.Today.Year + 2)}";
            var c = new FutureCode(dummyFutureCode, DateTime.Today.Year - 2, futureSettingsProvider);

            var contract     = c.GetFrontMonth(origin, false);
            var lastContract = c.GetFrontMonth(lastDate, false);

            while (contract != lastContract)
            {
                var cc     = new FutureCode(contract, origin.Year, futureSettingsProvider);
                var exp    = ListedUtils.FuturesCodeToDateTime(contract);
                var record = new NYMEXOptionRecord
                {
                    ContractMonth = exp.Month,
                    ContractYear  = exp.Year,
                    Symbol        = nymexSymbol
                };
                var optExpiry = OptionExpiryFromNymexRecord(record, calendarProvider);
                if (optExpiry > origin)
                {
                    allOptionExpiries.Add(optExpiry);
                }

                contract = cc.GetNextCode(false);
            }

            var surface = ListedSurfaceHelper.ToRiskyFlySurfaceStepFlat(smiles, origin, priceCurve, allOptionExpiries, currency);

            return(surface);
        }
示例#20
0
        public static RiskyFlySurface GetSurfaceForCode(string nymexSymbol, string nymexOptionFilename, string qwackCode, PriceCurve priceCurve, ICalendarProvider calendarProvider, ICurrencyProvider currency)
        {
            var parsed = NYMEXOptionParser.Parse(nymexOptionFilename).Where(r => r.Symbol == nymexSymbol);

            var(optionExerciseType, optionMarginingType) = OptionTypeFromCode(nymexSymbol);
            var origin = DateTime.ParseExact(parsed.First().TradeDate, "MM/dd/yyyy", CultureInfo.InvariantCulture);

            var q = parsed.Select(x => new ListedOptionSettlementRecord
            {
                CallPut               = x.PutCall == "C"?OptionType.C:OptionType.P,
                ExerciseType          = optionExerciseType,
                MarginType            = optionMarginingType,
                PV                    = x.Settle,
                Strike                = x.Strike,
                UnderlyingFuturesCode = Year2to1(x.Contract.Split(' ')[0].Replace(nymexSymbol, qwackCode)),
                ExpiryDate            = OptionExpiryFromNymexRecord(x, calendarProvider),
                ValDate               = origin
            }).ToList();

            var priceDict = priceCurve.PillarLabels.ToDictionary(x => x, x => priceCurve.GetPriceForDate(priceCurve.PillarDatesForLabel(x)));

            ListedSurfaceHelper.ImplyVols(q, priceDict, new ConstantRateIrCurve(0.0, origin, "dummy", currency.GetCurrency("USD")));
            var smiles  = ListedSurfaceHelper.ToDeltaSmiles(q, priceDict);
            var surface = ListedSurfaceHelper.ToRiskyFlySurface(smiles, origin, smiles.Keys.Select(x => priceCurve.GetPriceForDate(x)).ToArray());

            return(surface);
        }
示例#21
0
 public IrCurve(TO_IrCurve transportObject, ICurrencyProvider currencyProvider)
     : this(transportObject.Pillars, transportObject.Rates, transportObject.BuildDate, transportObject.Name, transportObject.InterpKind,
            currencyProvider.GetCurrency(transportObject.Ccy), transportObject.CollateralSpec, transportObject.RateStorageType)
 {
     _basis = transportObject.Basis;
 }
示例#22
0
文件: FxMatrix.cs 项目: biqueta/qwack
 public string GetDiscountCurve(string currency) => DiscountCurveMap.TryGetValue(_currencyProvider.GetCurrency(currency), out var curve) ? curve : null;
示例#23
0
        public void Portfolio()
        {
            var bd  = DateTime.Parse("2018-09-13");
            var swp = AssetProductFactory.CreateTermAsianSwap(bd, bd.AddYears(1), 100, "AssetX", CalendarProvider.Collection["USD"], bd.AddYears(2), CcyProvider.GetCurrency("USD"));

            var pf = new Portfolio()
            {
                Instruments = new List <IInstrument>()
            };

            Assert.Empty(PortfolioEx.AssetIds(pf));

            pf.Instruments = new List <IInstrument> {
                swp
            };

            Assert.Equal(swp.LastSensitivityDate, pf.LastSensitivityDate);
            Assert.Equal("AssetX", PortfolioEx.AssetIds(pf).First());
            Assert.Equal(bd.AddYears(2), pf.LastSensitivityDate);

            var deets = PortfolioEx.Details(pf);

            Assert.Throws <NotImplementedException>(() => pf.TradeId);
            Assert.Throws <NotImplementedException>(() => pf.Counterparty);
            Assert.Throws <NotImplementedException>(() => pf.Counterparty = null);
        }