Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableIRCap"/> class.
 /// </summary>
 /// <param name="baseDate">The base date.</param>
 /// <param name="identifier">The asset identifier.</param>
 /// <param name="rollDates">The roll dates. plus the maturity date. This array is an element longer than
 /// the notionals and strikes arrays.</param>
 /// <param name="notionals">The notionals for each caplet. There should be ne less than the number of roll dates.</param>
 /// <param name="strikes">The various strikes for each caplet. The same length as the notional list.</param>
 /// <param name="resets">An array of reset rates. This may be null.</param>
 /// <param name="resetOffset">The relative date offset for all the fixings.</param>
 /// <param name="paymentBusinessDayAdjustments">The payment business day adjustments.</param>
 /// <param name="capCalculation">The cap calculation.</param>
 /// <param name="fixingCalendar">The fixing Calendar.</param>
 public PriceableIRCap(DateTime baseDate, string identifier, List <DateTime> rollDates,
                       List <double> notionals, List <double> strikes, List <double> resets,
                       RelativeDateOffset resetOffset, BusinessDayAdjustments paymentBusinessDayAdjustments,
                       Calculation capCalculation, IBusinessCalendar fixingCalendar)
     : base(baseDate, paymentBusinessDayAdjustments, resetOffset, capCalculation, null)
 {
     Id          = identifier;
     SimpleIRCap = new SimpleIRSwap
     {
         dayCountFraction = capCalculation.dayCountFraction
     };
     ResetRates          = resets;
     RiskMaturityDate    = rollDates[rollDates.Count - 1];
     AdjustedPeriodDates = rollDates;
     AdjustedStartDate   = AdjustedPeriodDates[0];
     ExpiryDates         = GetResetDates(AdjustedPeriodDates, fixingCalendar, resetOffset, true);
     OptionsExpiryDate   = ExpiryDates[ExpiryDates.Count - 1];
     IsCap         = true;
     Strikes       = strikes;
     Notionals     = notionals;
     YearFractions = GetYearFractions();
     if (DiscountingType != null)
     {
         ModelIdentifier = "DiscountCapAsset";
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PriceableIRSwap"/> class.
        /// </summary>
        /// <param name="baseDate">The base date.</param>
        /// <param name="simpleIRSwap">This contains the minimal information for the swap.</param>
        /// <param name="spotDateOffset">All necessary data related to the spot period for the swap type.</param>
        /// <param name="calculation">Contians information related to the floating leg.</param>
        /// <param name="businessDayAdjustments">The business day adjustments for all payments.</param>
        /// <param name="underlyingRateIndex">Index of the floating leg.</param>
        /// <param name="fixingCalendar">The fixingCalendar.</param>
        /// <param name="paymentCalendar">The paymentCalendar.</param>
        /// <param name="fixedRate">The fixed rate.</param>
        public PriceableIRSwap(DateTime baseDate, SimpleIRSwap simpleIRSwap, RelativeDateOffset spotDateOffset,
                               Calculation calculation, BusinessDayAdjustments businessDayAdjustments, RateIndex underlyingRateIndex,
                               IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fixedRate)
            : base(baseDate, simpleIRSwap, spotDateOffset, calculation, businessDayAdjustments, underlyingRateIndex, fixingCalendar, paymentCalendar, fixedRate)
        {
            ModelIdentifier = DiscountingType == null ? "SwapAsset" : "DiscountSwapAsset";
            //The floating leg which is now non-zero.
            var unadjustedDateSchedule = DateScheduler.GetUnadjustedDateSchedule(AdjustedStartDate, SimpleIRSwap.term, UnderlyingRateIndex.term);

            FloatingLegAdjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(unadjustedDateSchedule, BusinessDayAdjustments.businessDayConvention, fixingCalendar);
            FloatingLegWeightings          = CreateWeightings(CDefaultWeightingValue, FloatingLegAdjustedPeriodDates.Count - 1);
            FloatingLegYearFractions       = GetFloatingLegYearFractions();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PriceableIRSwap"/> class.
        /// </summary>
        /// <param name="baseDate">The base date.</param>
        /// <param name="fixedLegSwap">The fixed leg details.</param>
        /// <param name="spotDate">the spot date.</param>
        /// <param name="notional">The notional amount.</param>
        /// <param name="paymentBusinessDayAdjustments">The business day adjustments.</param>
        /// <param name="floatingLegSwap">The floating leg details.</param>
        /// <param name="floatingLegcalculation">The floatingLegcalculation.</param>
        /// <param name="fixingDateOffset">The fixing date business day adjustments.</param>
        /// <param name="resetRates">The reset rates of the floating leg - if any.</param>
        /// <param name="fixingCalendar">The fixing calendar. If null, a new is constructed based on the business calendars.</param>
        /// <param name="paymentCalendar">The payment calendar. If null, a new is constructed based on the business calendars.</param>
        /// <param name="fixedRate">The fixed rate.</param>
        /// <param name="spread">The spread on the floating leg.</param>
        public PriceableIRSwap(DateTime baseDate, SimpleIRSwap fixedLegSwap, DateTime spotDate, MoneyBase notional,
                               BusinessDayAdjustments paymentBusinessDayAdjustments, SimpleIRSwap floatingLegSwap,
                               Calculation floatingLegcalculation, RelativeDateOffset fixingDateOffset, List <Decimal> resetRates,
                               IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fixedRate, BasicQuotation spread)
            : base(baseDate, fixedLegSwap, fixingDateOffset, floatingLegcalculation, paymentBusinessDayAdjustments, null, fixingCalendar, paymentCalendar, fixedRate)
        {
            ModelIdentifier     = DiscountingType == null ? "SwapAsset" : "DiscountSwapAsset";
            FloatingLegSpread   = GetSpread(spread);
            ForwardRates        = resetRates?.ToArray();
            UnderlyingRateIndex = RateIndexHelper.Parse(FloatingRateCalculation.floatingRateIndex.Value, notional.currency.Value, Calculation.dayCountFraction.Value);
            var unadjustedFloatingDates = DateScheduler.GetUnadjustedDateSchedule(spotDate, floatingLegSwap.term, floatingLegSwap.paymentFrequency);

            FloatingLegAdjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(unadjustedFloatingDates, paymentBusinessDayAdjustments.businessDayConvention, paymentCalendar);
            FloatingLegWeightings          = CreateWeightings(CDefaultWeightingValue, FloatingLegAdjustedPeriodDates.Count - 1);
            FloatingLegYearFractions       = GetFloatingLegYearFractions();
        }
Ejemplo n.º 4
0
        private static UnderlyingAsset CreateSimpleIRSwap(string marketInstrumentId)
        {
            var simpleIRSwap = new SimpleIRSwap();

            string[] slicedInstrumentId = marketInstrumentId.Split('-');
            string   instrumentCurrency = slicedInstrumentId[0];
            string   instrumentTerm     = slicedInstrumentId[2];

            simpleIRSwap.currency = new IdentifiedCurrency {
                Value = instrumentCurrency
            };
            simpleIRSwap.term                  = PeriodHelper.Parse(instrumentTerm);
            simpleIRSwap.instrumentId          = new[] { new InstrumentId() };
            simpleIRSwap.instrumentId[0].Value = marketInstrumentId;
            return(simpleIRSwap);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PriceableSimpleIRSwap"/> class.
        /// </summary>
        /// <param name="baseDate">The base date.</param>
        /// <param name="identifier">The asset identifier.</param>
        /// <param name="adjustedDates">The dates.</param>
        /// <param name="notionalWeights">The notionals, weighted by the first notional.</param>
        /// <param name="calculation">A calculation.</param>
        /// <param name="businessDayAdjustments">The business day adjustments.</param>
        /// <param name="underlyingRateIndex">Index of the rate.</param>
        /// <param name="fixedRate">The fixed rate.</param>
        public PriceableSimpleIRSwap(DateTime baseDate, string identifier, DateTime[] adjustedDates, Decimal[] notionalWeights,
                                     Calculation calculation, BusinessDayAdjustments businessDayAdjustments, RateIndex underlyingRateIndex,
                                     BasicQuotation fixedRate)
            : base(baseDate, businessDayAdjustments, calculation, fixedRate)
        {
            Id           = identifier;
            SimpleIRSwap = new SimpleIRSwap
            {
                dayCountFraction = calculation.dayCountFraction
            };
            UnderlyingRateIndex = underlyingRateIndex;
            RiskMaturityDate    = adjustedDates[adjustedDates.Length - 1];
            AdjustedPeriodDates = new List <DateTime>(adjustedDates);
            AdjustedStartDate   = AdjustedPeriodDates[0];
            Weightings          = notionalWeights;
            YearFractions       = GetYearFractions();
            ModelIdentifier     = DiscountingType == null ? "SimpleSwapAsset" : "SimpleDiscountSwapAsset";
            var timeToMaturity = Actual365.Instance.YearFraction(baseDate, RiskMaturityDate);

            EndDiscountFactor = (decimal)System.Math.Exp(-(double)fixedRate.value * timeToMaturity);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PriceableSimpleIRSwap"/> class.
        /// </summary>
        /// <param name="baseDate">The base date.</param>
        /// <param name="simpleIRSwap">THe FpML swap.</param>
        /// <param name="spotDate">The spot date.</param>
        /// <param name="calculation">A calculation.</param>
        /// <param name="stringRollConvention">The roll convention.</param>
        /// <param name="businessDayAdjustments">The business day adjustments.</param>
        /// <param name="underlyingRateIndex">Index of the rate.</param>
        /// <param name="fixingCalendar">The fixingCalendar.</param>
        /// <param name="paymentCalendar">The paymentCalendar.</param>
        /// <param name="fixedRate">The fixed rate.</param>
        public PriceableSimpleIRSwap(DateTime baseDate, SimpleIRSwap simpleIRSwap,
                                     DateTime spotDate, Calculation calculation, String stringRollConvention,
                                     BusinessDayAdjustments businessDayAdjustments, RateIndex underlyingRateIndex,
                                     IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fixedRate)
            : base(baseDate, businessDayAdjustments, calculation, fixedRate)
        {
            Id                  = simpleIRSwap.id;
            SimpleIRSwap        = simpleIRSwap;
            UnderlyingRateIndex = underlyingRateIndex;
            AdjustedStartDate   = spotDate;
            List <DateTime> unadjustedDateSchedule = DateScheduler.GetUnadjustedDateSchedule(AdjustedStartDate, SimpleIRSwap.term, SimpleIRSwap.paymentFrequency);

            AdjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(unadjustedDateSchedule, BusinessDayAdjustments.businessDayConvention, paymentCalendar);
            RiskMaturityDate    = AdjustedPeriodDates[AdjustedPeriodDates.Count - 1];
            Weightings          = CreateWeightings(CDefaultWeightingValue, AdjustedPeriodDates.Count - 1);
            YearFractions       = GetYearFractions();
            ModelIdentifier     = DiscountingType == null ? "SimpleSwapAsset" : "SimpleDiscountSwapAsset";
            var timeToMaturity = Actual365.Instance.YearFraction(baseDate, RiskMaturityDate);

            EndDiscountFactor = (decimal)System.Math.Exp(-(double)fixedRate.value * timeToMaturity);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PriceableIRCap"/> class.
        /// </summary>
        /// <param name="baseDate">The base date.</param>
        /// <param name="effectiveDate">The effective Date.</param>
        /// <param name="term">The cap term.</param>
        /// <param name="strike">The strike for each caplet.</param>
        /// <param name="lastResets">A list of reset rates. This may be null.</param>
        /// <param name="includeStubFlag">A flag: include the first stub period or not.</param>
        /// <param name="paymentFrequency">The caplet frequency.</param>
        /// <param name="rollBackward">A flag which determines whether to roll
        /// the dates: Backward or Forward. Currency this is ignored.</param>
        /// <param name="resetOffset">The relative date offset for all the fixings.</param>
        /// <param name="paymentBusinessDayAdjustments">The payment business day adjustments.</param>
        /// <param name="fixingCalendar">The fixing Calendar.</param>
        /// <param name="paymentCalendar">The payment Calendar.</param>
        /// <param name="capCalculation">The cap calculation.</param>
        public PriceableIRCap(DateTime baseDate, DateTime effectiveDate,
                              string term, Double strike, List <double> lastResets,
                              Boolean includeStubFlag, string paymentFrequency,
                              Boolean rollBackward, RelativeDateOffset resetOffset,
                              BusinessDayAdjustments paymentBusinessDayAdjustments, Calculation capCalculation,
                              IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar)
            : base(baseDate, paymentBusinessDayAdjustments, resetOffset, capCalculation, null)
        {
            Id          = "Local";
            SimpleIRCap = new SimpleIRSwap
            {
                dayCountFraction = capCalculation.dayCountFraction
            };
            ResetRates = lastResets;
            var unadjustedDates = Analytics.Schedulers.DateScheduler.GetUnadjustedDateSchedule(effectiveDate, PeriodHelper.Parse(term),
                                                                                               PeriodHelper.Parse(paymentFrequency));
            var adjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(unadjustedDates, paymentBusinessDayAdjustments.businessDayConvention, paymentCalendar);

            RiskMaturityDate   = adjustedPeriodDates[adjustedPeriodDates.Count - 1];
            IncludeFirstPeriod = includeStubFlag;
            //if (!includeStubFlag)
            //{
            //    adjustedPeriodDates.RemoveAt(0);
            //}
            AdjustedStartDate   = effectiveDate;
            AdjustedPeriodDates = adjustedPeriodDates;
            ExpiryDates         = GetResetDates(AdjustedPeriodDates, fixingCalendar, resetOffset, true);
            OptionsExpiryDate   = ExpiryDates[ExpiryDates.Count - 1];
            IsCap         = true;
            YearFractions = GetYearFractions();
            Strikes       = CreateList(strike, YearFractions.Count);
            Notionals     = CreateList((double)InitialNotional, YearFractions.Count);
            if (DiscountingType != null)
            {
                ModelIdentifier = "DiscountCapAsset";
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Parses the data.
        /// </summary>
        /// <param name="instrumentIds"></param>
        /// <returns></returns>
        public static QuotedAssetSet Parse(string[] instrumentIds)
        {
            var quotedAssetSetFactory = new QuotedAssetSetFactory();

            const string rateQuotationType = "MarketQuote";

            for (var i = 0; i < instrumentIds.Length; i++)
            {
                Asset underlyingAsset;

                var instrumentId = instrumentIds[i];
                var results      = instrumentIds[i].Split('-');
                var instrument   = results[1];

                var listBasicQuotations = new List <BasicQuotation>();

                const string priceUnitDecimalRate = "DecimalRate";

                switch (instrument)
                {
                case "ZeroRate":
                {
                    underlyingAsset = new Cash {
                        id = instrumentId
                    };
                    listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate));
                    break;
                }

                case "Xibor":
                case "OIS":
                {
                    var tenor = results[2];
                    underlyingAsset = new RateIndex {
                        id = instrumentId, term = Period.Parse(tenor)
                    };
                    listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate));
                    break;
                }

                case "IRSwap":
                case "XccySwap":
                case "SimpleIRSwap":
                {
                    underlyingAsset = new SimpleIRSwap {
                        id = instrumentId, term = Period.Parse(results[2])
                    };
                    listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate));
                    break;
                }

                case "Deposit":
                case "XccyDepo":
                case "BankBill":
                {
                    underlyingAsset = new Deposit {
                        id = instrumentId, term = Period.Parse(results[2])
                    };
                    listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate));
                    break;
                }

                case "SimpleFra":
                case "Fra":
                case "BillFra":
                {
                    var index = results[3];
                    var asset = new SimpleFra {
                        id = instrumentId, startTerm = Period.Parse(results[2])
                    };

                    asset.endTerm   = asset.startTerm.Sum(Period.Parse(index));
                    underlyingAsset = asset;
                    listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate));
                    break;
                }

                case "IRFuture":
                {
                    underlyingAsset = new Future {
                        id = instrumentId
                    };
                    listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate));
                    listBasicQuotations.Add(BasicQuotationHelper.Create("Volatility", "LognormalVolatility"));
                    break;
                }

                case "CPIndex":
                {
                    var tenor = results[2];
                    underlyingAsset = new RateIndex {
                        id = instrumentId, term = Period.Parse(tenor)
                    };
                    listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate));
                    break;
                }

                case "SimpleCPISwap":
                case "CPISwap":
                case "ZCCPISwap":
                {
                    underlyingAsset = new SimpleIRSwap {
                        id = instrumentId, term = Period.Parse(results[2])
                    };
                    listBasicQuotations.Add(BasicQuotationHelper.Create(rateQuotationType, priceUnitDecimalRate));
                    break;
                }

                default:
                    throw new NotSupportedException(string.Format("Asset type {0} is not supported", instrument));
                }

                quotedAssetSetFactory.AddAssetAndQuotes(underlyingAsset, Helpers.BasicAssetValuationHelper.Create(underlyingAsset.id, listBasicQuotations.ToArray()));
            }
            return(quotedAssetSetFactory.Create());
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Parses the string info into an asset.
        /// </summary>
        /// <param name="instrumentId"></param>
        /// <param name="value"></param>
        /// <param name="adjustment"></param>
        /// <returns></returns>
        public static Pair <Asset, BasicAssetValuation> Parse(string instrumentId, decimal value, decimal adjustment)
        {
            const string rateQuotationType = "MarketQuote";
            Asset        underlyingAsset;
            var          results             = instrumentId.Split('-');
            var          instrument          = results[1];
            var          listBasicQuotations = new List <BasicQuotation>();

            switch (instrument)
            {
            case "ZeroRate":
            {
                var zeroRate = new Cash {
                    id = instrumentId
                };
                underlyingAsset = zeroRate;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));
                break;
            }

            case "Xibor":
            case "OIS":
            {
                var tenor     = results[2];
                var rateIndex = new RateIndex {
                    id = instrumentId, term = Period.Parse(tenor)
                };
                underlyingAsset = rateIndex;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "DecimalRate"));
                break;
            }

            case "IRSwap":
            case "XccySwap":
            case "SimpleIRSwap":
            {
                var simpleIRSwap = new SimpleIRSwap {
                    id = instrumentId, term = Period.Parse(results[2])
                };
                underlyingAsset = simpleIRSwap;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "DecimalRate"));
                break;
            }

            case "Deposit":
            case "XccyDepo":
            case "BankBill":
            {
                var deposit = new Deposit {
                    id = instrumentId, term = Period.Parse(results[2])
                };
                underlyingAsset = deposit;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "DecimalRate"));
                break;
            }

            case "SimpleFra":
            case "Fra":
            case "BillFra":
            case "SpreadFra":
            {
                var index = results[3];
                var asset = new SimpleFra {
                    id = instrumentId, startTerm = Period.Parse(results[2])
                };

                asset.endTerm   = asset.startTerm.Sum(Period.Parse(index));
                underlyingAsset = asset;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "DecimalRate"));
                break;
            }

            case "IRCap":
            {
                var simpleIRCap = new SimpleIRSwap {
                    id = instrumentId, term = Period.Parse(results[2])
                };
                underlyingAsset = simpleIRCap;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, "Premium", "Amount"));
                break;
            }

            case "IRFuture":
            {
                var future = new Future {
                    id = instrumentId
                };

                underlyingAsset = future;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));
                listBasicQuotations.Add(BasicQuotationHelper.Create(adjustment, "Volatility", "LognormalVolatility"));
                break;
            }

            case "CommodityFuture":
            {
                var future = new Future {
                    id = instrumentId
                };

                underlyingAsset = future;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));
                break;
            }

            case "CPIndex":
            {
                var tenor     = results[2];
                var rateIndex = new RateIndex {
                    id = instrumentId, term = Period.Parse(tenor)
                };
                underlyingAsset = rateIndex;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "DecimalRate"));
                break;
            }

            case "SimpleCPISwap":
            case "CPISwap":
            case "ZCCPISwap":
            {
                var simpleIRSwap = new SimpleIRSwap {
                    id = instrumentId, term = Period.Parse(results[2])
                };
                underlyingAsset = simpleIRSwap;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "DecimalRate"));
                break;
            }

            case "FxSpot":
            case "FxForward":
            {
                //  var tenor = results[2];
                var fxRateAsset = new FxRateAsset {
                    id = instrumentId
                };
                underlyingAsset = fxRateAsset;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + adjustment, rateQuotationType, "FxRate"));
                break;
            }

            case "CommoditySpot":
            case "CommodityForward":
            {
                var commodityAsset = new FxRateAsset {
                    id = instrumentId
                };
                underlyingAsset = commodityAsset;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "Price"));
                break;
            }

            case "Bond":
            {
                var asset = new Bond {
                    id = instrumentId
                };
                underlyingAsset = asset;
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DirtyPrice"));
                break;
            }

            default:
                throw new NotSupportedException(string.Format("Asset type {0} is not supported", instrument));
            }

            return(new Pair <Asset, BasicAssetValuation>(underlyingAsset, Helpers.BasicAssetValuationHelper.Create(underlyingAsset.id, listBasicQuotations.ToArray())));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Parses the string info into an asset.
        /// </summary>
        /// <param name="instrumentId"></param>
        /// <param name="value"></param>
        /// <param name="adjustment"></param>
        /// <returns></returns>
        public static Pair <Asset, BasicAssetValuation> Parse(string instrumentId, decimal value, decimal?adjustment)
        {
            const string rateQuotationType       = PriceableSimpleRateAsset.RateQuotationType;
            const string volatilityQuotationType = PriceableCapRateAsset.VolatilityQuotationType;
            Asset        underlyingAsset;
            decimal      additional = 0.0m;

            if (adjustment != null)
            {
                additional = (decimal)adjustment;
            }
            var listBasicQuotations = new List <BasicQuotation>();
            var properties          = new PriceableAssetProperties(instrumentId);

            switch (properties.AssetType)
            {
            //This is in place to handle volatility curves where the tenor is the expiry.
            case AssetTypesEnum.Period:
            {
                //There is no underlying asset.
                underlyingAsset = null;
                listBasicQuotations.Add(BasicQuotationHelper.Create(instrumentId, value, volatilityQuotationType, "LognormalVolatility"));
                break;
            }

            case AssetTypesEnum.ZeroRate:
            {
                underlyingAsset = new Cash {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.Xibor:
            case AssetTypesEnum.OIS:
            {
                underlyingAsset = new RateIndex {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.IRSwap:
            case AssetTypesEnum.ClearedIRSwap:
            case AssetTypesEnum.OISSwap:
            case AssetTypesEnum.XccySwap:
            case AssetTypesEnum.SimpleIRSwap:
            case AssetTypesEnum.XccyBasisSwap:
            case AssetTypesEnum.BasisSwap:
            case AssetTypesEnum.ResettableXccyBasisSwap:
            {
                underlyingAsset = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.Caplet:
            case AssetTypesEnum.Floorlet:
            case AssetTypesEnum.BillCaplet:
            case AssetTypesEnum.BillFloorlet:
            {
                underlyingAsset = new SimpleFra
                {
                    id        = instrumentId,
                    startTerm = properties.TermTenor,
                    endTerm   = properties.TermTenor.Sum(properties.ForwardIndex)
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Strike", "DecimalRate"));
                }
                break;
            }

            case AssetTypesEnum.Deposit:
            case AssetTypesEnum.SpreadDeposit:
            case AssetTypesEnum.XccyDepo:
            case AssetTypesEnum.BankBill:
            case AssetTypesEnum.Repo:
            case AssetTypesEnum.RepoSpread:
            {
                underlyingAsset = new Deposit {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.SimpleFra:
            case AssetTypesEnum.Fra:
            case AssetTypesEnum.BillFra:
            case AssetTypesEnum.SpreadFra:
            {
                underlyingAsset = new SimpleFra
                {
                    id        = instrumentId,
                    startTerm = properties.TermTenor,
                    endTerm   = properties.TermTenor.Sum(properties.ForwardIndex)      //TODO this restricts the perios to be the same!!!
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.Swaption:
            {
                underlyingAsset = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Strike", "DecimalRate"));
                }
                break;
            }

            case AssetTypesEnum.IRFloor:
            case AssetTypesEnum.IRCap:
            {
                underlyingAsset = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Strike", "DecimalRate"));
                }
                break;
            }

            case AssetTypesEnum.IRFutureOption:
            case AssetTypesEnum.IRCallFutureOption:
            case AssetTypesEnum.IRPutFutureOption:
            {
                underlyingAsset = new Future {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Strike", "DecimalRate"));
                }
                break;
            }

            case AssetTypesEnum.IRFuture:
            {
                underlyingAsset = new Future {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Volatility", "LognormalVolatility"));
                }
                break;
            }

            case AssetTypesEnum.CommodityFuture:
            case AssetTypesEnum.CommodityFutureSpread:
            {
                underlyingAsset = new Future {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.CPIndex:
            {
                underlyingAsset = new RateIndex {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.SimpleCPISwap:
            case AssetTypesEnum.CPISwap:
            case AssetTypesEnum.ZCCPISwap:
            {
                underlyingAsset = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.FxSpot:
            case AssetTypesEnum.FxForward:
            {
                underlyingAsset = new FxRateAsset {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "FxRate"));
                break;
            }

            case AssetTypesEnum.Equity:
            case AssetTypesEnum.EquityForward:
            {
                underlyingAsset = new EquityAsset {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "Price"));
                break;
            }

            case AssetTypesEnum.CommoditySpot:
            case AssetTypesEnum.CommodityForward:
            case AssetTypesEnum.CommodityAverageForward:
            case AssetTypesEnum.CommoditySpread:
            {
                underlyingAsset = new Commodity {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "Price"));
                break;
            }

            case AssetTypesEnum.Bond:
            case AssetTypesEnum.BondSpot:
            case AssetTypesEnum.BondForward:
            {
                underlyingAsset = new Bond {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));        //Changed from DirtyPrice.
                break;
            }

            case AssetTypesEnum.Lease:
            {
                underlyingAsset = new Lease {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "Price"));
                break;
            }

            default:
                throw new NotSupportedException($"Asset type {properties.AssetType} is not supported");
            }
            var id = underlyingAsset?.id;

            if (underlyingAsset == null)
            {
                id = listBasicQuotations[0].id;
            }
            return(new Pair <Asset, BasicAssetValuation>(underlyingAsset, BasicAssetValuationHelper.Create(id, listBasicQuotations.ToArray())));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Parses the string info into an asset.
        /// </summary>
        /// <param name="instrumentId"></param>
        /// <returns></returns>
        public static Asset Parse(string instrumentId)
        {
            Asset underlyingAsset;
            var   properties = new PriceableAssetProperties(instrumentId);

            switch (properties.AssetType)
            {
            case AssetTypesEnum.ZeroRate:
            {
                var zeroRate = new Cash {
                    id = instrumentId
                };
                underlyingAsset = zeroRate;
                break;
            }

            case AssetTypesEnum.Xibor:
            case AssetTypesEnum.OIS:
            {
                var rateIndex = new RateIndex {
                    id = instrumentId, term = properties.TermTenor
                };
                underlyingAsset = rateIndex;
                break;
            }

            case AssetTypesEnum.IRSwap:
            case AssetTypesEnum.ClearedIRSwap:
            case AssetTypesEnum.OISSwap:
            case AssetTypesEnum.XccySwap:
            case AssetTypesEnum.SimpleIRSwap:
            case AssetTypesEnum.XccyBasisSwap:
            case AssetTypesEnum.BasisSwap:
            case AssetTypesEnum.ResettableXccyBasisSwap:
            {
                var simpleIRSwap = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                underlyingAsset = simpleIRSwap;
                break;
            }

            case AssetTypesEnum.Deposit:
            case AssetTypesEnum.SpreadDeposit:
            case AssetTypesEnum.XccyDepo:
            case AssetTypesEnum.BankBill:
            case AssetTypesEnum.Repo:
            case AssetTypesEnum.RepoSpread:
            {
                var deposit = new Deposit {
                    id = instrumentId, term = properties.TermTenor
                };
                underlyingAsset = deposit;
                break;
            }

            case AssetTypesEnum.SimpleFra:
            case AssetTypesEnum.Fra:
            case AssetTypesEnum.BillFra:
            case AssetTypesEnum.SpreadFra:
            {
                var simpleFra = new SimpleFra {
                    id = instrumentId, startTerm = properties.TermTenor
                };
                if (properties.ForwardIndex == null)
                {
                    throw new ArgumentException("ForwardIndex must be set in the instrumentId " + instrumentId,
                                                nameof(instrumentId));
                }
                simpleFra.endTerm = simpleFra.startTerm.Sum(properties.ForwardIndex);
                underlyingAsset   = simpleFra;
                break;
            }

            case AssetTypesEnum.IRFloor:
            case AssetTypesEnum.IRCap:
            {
                var simpleIRCap = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                underlyingAsset = simpleIRCap;
                break;
            }

            case AssetTypesEnum.IRFutureOption:
            case AssetTypesEnum.IRFuture:
            {
                var future = new Future {
                    id = instrumentId
                };
                underlyingAsset = future;
                break;
            }

            case AssetTypesEnum.CommodityFuture:
            case AssetTypesEnum.CommodityFutureSpread:
            {
                var future = new Future {
                    id = instrumentId
                };
                underlyingAsset = future;
                break;
            }

            case AssetTypesEnum.CPIndex:
            {
                var rateIndex = new RateIndex {
                    id = instrumentId, term = properties.TermTenor
                };
                underlyingAsset = rateIndex;
                break;
            }

            case AssetTypesEnum.SimpleCPISwap:
            case AssetTypesEnum.CPISwap:
            case AssetTypesEnum.ZCCPISwap:
            {
                var simpleIRSwap = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                underlyingAsset = simpleIRSwap;
                break;
            }

            case AssetTypesEnum.Equity:
            case AssetTypesEnum.EquityForward:
            {
                //  var tenor = results[2];
                var equityAsset = new EquityAsset {
                    id = instrumentId
                };
                underlyingAsset = equityAsset;
                break;
            }

            case AssetTypesEnum.FxSpot:
            case AssetTypesEnum.FxForward:
            {
                //  var tenor = results[2];
                var fxRateAsset = new FxRateAsset {
                    id = instrumentId
                };
                underlyingAsset = fxRateAsset;
                break;
            }

            case AssetTypesEnum.CommoditySpot:
            case AssetTypesEnum.CommodityForward:
            case AssetTypesEnum.CommodityAverageForward:
            case AssetTypesEnum.CommoditySpread:
            {
                var commodityAsset = new Commodity {
                    id = instrumentId
                };
                underlyingAsset = commodityAsset;
                break;
            }

            case AssetTypesEnum.Bond:
            case AssetTypesEnum.BondSpot:
            case AssetTypesEnum.BondForward:
            {
                var bond = new Bond {
                    id = instrumentId
                };
                underlyingAsset = bond;
                break;
            }

            default:
                throw new NotSupportedException($"Asset type {properties.AssetType} is not supported");
            }
            return(underlyingAsset);
        }