Exemplo n.º 1
0
        public override IMarketCondition GenerateMarketCondition(QdpMarket market)
        {
            var prebuiltMarket = market as PrebuiltQdpMarket;

            if (prebuiltMarket != null)
            {
                return(GenerateMarketConditionFromPrebuilt(prebuiltMarket));
            }
            else
            {
                var recTicker  = TradeInfo.RecTicker;
                var payTicker  = TradeInfo.PayTicker;
                var fxTicker   = TradeInfo.FxTicker;
                var recLegSpot = market.GetData <StockMktData>(recTicker).Price;
                var payLegSpot = market.GetData <StockMktData>(payTicker).Price;
                var fx         = market.GetData <FxFixingMktData>(fxTicker).Price;

                return(new MarketCondition(
                           x => x.ValuationDate.Value = market.ReferenceDate,
                           x => x.SpotPrices.Value = new Dictionary <string, double> {
                    { recTicker, recLegSpot }, { payTicker, payLegSpot }
                },
                           x => x.FxSpot.Value = new Dictionary <string, double> {
                    { fxTicker, fx }
                }
                           ));
            }
        }
Exemplo n.º 2
0
        public override IMarketCondition GenerateMarketCondition(QdpMarket market)
        {
            var parseMarket = _bondVf.GenerateMarketCondition(market);

            var mktQuote = new Dictionary <string, Tuple <PriceQuoteType, double> >();

            try
            {
                var startBondId      = TradeInfo.TradeId + "_Start";
                var startBondMktData = market.GetData <BondMktData>(startBondId);
                if (startBondMktData != null)
                {
                    mktQuote[startBondId] = Tuple.Create(startBondMktData.PriceQuoteType.ToPriceQuoteType(), startBondMktData.Quote);
                }

                var endBondId      = TradeInfo.TradeId + "_End";
                var endBondMktData = market.GetData <BondMktData>(endBondId);
                if (endBondMktData != null)
                {
                    mktQuote[endBondId] = Tuple.Create(endBondMktData.PriceQuoteType.ToPriceQuoteType(), endBondMktData.Quote);
                }

                foreach (var key in parseMarket.MktQuote.Value.Keys)
                {
                    mktQuote[key] = parseMarket.MktQuote.Value[key];
                }
                parseMarket = parseMarket.UpdateCondition(new UpdateMktConditionPack <Dictionary <string, Tuple <PriceQuoteType, double> > >(x => x.MktQuote, mktQuote));
            }
            catch (Exception ex)
            {
                throw new PricingBaseException(string.Format("Market price is missing, detailed message: {0}", ex.Message));
            }
            return(parseMarket);
        }
Exemplo n.º 3
0
        public override IMarketCondition GenerateMarketCondition(QdpMarket market)
        {
            var valuationParameter = TradeInfo.ValuationParamters;

            return(new MarketCondition(
                       x => x.ValuationDate.Value = market.ReferenceDate,
                       x => x.DiscountCurve.Value = market.GetData <CurveData>(valuationParameter.DiscountCurveName).YieldCurve,
                       x => x.FixingCurve.Value = market.GetData <CurveData>(valuationParameter.FixingCurveName).YieldCurve,
                       x => x.HistoricalIndexRates.Value = market.HistoricalIndexRates
                       ));
        }
Exemplo n.º 4
0
        public override IMarketCondition GenerateMarketCondition(QdpMarket market)
        {
            var valuationParameter = TradeInfo.ValuationParamters;
            var volsurf            = market.GetData <VolSurfMktData>(valuationParameter.FxVolSurfName).ToImpliedVolSurface(market.ReferenceDate);


            return(new MarketCondition(
                       x => x.ValuationDate.Value = market.ReferenceDate,
                       x => x.DiscountCurve.Value = market.GetData <CurveData>(valuationParameter.DomCcyDiscountCurveName).YieldCurve,
                       x => x.FgnDiscountCurve.Value = market.GetData <CurveData>(valuationParameter.FgnCcyDiscountCurveName).YieldCurve,
                       x => x.VolSurfaces.Value = new Dictionary <string, IVolSurface> {
                { "", volsurf }
            }

                       ));
        }
Exemplo n.º 5
0
        public override IMarketCondition GenerateMarketCondition(QdpMarket market)
        {
            var prebulitMarket = market as PrebuiltQdpMarket;

            if (prebulitMarket != null)
            {
                return(GenerateMarketConditionFromPrebuilt(prebulitMarket));
            }
            else
            {
                var valuationParameter = TradeInfo.ValuationParameters;
                var bondMktData        = market.GetData <BondMktData>(TradeInfo.TradeId);
                var volsurf            = market.GetData <VolSurfMktData>(valuationParameter.VolSurfNames[0]).ToImpliedVolSurface(market.ReferenceDate);
                return(new MarketCondition(
                           x => x.ValuationDate.Value = market.ReferenceDate,
                           x => x.DiscountCurve.Value = market.GetData <CurveData>(valuationParameter.DiscountCurveName).YieldCurve,
                           x => x.FixingCurve.Value = market.GetData <CurveData>(valuationParameter.DiscountCurveName).YieldCurve,
                           x => x.DividendCurves.Value = new Dictionary <string, IYieldCurve> {
                    { "", market.GetData <CurveData>(valuationParameter.DividendCurveNames[0]).YieldCurve }
                },
                           x => x.RiskfreeCurve.Value = market.GetData <CurveData>(valuationParameter.DiscountCurveName).YieldCurve,
                           x => x.VolSurfaces.Value = new Dictionary <string, IVolSurface> {
                    { "", volsurf }
                },
                           x => x.MktQuote.Value = new Dictionary <string, Tuple <PriceQuoteType, double> > {
                    { TradeInfo.TradeId, Tuple.Create((bondMktData == null || string.IsNullOrEmpty(bondMktData.PriceQuoteType)) ? PriceQuoteType.None : bondMktData.PriceQuoteType.ToPriceQuoteType(), (bondMktData == null ? 100.0 : bondMktData.Quote)) }
                },
                           x => x.SpotPrices.Value = new Dictionary <string, double> {
                    { "", market.GetData <StockMktData>(valuationParameter.UnderlyingId).Price }
                },
                           x => x.HistoricalIndexRates.Value = market.HistoricalIndexRates
                           ));
            }
        }
Exemplo n.º 6
0
        public override IMarketCondition GenerateMarketCondition(QdpMarket market)
        {
            var prebuiltMarket = market as PrebuiltQdpMarket;

            if (prebuiltMarket != null)
            {
                return(GenerateMarketConditionFromPrebuilt(prebuiltMarket));
            }
            else
            {
                var valuationParameter = TradeInfo.ValuationParamters;
                var bondMktData        = market.GetData <BondMktData>(TradeInfo.TradeId);

                if (valuationParameter == null)
                {
                    return(new MarketCondition(
                               x => x.ValuationDate.Value = market.ReferenceDate,
                               x => x.DiscountCurve.Value = null,
                               x => x.FixingCurve.Value = null,
                               x => x.RiskfreeCurve.Value = null,
                               x => x.MktQuote.Value = new Dictionary <string, Tuple <PriceQuoteType, double> > {
                        { TradeInfo.TradeId, Tuple.Create((bondMktData == null || string.IsNullOrEmpty(bondMktData.PriceQuoteType)) ? PriceQuoteType.None : bondMktData.PriceQuoteType.ToPriceQuoteType(), (bondMktData == null ? 100.0 : bondMktData.Quote)) }
                    },
                               x => x.HistoricalIndexRates.Value = market.HistoricalIndexRates
                               ));
                }

                var fixingCurveName = string.IsNullOrEmpty(valuationParameter.FixingCurveName)
                    ? valuationParameter.DiscountCurveName
                    : valuationParameter.FixingCurveName;
                return(new MarketCondition(
                           x => x.ValuationDate.Value = market.ReferenceDate,
                           x => x.DiscountCurve.Value = market.GetData <CurveData>(valuationParameter.DiscountCurveName).YieldCurve,
                           x => x.FixingCurve.Value = market.GetData <CurveData>(fixingCurveName).YieldCurve,
                           x => x.RiskfreeCurve.Value = market.GetData <CurveData>(valuationParameter.RiskfreeCurveName).YieldCurve,
                           x => x.MktQuote.Value = new Dictionary <string, Tuple <PriceQuoteType, double> > {
                    { TradeInfo.TradeId, Tuple.Create((bondMktData == null || string.IsNullOrEmpty(bondMktData.PriceQuoteType)) ? PriceQuoteType.None : bondMktData.PriceQuoteType.ToPriceQuoteType(), (bondMktData == null ? 100.0 : bondMktData.Quote)) }
                },
                           x => x.HistoricalIndexRates.Value = market.HistoricalIndexRates
                           ));
            }
        }
Exemplo n.º 7
0
        public override IMarketCondition GenerateMarketCondition(QdpMarket market)
        {
            var prebuiltMarket = market as PrebuiltQdpMarket;

            if (prebuiltMarket != null)
            {
                return(GenerateMarketConditionFromPrebuilt(prebuiltMarket));
            }
            else
            {
                var valuationParameter = TradeInfo.ValuationParamters;

                return(new MarketCondition(
                           x => x.ValuationDate.Value = market.ReferenceDate,
                           x => x.DiscountCurve.Value = market.GetData <CurveData>(valuationParameter.DiscountCurveName).YieldCurve,
                           x => x.FixingCurve.Value = market.GetData <CurveData>(valuationParameter.FixingCurveName).YieldCurve,
                           x => x.HistoricalIndexRates.Value = market.HistoricalIndexRates
                           ));
            }
        }
Exemplo n.º 8
0
        public override IMarketCondition GenerateMarketCondition(QdpMarket market)
        {
            var prebuiltMarket = market as PrebuiltQdpMarket;

            if (prebuiltMarket != null)
            {
                return(GenerateMarketConditionFromPrebuilt(prebuiltMarket));
            }
            else
            {
                var valuationParameter = TradeInfo.ValuationParamters;
                var mktQuote           = new Dictionary <string, Tuple <PriceQuoteType, double> >();
                try
                {
                    var futMktData = market.GetData <FuturesMktData>(TradeInfo.TradeId);
                    mktQuote[TradeInfo.TradeId] = futMktData != null?Tuple.Create(PriceQuoteType.Dirty, futMktData.FuturesPrice) : null;

                    foreach (var deliverableBondInfo in TradeInfo.DeliverableBondInfos)
                    {
                        var bondMktData = market.GetData <BondMktData>(deliverableBondInfo.TradeId);
                        if (bondMktData != null)
                        {
                            mktQuote[deliverableBondInfo.TradeId] = Tuple.Create(bondMktData.PriceQuoteType.ToPriceQuoteType(), bondMktData.Quote);
                        }
                        var tfBondId  = TradeInfo.TradeId + "_" + deliverableBondInfo.TradeId;
                        var tfMktData = market.GetData <TreasuryFutureMktData>(tfBondId);
                        if (tfMktData != null)
                        {
                            mktQuote[tfBondId] = Tuple.Create(tfMktData.PriceQuoteType.ToPriceQuoteType(), tfMktData.Quote);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new PricingBaseException(string.Format("Market price is missing, detailed message: {0}", ex.Message));
                }

                var fixingCurveName = valuationParameter.FixingCurveName;
                if (string.IsNullOrEmpty(fixingCurveName))
                {
                    fixingCurveName = valuationParameter.DiscountCurveName;
                }

                return(new MarketCondition(
                           x => x.ValuationDate.Value = market.ReferenceDate,
                           x => x.DiscountCurve.Value = market.GetData <CurveData>(valuationParameter.DiscountCurveName).YieldCurve,
                           x => x.FixingCurve.Value = market.GetData <CurveData>(fixingCurveName).YieldCurve,
                           x => x.RiskfreeCurve.Value = market.GetData <CurveData>(valuationParameter.RiskfreeCurveName).YieldCurve,
                           x => x.MktQuote.Value = mktQuote,
                           x => x.HistoricalIndexRates.Value = market.HistoricalIndexRates
                           ));
            }
        }
Exemplo n.º 9
0
        public void Fr007CurveConstructionTest()
        {
            var historiclIndexRates = HistoricalDataLoadHelper.HistoricalIndexRates;

            var fr007CurveName       = "Swap_Fr007";
            var fr007CurveConvention = new CurveConvention("fr007CurveConvention",
                                                           "CNY",
                                                           "ModifiedFollowing",
                                                           "Chn_ib",
                                                           "Act365",
                                                           "Continuous",
                                                           "CubicHermiteMonotic");
            var rateDefinition = new[]
            {
                new RateMktData("1D", 0.0431, "Fr007", "Deposit", fr007CurveName),
                new RateMktData("7D", 0.053, "Fr007", "Deposit", fr007CurveName),
                new RateMktData("3M", 0.0494, "Fr007", "InterestRateSwap", fr007CurveName),
                new RateMktData("6M", 0.0493, "Fr007", "InterestRateSwap", fr007CurveName),
            };

            var curveDefinition = new[]
            {
                new InstrumentCurveDefinition(fr007CurveName, fr007CurveConvention, rateDefinition, "SpotCurve")
            };

            var marketInfo = new MarketInfo("tmpMarket", "2014-02-10", curveDefinition, historiclIndexRates);
            var temp       = CalendarImpl.Get("chn_ib");

            QdpMarket market = null;

            var time1 = DateTime.Now;

            for (var i = 0; i <= 10; ++i)
            {
                var result = MarketFunctions.BuildMarket(marketInfo, out market);
            }
            var time2 = DateTime.Now;

            Console.WriteLine("{0}ms", (time2 - time1).TotalMilliseconds);
            var fr007Curve = market.GetData <CurveData>(fr007CurveName).YieldCurve;

            Assert.AreEqual(fr007Curve.KeyPoints[0].Item2, 0.0430974555290732, 1e-4);            // use IrsFloatingLegPvReal
            Assert.AreEqual(fr007Curve.KeyPoints[3].Item2, 0.048992349561639, 1e-4);             // use IrsFloatingLegPvReal
        }
Exemplo n.º 10
0
        public override IMarketCondition GenerateMarketCondition(QdpMarket market)
        {
            var prebuiltMarket = market as PrebuiltQdpMarket;

            if (prebuiltMarket != null)
            {
                return(GenerateMarketConditionFromPrebuilt(prebuiltMarket));
            }
            else
            {
                var ticker = TradeInfo.UnderlyingTicker;
                var spot   = market.GetData <StockMktData>(ticker).Price;
                return(new MarketCondition(
                           x => x.ValuationDate.Value = market.ReferenceDate,
                           x => x.SpotPrices.Value = new Dictionary <string, double> {
                    { "", spot }
                }
                           ));
            }
        }