/// <summary> /// Initializes a new instance of the <see cref="CommoditySpreadCurve2"/> class. /// </summary> /// <param name="referenceCurve">The reference curve.</param> /// <param name="spreadAssets">The spreads by asset.</param> /// <param name="properties">The properties of the new spread curve.</param> /// <param name="algorithm">The alogorithm holder. </param> public CommoditySpreadCurve2(NamedValueSet properties, ICommodityCurve referenceCurve, List <IPriceableCommoditySpreadAssetController> spreadAssets, PricingStructureAlgorithmsHolder algorithm) : base(properties, algorithm) { PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Commodity, properties); //Set the identifier. var pricingStructureId = GetCommodityCurveId(); if (pricingStructureId.PricingStructureType != PricingStructureTypeEnum.CommoditySpreadCurve) { return; } //Set the reference curve BaseCurve = referenceCurve; ReferenceCurveId = BaseCurve.GetPricingStructureId(); PriceableCommoditySpreadAssets = spreadAssets; //Order the assets. PriceableCommoditySpreadAssets = PriceableCommoditySpreadAssets.OrderBy(a => a.GetRiskMaturityDate()).ToList(); var termCurve = SetConfigurationData(); //Get the reference interpolated curve. IList <Double> xArray = new List <double>(); IList <Double> yArray = new List <double>(); termCurve.point = CommoditySpreadBootstrapper2.Bootstrap(PriceableCommoditySpreadAssets, BaseCurve, pricingStructureId.BaseDate, termCurve.extrapolationPermitted, Tolerance, ref xArray, ref yArray); CreatePricingStructure(pricingStructureId, termCurve, PriceableAssetFactory.Parse(PriceableCommoditySpreadAssets)); SetInterpolator(BaseCurve, xArray, yArray, pricingStructureId.PricingStructureType); }
/// <summary> /// Initializes a new instance of the <see cref="RateBasisCurve"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">The client namespace</param> /// <param name="referenceCurveData">The market data. This must contain both the underlying base curve and the spread curve. /// Otherwise the RateBasisInterpolator can not instantiate.</param> /// <param name="derivedCurveData">The spread Curve Data</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="rollCalendar">The rollCalendar.</param> public ClearedRateCurve(ILogger logger, ICoreCache cache, String nameSpace, Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> referenceCurveData, Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> derivedCurveData, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar) : base(derivedCurveData.Third, GenerateHolder(logger, cache, nameSpace, derivedCurveData.Third)) { PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, derivedCurveData.Third); var curveId = GetRateCurveId(); //Set the identifier. var nvs = derivedCurveData.Third; var pricingStructureId = GetRateCurveId(); var refCurveId = PropertyHelper.ExtractReferenceCurveUniqueId(nvs); ReferenceDiscountingCurveId = refCurveId != null ? new Identifier(refCurveId) : ReferenceDiscountingCurveId = null; if (pricingStructureId.PricingStructureType != PricingStructureTypeEnum.ClearedRateCurve) { return; } //Set the reference curve var baseCurveFpml = new Pair <PricingStructure, PricingStructureValuation>(referenceCurveData.First, referenceCurveData.Second); var baseCurveProps = referenceCurveData.Third; BaseDiscountingCurve = (IRateCurve)PricingStructureFactory.Create(logger, cache, nameSpace, fixingCalendar, rollCalendar, baseCurveFpml, baseCurveProps); //Get the spread Data var spreadCurveFpml = new Pair <PricingStructure, PricingStructureValuation>(derivedCurveData.First, derivedCurveData.Second); //Override properties. //var optimize = PropertyHelper.ExtractOptimizeBuildFlag(properties); var bootstrap = PropertyHelper.ExtractBootStrapOverrideFlag(nvs); var tempFpml = (YieldCurveValuation)spreadCurveFpml.Second; var spreadAssets = tempFpml.inputs; //This is to catch it when there are no discount factor points. var discountsAbsent = tempFpml.discountFactorCurve?.point == null || tempFpml.discountFactorCurve.point.Length == 0; var indexTenor = curveId.ForecastRateIndex?.indexTenor; if (bootstrap || discountsAbsent) { //There must be a valid quoted asset set in order to bootstrap. if (!XsdClassesFieldResolver.QuotedAssetSetIsValid(spreadAssets)) { return; } PriceableClearedRateAssets = PriceableAssetFactory.CreatePriceableClearedRateAssetsWithBasisSwaps(logger, cache, nameSpace, indexTenor, spreadAssets, pricingStructureId.BaseDate, fixingCalendar, rollCalendar); GetYieldCurveValuation().zeroCurve = null; TermCurve termCurve = tempFpml.discountFactorCurve ?? SetConfigurationData(); DateTime baseDate = GetYieldCurveValuation().baseDate.Value; termCurve.point = ClearedRateBootstrapper.Bootstrap(PriceableClearedRateAssets, BaseDiscountingCurve, baseDate, termCurve.extrapolationPermitted, termCurve.interpolationMethod, Tolerance); SetFpMLData(new Pair <PricingStructure, PricingStructureValuation>(PricingStructure, PricingStructureValuation), false); SetInterpolator(termCurve); } else { // the discount curve is already built, so don't rebuild PriceableClearedRateAssets = PriceableAssetFactory.CreatePriceableClearedRateAssetsWithBasisSwaps(logger, cache, nameSpace, indexTenor, spreadAssets, pricingStructureId.BaseDate, fixingCalendar, rollCalendar); //Order the assets. PriceableClearedRateAssets = PriceableClearedRateAssets.OrderBy(a => a.GetRiskMaturityDate()).ToList(); CreatePricingStructure(pricingStructureId, tempFpml.discountFactorCurve, spreadAssets); // CreatePricingStructure(pricingStructureId, tempFpml.discountFactorCurve, PriceableAssetFactory.Parse(PriceableClearedRateAssets)); SetInterpolator(GetYieldCurveValuation().discountFactorCurve); } }
/// <summary> /// Initializes a new instance of the <see cref="RateBasisCurve"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">The client namespace</param> /// <param name="baseDiscountingCurve">The reference curve.</param> /// <param name="clearedRateAssets">The cleared rate asset.</param> /// <param name="properties">The properties of the new spread curve.</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="rollCalendar">The rollCalendar.</param> public ClearedRateCurve(ILogger logger, ICoreCache cache, string nameSpace, IRateCurve baseDiscountingCurve, QuotedAssetSet clearedRateAssets, NamedValueSet properties, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar) : base(logger, cache, nameSpace, new RateCurveIdentifier(properties), fixingCalendar, rollCalendar) { PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, properties); BaseDiscountingCurve = baseDiscountingCurve; ReferenceDiscountingCurveId = BaseDiscountingCurve.GetPricingStructureId(); if (PricingStructureIdentifier.PricingStructureType != PricingStructureTypeEnum.ClearedRateCurve) { return; } var termCurve = SetConfigurationData(); var curveId = GetRateCurveId(); var indexTenor = curveId.ForecastRateIndex?.indexTenor; //Set the priceable assets. PriceableClearedRateAssets = PriceableAssetFactory.CreatePriceableClearedRateAssetsWithBasisSwaps(logger, cache, nameSpace, indexTenor, clearedRateAssets, PricingStructureIdentifier.BaseDate, fixingCalendar, rollCalendar); termCurve.point = ClearedRateBootstrapper.Bootstrap(PriceableClearedRateAssets, BaseDiscountingCurve, curveId.BaseDate, termCurve.extrapolationPermitted, termCurve.interpolationMethod, Tolerance); CreatePricingStructure(curveId, termCurve, clearedRateAssets); // CreatePricingStructure(curveId, termCurve, PriceableAssetFactory.Parse(PriceableClearedRateAssets)); // Interpolate the DiscountFactor curve based on the respective curve interpolation SetInterpolator(termCurve); }
/// <summary> /// Initializes a new instance of the <see cref="ClearedRateCurve"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">The client namespace</param> /// <param name="fpmlData">The FPML data.</param> /// <param name="properties">The properties.</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="rollCalendar">The rollCalendar.</param> public ClearedRateCurve(ILogger logger, ICoreCache cache, string nameSpace, Pair <PricingStructure, PricingStructureValuation> fpmlData, NamedValueSet properties, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar) : base(logger, cache, nameSpace, new RateCurveIdentifier(properties), fixingCalendar, rollCalendar) { PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, properties); var refCurveId = PropertyHelper.ExtractReferenceCurveUniqueId(properties); ReferenceDiscountingCurveId = refCurveId != null ? new Identifier(refCurveId) : ReferenceDiscountingCurveId = null; var tempFpml = (YieldCurveValuation)fpmlData.Second; var curveId = GetRateCurveId(); Initialize(properties, Holder); FixingCalendar = fixingCalendar; PaymentCalendar = rollCalendar; //Override properties. //var optimize = PropertyHelper.ExtractOptimizeBuildFlag(properties);//TODO removed optimisation as it means that partial hedges can not be undertaken. var bootstrap = PropertyHelper.ExtractBootStrapOverrideFlag(properties); var termCurve = SetConfigurationData(); var qas = tempFpml.inputs; var indexTenor = curveId.ForecastRateIndex?.indexTenor; //This is to catch it when there are no discount factor points. var discountsAbsent = tempFpml.discountFactorCurve?.point == null || tempFpml.discountFactorCurve.point.Length == 0; //This is an override if the cache is null, as the bootstrapper will not work. if (cache == null) { //optimize = true; bootstrap = false; } bool validAssets = XsdClassesFieldResolver.QuotedAssetSetIsValid(qas); //Test to see if a bootstrap is required. if (bootstrap || discountsAbsent) { //There must be a valid quoted asset set in order to bootstrap. if (!validAssets) { return; } PriceableClearedRateAssets = PriceableAssetFactory.CreatePriceableClearedRateAssetsWithBasisSwaps(logger, cache, nameSpace, indexTenor, qas, GetRateCurveId().BaseDate, fixingCalendar, rollCalendar); termCurve.point = RateBootstrapper.Bootstrap(PriceableClearedRateAssets, curveId.BaseDate, termCurve.extrapolationPermitted, termCurve.interpolationMethod, Tolerance); CreatePricingStructure(curveId, termCurve, qas); SetInterpolator(termCurve); } else { // the discount curve is already built, so don't rebuild SetFpMLData(fpmlData, false); SetInterpolator(((YieldCurveValuation)PricingStructureValuation).discountFactorCurve); //Set the priceable assets. if (validAssets)//!optimize && { PriceableClearedRateAssets = PriceableAssetFactory.CreatePriceableClearedRateAssetsWithBasisSwaps(logger, cache, nameSpace, indexTenor, qas, GetRateCurveId().BaseDate, fixingCalendar, rollCalendar); } } }
///// <summary> ///// Create a surface from an FpML ///// </summary> ///// <param name="fpmlData"></param> //public ExtendedEquityVolatilitySurface(Pair<PricingStructure, PricingStructureValuation> fpmlData) // : this(fpmlData, PricingStructurePropertyHelper.EquityVolatilityMatrix(fpmlData)) //{} /// <summary> /// Create a surface from an FpML /// </summary> /// <param name="nameSpace">The nameSpace</param> /// <param name="fpmlData">The data.</param> /// <param name="logger"></param> /// <param name="cache">The cache.</param> /// <param name="properties">The properties.</param> public ExtendedEquityVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, Pair <PricingStructure, PricingStructureValuation> fpmlData, NamedValueSet properties) : base(logger, cache, nameSpace, fpmlData, properties) { PricingStructureData = new PricingStructureData(CurveType.Parent, Constants.AssetClass.Equity); }
public SABRVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, NamedValueSet properties, String[] expiryTenors, Double[] strikes, Double[,] volSurface) : base(logger, cache, nameSpace, properties, expiryTenors, strikes, volSurface) { var assetClass = properties.GetString(CurveProp.AssetClass, true); var type = EnumHelper.Parse <AssetClass>(assetClass); var assetId = properties.GetValue <string>(CurveProp.AssetId, true); var baseDate = properties.GetValue <DateTime>(CurveProp.BaseDate, true); PricingStructureData = new PricingStructureData(CurveType.Parent, type); UnderlyingPriceableAssets = new List <IPriceableAssetController>(); foreach (var tenor in expiryTenors) { var expiryTenor = PeriodHelper.Parse(tenor); var offset = new Offset { period = expiryTenor.period, periodMultiplier = expiryTenor.periodMultiplier, periodSpecified = true, dayType = DayTypeEnum.Calendar, dayTypeSpecified = true }; var expiryDate = offset.Add(baseDate); var assetProperties = PriceableAssetFactory.BuildPropertiesForAssets(nameSpace, assetId, expiryDate); var asset = PriceableAssetFactory.Create(logger, cache, nameSpace, null, assetProperties, null, null); UnderlyingPriceableAssets.Add(asset); } }
/// <summary> /// Takes a range of volatilities, an array of tenor expiries and an /// array of strikes to create a VolatilitySurface /// </summary> /// <param name="expiryTenors">the expiry tenors.</param> /// <param name="strikes">The strikes.</param> /// <param name="volSurface">The vol surface.</param> /// <param name="nameSpace">The nameSpace</param> /// <param name="properties">The properties.</param> /// <param name="logger"></param> /// <param name="cache">The cache.</param> /// <param name="forwards">The array of forwards. The first element is the spot value. Consequently, the length of this array is expiryTenors.Length + 1.</param> public ExtendedEquityVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, NamedValueSet properties, String[] expiryTenors, Double[] strikes, Double[] forwards, Double[,] volSurface) : base(logger, cache, nameSpace, properties, expiryTenors, strikes, forwards, volSurface) { PricingStructureData = new PricingStructureData(CurveType.Parent, Constants.AssetClass.Equity); }
/// <summary> /// Create a surface from an FpML /// </summary> /// <param name="fpmlData"></param> public VolatilityCube(Pair <PricingStructure, PricingStructureValuation> fpmlData) : base(fpmlData) { PricingStructureData = new PricingStructureData(CurveType.Parent, Constants.AssetClass.Rates);//TODO Need to set for the different underlyers. SetInterpolator(); _matrixIndexHelper = new SortedList <ExpiryTenorStrikeKey, int>(new ExpiryTenorStrikeKey()); ProcessVolatilityRepresentation(); }
/// <summary> /// Create a surface from an FpML /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">The nameSpace</param> /// <param name="fpmlData">The data.</param> /// <param name="properties">The properties.</param> public SABRVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, Pair <PricingStructure, PricingStructureValuation> fpmlData, NamedValueSet properties) : base(logger, cache, nameSpace, fpmlData, properties) { var assetClass = properties.GetString(CurveProp.AssetClass, true); var type = EnumHelper.Parse <AssetClass>(assetClass); PricingStructureData = new PricingStructureData(CurveType.Parent, type); }
/// <summary> /// Initializes a new instance of the <see cref="RateSpreadCurve"/> class. /// </summary> /// <param name="referenceCurve">The reference curve.</param> /// <param name="spreadAssets">The spreads by asset.</param> /// <param name="properties">The properties of the new spread curve.</param> /// <param name="algorithm">The algorithm holder. </param> public RateSpreadCurve(NamedValueSet properties, IRateCurve referenceCurve, List <IPriceableRateSpreadAssetController> spreadAssets, PricingStructureAlgorithmsHolder algorithm) : base(properties, algorithm) { PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, properties); PriceableSpreadAssets = spreadAssets; BaseCurve = referenceCurve; }
/// <summary> /// Initializes a new instance of the <see cref="CurveBase"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">The nameSpace</param> /// <param name="curveIdentifier">The curveIdentifier.</param> protected CommodityCurve(ILogger logger, ICoreCache cache, String nameSpace, PricingStructureIdentifier curveIdentifier) : base(logger, cache, nameSpace, curveIdentifier) { var properties = curveIdentifier.GetProperties(); PricingStructureData = new PricingStructureData(CurveType.Parent, AssetClass.Commodity, properties); Tolerance = PropertyHelper.ExtractDoubleProperty("Tolerance", properties) ?? GetDefaultTolerance(Holder); }
/// <summary> /// Initializes a new instance of the <see cref="RateBasisCurve"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">The client namespace</param> /// <param name="properties">The properties.</param> /// <param name="refCurve">The reference parent curve id.</param> /// <param name="value">The values.</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="rollCalendar">The rollCalendar.</param> public RateBasisCurve(ILogger logger, ICoreCache cache, string nameSpace, NamedValueSet properties, IPricingStructure refCurve, Decimal value, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar) : base(logger, cache, nameSpace, AdjustMarketQuotes(value, refCurve.GetFpMLData(), PropertyHelper.ExtractUniqueCurveIdentifier(properties)), properties, fixingCalendar, rollCalendar) { PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, properties); ReferenceCurveId = refCurve.GetPricingStructureId(); }
/// <summary> /// Initializes a new instance of the <see cref="CurveBase"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">The nameSpace</param> /// <param name="curveIdentifier">The curveIdentifier.</param> protected RateSpreadCurve(ILogger logger, ICoreCache cache, String nameSpace, PricingStructureIdentifier curveIdentifier) : base(logger, cache, nameSpace, curveIdentifier) { var properties = curveIdentifier.GetProperties(); PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, properties); }
/// <summary> /// /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace"></param> /// <param name="properties"></param> /// <param name="expiries"></param> /// <param name="vols"></param> /// <param name="inputInstruments"></param> /// <param name="inputSwapRates"></param> /// <param name="blackVolatilities"></param> public SABRVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, NamedValueSet properties, DateTime[] expiries, double[] vols, string[] inputInstruments, double[] inputSwapRates, double[] blackVolatilities) : base(logger, cache, nameSpace, properties, expiries, vols, inputInstruments, inputSwapRates, blackVolatilities) { var assetClass = properties.GetString(CurveProp.AssetClass, true); var type = EnumHelper.Parse <AssetClass>(assetClass); PricingStructureData = new PricingStructureData(CurveType.Parent, type); }
/// <summary> /// Initializes a new instance of the <see cref="RateSpreadCurve"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">The client namespace</param> /// <param name="referenceCurve">The reference parent curve id.</param> /// <param name="spreadAssets">The spreads by asset.</param> /// <param name="properties">The properties of the new spread curve.</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="rollCalendar">The rollCalendar.</param> public RateSpreadCurve(ILogger logger, ICoreCache cache, string nameSpace, IRateCurve referenceCurve, QuotedAssetSet spreadAssets, NamedValueSet properties, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar) : base(logger, cache, nameSpace, ProcessQuotedAssetSet(logger, cache, nameSpace, referenceCurve, spreadAssets, properties, fixingCalendar, rollCalendar), properties, fixingCalendar, rollCalendar) { PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, properties); BaseCurve = referenceCurve; ReferenceCurveId = BaseCurve.GetPricingStructureId(); }
/// <summary> /// Takes a range of volatilities, an array of tenor expiries and an /// array of strikes to create a VolatilitySurface /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="instrumentIds">A set of valid instrumentIds</param> /// <param name="expiryTenors">the expiry tenors.</param> /// <param name="strikes">The strikes.</param> /// <param name="values">The values.</param> /// <param name="nameSpace">The nameSpace</param> /// <param name="properties">The properties.</param> public SABRVolatilitySurface(ILogger logger, ICoreCache cache, String nameSpace, NamedValueSet properties, String[] instrumentIds, String[] expiryTenors, Double[] strikes, Double[,] values) : base(logger, cache, nameSpace, properties, expiryTenors, strikes, MapFromRatePremiums(instrumentIds, values))//TODO map into the volsurface. { var assetClass = properties.GetString(CurveProp.AssetClass, true); var type = EnumHelper.Parse <AssetClass>(assetClass); PricingStructureData = new PricingStructureData(CurveType.Parent, type); }
/// <summary> /// Initializes a new instance of the <see cref="RateBasisCurve"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">The client namespace</param> /// <param name="spreadFpmlData">The FPML data.</param> /// <param name="properties">The properties</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="rollCalendar">The rollCalendar.</param> public RateBasisCurve(ILogger logger, ICoreCache cache, string nameSpace, Pair <PricingStructure, PricingStructureValuation> spreadFpmlData, NamedValueSet properties, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar) : base(logger, cache, nameSpace, spreadFpmlData, properties, fixingCalendar, rollCalendar) { PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, properties); var refCurveId = PropertyHelper.ExtractReferenceCurveUniqueId(properties); ReferenceCurveId = refCurveId != null ? new Identifier(refCurveId) : ReferenceCurveId = null; }
/// <summary> /// Initializes a new instance of the <see cref="FxDerivedCurve"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">The client namespace</param> /// <param name="curve1">The currency1 data. This should be against USD. /// This must also be the currency1 curve for the derived fx curve.</param> /// <param name="curve2">The currency2 data. This should be against USD.</param> /// <param name="newFxCurveProperties">The new FxCurve properties .</param> public FxDerivedCurve(ILogger logger, ICoreCache cache, string nameSpace, FxCurve curve1, FxCurve curve2, NamedValueSet newFxCurveProperties) { PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Fx, newFxCurveProperties); FxCurve1 = curve1; FxCurve2 = curve2; Currency1 = curve1.GetQuotedCurrencyPair().currency1.Value != "USD" ? curve1.GetQuotedCurrencyPair().currency1.Value : curve1.GetQuotedCurrencyPair().currency2.Value; Currency2 = curve2.GetQuotedCurrencyPair().currency1.Value != "USD" ? curve2.GetQuotedCurrencyPair().currency1.Value : curve2.GetQuotedCurrencyPair().currency2.Value; SpotDate = GetSpotDate(logger, cache, nameSpace, null, null, FxCurve1.GetBaseDate());//Create the new identifier. PricingStructureIdentifier = new FxCurveIdentifier(newFxCurveProperties); }
/// <summary> /// Initializes a new instance of the <see cref="CommoditySpreadCurve2"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">The client namespace</param> /// <param name="referenceCurveData">The market data. This must contain both the underlying base curve and the spread curve. /// Otherwise the RateBasisInterpolator can not instantiate.</param> /// <param name="spreadCurveData">The spread Curve Data</param> /// <param name="rollCalendar">The rollCalendar.</param> public CommoditySpreadCurve2(ILogger logger, ICoreCache cache, String nameSpace, Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> referenceCurveData, Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> spreadCurveData, IBusinessCalendar rollCalendar) : base(spreadCurveData.Third, GenerateHolder(logger, cache, nameSpace, spreadCurveData.Third)) { PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, spreadCurveData.Third); //Set the identifier. var nvs = spreadCurveData.Third; var pricingStructureId = GetCommodityCurveId(); var refCurveId = PropertyHelper.ExtractReferenceCurveUniqueId(nvs); ReferenceCurveId = refCurveId != null ? new Identifier(refCurveId) : ReferenceCurveId = null; if (pricingStructureId.PricingStructureType != PricingStructureTypeEnum.CommoditySpreadCurve) { return; } //Set the reference curve var baseCurveFpml = new Pair <PricingStructure, PricingStructureValuation>(referenceCurveData.First, referenceCurveData.Second); var baseCurveProps = referenceCurveData.Third; BaseCurve = (ICommodityCurve)PricingStructureFactory.Create(logger, cache, nameSpace, rollCalendar, rollCalendar, baseCurveFpml, baseCurveProps); //Get the spread Data var spreadCurveFpml = new Pair <PricingStructure, PricingStructureValuation>(spreadCurveData.First, spreadCurveData.Second); //Override properties. //var optimize = PropertyHelper.ExtractOptimizeBuildFlag(properties); var bootstrap = PropertyHelper.ExtractBootStrapOverrideFlag(nvs); var tempFpml = (FxCurveValuation)spreadCurveFpml.Second; var spreadAssets = tempFpml.spotRate; //This is to catch it when there are no discount factor points. var discountsAbsent = tempFpml.fxForwardCurve == null || tempFpml.fxForwardCurve.point == null || tempFpml.fxForwardCurve.point.Length == 0; if (bootstrap || discountsAbsent) { //There must be a valid quotedassetset in order to bootstrap. if (!XsdClassesFieldResolver.QuotedAssetSetIsValid(spreadAssets)) { return; } PriceableCommoditySpreadAssets = PriceableAssetFactory.CreatePriceableCommoditySpreadAssets(logger, cache, nameSpace, pricingStructureId.BaseDate, spreadAssets, rollCalendar); Build(logger, cache, nameSpace, rollCalendar, rollCalendar); } else { // the discount curve is already built, so don't rebuild PriceableCommoditySpreadAssets = PriceableAssetFactory.CreatePriceableCommoditySpreadAssets(logger, cache, nameSpace, pricingStructureId.BaseDate, spreadAssets, rollCalendar); //Order the assets. PriceableCommoditySpreadAssets = PriceableCommoditySpreadAssets.OrderBy(a => a.GetRiskMaturityDate()).ToList(); CreatePricingStructure(pricingStructureId, tempFpml.fxForwardCurve, PriceableAssetFactory.Parse(PriceableCommoditySpreadAssets)); //SetInterpolator(BaseCurve, pricingStructureId.PricingStructureType); } }
/// <summary> /// Initializes a new instance of the <see cref="CommodityCurve"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">The nameSpace</param> /// <param name="properties">The properties.</param> /// <param name="assetSet">The assetSet.</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="rollCalendar">The rollCalendar.</param> /// <param name="tolerance">The tolerance for the solver.</param> public CommodityCurve(ILogger logger, ICoreCache cache, string nameSpace, NamedValueSet properties, FxRateSet assetSet, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar, double tolerance) { PricingStructureData = new PricingStructureData(CurveType.Parent, AssetClass.Commodity, properties); var curveId = new CommodityCurveIdentifier(properties); PricingStructureIdentifier = curveId; Holder = new PricingStructureAlgorithmsHolder(logger, cache, nameSpace, curveId.PricingStructureType, curveId.Algorithm); // Get algo name from the properties // Algorithm = properties.GetValue <string>("Algorithm", true); InitialiseInstance(logger, cache, nameSpace, curveId, curveId.BaseDate, assetSet, fixingCalendar, rollCalendar, tolerance); }
/// <summary> /// /// </summary> /// <param name="properties"></param> /// <param name="algorithmHolder"></param> protected void Initialize(NamedValueSet properties, PricingStructureAlgorithmsHolder algorithmHolder) { PricingStructureData = new PricingStructureData(CurveType.Parent, AssetClass.Commodity, properties); if (algorithmHolder != null) { Tolerance = PropertyHelper.ExtractDoubleProperty("Tolerance", properties) ?? GetDefaultTolerance(algorithmHolder); Holder = algorithmHolder; } else { Tolerance = 10 ^ -9; } }
/// <summary> /// Initializes a new instance of the <see cref="RateSpreadCurve"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">The client namespace</param> /// <param name="spreadCurveData">The spread Curve Data</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="rollCalendar">The rollCalendar.</param> public RateSpreadCurve(ILogger logger, ICoreCache cache, String nameSpace, Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> spreadCurveData, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar) : base(spreadCurveData.Third, GenerateHolder(logger, cache, nameSpace, spreadCurveData.Third)) { PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, spreadCurveData.Third); FixingCalendar = fixingCalendar; PaymentCalendar = rollCalendar; //Set the identifier. var nvs = spreadCurveData.Third; var refCurveId = PropertyHelper.ExtractReferenceCurveUniqueId(nvs); ReferenceCurveId = refCurveId != null ? new Identifier(refCurveId) : ReferenceCurveId = null; }
/// <summary> /// Initializes a new instance of the <see cref="CapVolatilityCurve"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">The nameSpace</param> /// <param name="curveIdentifier">The curveIdentifier.</param> protected CapVolatilityCurve(ILogger logger, ICoreCache cache, String nameSpace, PricingStructureIdentifier curveIdentifier) : base(logger, cache, nameSpace, curveIdentifier) { BootstrapperName = "CapFloorBootstrapper"; UnderlyingInterpolatedCurve = "CapVolatilityCurve"; var properties = curveIdentifier.GetProperties(); PricingStructureData = new PricingStructureData(CurveType.Parent, AssetClass.Rates, properties); Tolerance = PropertyHelper.ExtractDoubleProperty("Tolerance", properties) ?? GetDefaultTolerance(Holder); var compoundingFrequency = properties.GetString("CompoundingFrequency", null); CompoundingFrequency = compoundingFrequency != null ? EnumHelper.Parse <CompoundingFrequencyEnum>(compoundingFrequency) : GetDefaultCompounding(Holder); }
/// <summary> /// Initializes a new instance of the <see cref="RateBasisCurve"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">The client namespace</param> /// <param name="referenceCurve">The reference parent curve id.</param> /// <param name="spreadAssets">The spreads by asset.</param> /// <param name="properties">The properties of the new spread curve.</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="rollCalendar">The rollCalendar.</param> public RateBasisCurve(ILogger logger, ICoreCache cache, string nameSpace, IRateCurve referenceCurve, QuotedAssetSet spreadAssets, NamedValueSet properties, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar) : base(logger, cache, nameSpace, ProcessQuotedAssetSet(logger, cache, nameSpace, referenceCurve, spreadAssets, properties, fixingCalendar, rollCalendar), properties, fixingCalendar, rollCalendar) { PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, properties); BaseCurve = referenceCurve; ReferenceCurveId = BaseCurve.GetPricingStructureId(); if (PricingStructureIdentifier.PricingStructureType != PricingStructureTypeEnum.RateBasisCurve) { return; } //Set the spread sets. PriceableRateSpreadAssets = PriceableAssetFactory.CreatePriceableRateSpreadAssets(logger, cache, nameSpace, PricingStructureIdentifier.BaseDate, spreadAssets, fixingCalendar, rollCalendar); Build(logger, cache, nameSpace, fixingCalendar, rollCalendar); }
/// <summary> /// Initializes a new instance of the <see cref="CommodityCurve"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">The client namespace</param> /// <param name="fpmlData">The FPML data.</param> /// <param name="properties">The properties.</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="rollCalendar">The rollCalendar.</param> public CommodityCurve(ILogger logger, ICoreCache cache, string nameSpace, Pair <PricingStructure, PricingStructureValuation> fpmlData, NamedValueSet properties, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar) : base(logger, cache, nameSpace, fpmlData, new CommodityCurveIdentifier(properties)) { PricingStructureData = new PricingStructureData(CurveType.Parent, AssetClass.Commodity, properties); if (fpmlData == null) { return; } FixingCalendar = fixingCalendar; PaymentCalendar = rollCalendar; var tempFpML = (FxCurveValuation)fpmlData.Second; // Use default algorithm name // Algorithm = DefaultAlgorithName; var termCurve = SetConfigurationData(); //SetFpMLData(fpmlData); BootstrapperName = Holder.GetValue("Bootstrapper"); var bootstrap = PropertyHelper.ExtractBootStrapOverrideFlag(properties); // If there's no forward points - do build the curve. // //This is to catch it when there are no discount factor points. var discountsAbsent = tempFpML.fxForwardCurve == null || tempFpML.fxForwardCurve.point == null || tempFpML.fxForwardCurve.point.Length == 0; if (cache == null) { //optimize = true; bootstrap = false; } bool doBuild = (tempFpML.spotRate != null) && discountsAbsent; if (bootstrap || doBuild) { var qas = tempFpML.spotRate; PriceableCommodityAssets = PriceableAssetFactory.CreatePriceableCommodityAssets(logger, cache, nameSpace, tempFpML.baseDate.Value, qas, fixingCalendar, rollCalendar); var point = CommodityBootstrapper.Bootstrap(PriceableCommodityAssets, tempFpML.baseDate.Value, termCurve.extrapolationPermitted, termCurve.interpolationMethod); ((FxCurveValuation)fpmlData.Second).fxForwardCurve.point = point; } SetInterpolator(PricingStructureValuation.baseDate.Value, Holder); }
/// <summary> /// Initializes a new instance of the <see cref="RateBasisCurve"/> class. /// </summary> /// <param name="referenceCurve">The reference curve.</param> /// <param name="spreadAssets">The spreads by asset.</param> /// <param name="properties">The properties of the new spread curve.</param> /// <param name="algorithm">The algorithm holder. </param> public RateBasisCurve(NamedValueSet properties, IRateCurve referenceCurve, List <IPriceableRateSpreadAssetController> spreadAssets, PricingStructureAlgorithmsHolder algorithm) : base(properties, algorithm) { PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, properties); //Set the identifier. var pricingStructureId = GetRateCurveId(); if (pricingStructureId.PricingStructureType != PricingStructureTypeEnum.RateBasisCurve) { return; } //Set the reference curve BaseCurve = referenceCurve; ReferenceCurveId = BaseCurve.GetPricingStructureId(); PriceableRateSpreadAssets = spreadAssets; //Order the assets. PriceableRateSpreadAssets = PriceableRateSpreadAssets.OrderBy(a => a.GetRiskMaturityDate()).ToList(); var termCurve = SetConfigurationData(); //Get the reference interpolated curve. termCurve.point = RateSpreadBootstrapper.Bootstrap(PriceableRateSpreadAssets, BaseCurve, pricingStructureId.BaseDate, termCurve.extrapolationPermitted, Tolerance); CreatePricingStructure(pricingStructureId, termCurve, PriceableAssetFactory.Parse(PriceableRateSpreadAssets)); SetInterpolator(BaseCurve, pricingStructureId.PricingStructureType); // Set the Zero curve, just for reference YieldCurveValuation yieldCurveValuation = GetYieldCurveValuation(); if (yieldCurveValuation.zeroCurve?.rateCurve == null) { //var curveId = (RateCurveIdentifier)PricingStructureIdentifier; //var psType = PricingStructureIdentifier.PricingStructureType; TermCurve curve = YieldCurveAnalytics.ToZeroCurve(termCurve, GetBaseDate(), CompoundingFrequency, DayCounter); curve.interpolationMethod = InterpolationMethodHelper.Parse(Holder.GetValue("CurveInterpolation")); var zeroCurve = new ZeroRateCurve { rateCurve = curve, compoundingFrequency = FpML.V5r3.Reporting.CompoundingFrequency.Create(CompoundingFrequency) }; yieldCurveValuation.zeroCurve = zeroCurve; } }
/// <summary> /// Construct a VolatilityCube from points /// </summary> /// <param name="properties"></param> /// <param name="points"></param> public VolatilityCube(NamedValueSet properties, PricingStructurePoint[] points) { properties.Set(EnvironmentProp.Function, FunctionProp.Market.ToString()); PricingStructureIdentifier = new VolatilitySurfaceIdentifier(properties); var surfaceId = (VolatilitySurfaceIdentifier)PricingStructureIdentifier; PricingStructureData = new PricingStructureData(CurveType.Parent, Constants.AssetClass.Rates);//TODO Need to set for the different underlyers. SetInterpolator(); foreach (PricingStructurePoint point in points) { point.underlyingAssetReference = surfaceId.UnderlyingAssetReference; point.quoteUnits = surfaceId.StrikeQuoteUnits; } PricingStructure = new VolatilityRepresentation { name = surfaceId.Name, id = surfaceId.Id, currency = surfaceId.Currency, asset = new AnyAssetReference { href = surfaceId.Instrument }, }; var datapoints = new MultiDimensionalPricingData { point = points }; PricingStructureValuation = new VolatilityMatrix { dataPoints = datapoints, objectReference = new AnyAssetReference { href = surfaceId.Instrument }, baseDate = new IdentifiedDate { Value = surfaceId.BaseDate }, buildDateTime = DateTime.Now, buildDateTimeSpecified = true }; _matrixIndexHelper = new SortedList <ExpiryTenorStrikeKey, int>(new ExpiryTenorStrikeKey()); ProcessVolatilityRepresentation(); }
/// <summary> /// Initializes a new instance of the <see cref="FxCurve"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">THe client namespace</param> /// <param name="fpmlData">The FPML data.</param> /// <param name="properties">The properties.</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="rollCalendar">The rollCalendar.</param> public EquityCurve(ILogger logger, ICoreCache cache, string nameSpace, Pair <PricingStructure, PricingStructureValuation> fpmlData, NamedValueSet properties, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar) : base(logger, cache, nameSpace, fpmlData, new EquityCurveIdentifier(properties)) { PricingStructureData = new PricingStructureData(CurveType.Parent, AssetClass.Equity, properties); if (properties == null) { properties = PricingStructurePropertyHelper.FxCurve(fpmlData);//TODO } //Set the spot date; SettlementDate = GetSettlementDate(logger, cache, nameSpace, GetEquityCurveId(), fixingCalendar, rollCalendar, PricingStructureValuation.baseDate.Value); var fxCurveValuation = (FxCurveValuation)fpmlData.Second; // hack - set the base date - todo - is this the right place alex? PricingStructureValuation.baseDate = new IdentifiedDate { Value = PricingStructureIdentifier.BaseDate }; SetFpmlData(fpmlData); TermCurve termCurve = SetConfigurationData(); var bootstrap = PropertyHelper.ExtractBootStrapOverrideFlag(properties); var buildFlag = (fxCurveValuation.spotRate != null) && (fxCurveValuation.fxForwardCurve == null || fxCurveValuation.fxForwardCurve.point == null); // If there's no forward points - do build the curve. // - TODO what happened the central bank dates if ((bootstrap || buildFlag) && cache != null) { // if (BootstrapperName == "FastBootstrapper") //TODO PriceableEquityAssets = PriceableAssetFactory.CreatePriceableEquityAssets(logger, cache, nameSpace, fxCurveValuation.baseDate.Value, fxCurveValuation.spotRate, fixingCalendar, rollCalendar); fxCurveValuation.fxForwardCurve = termCurve; fxCurveValuation.fxForwardCurve.point = EquityBootstrapper.Bootstrap( PriceableEquityAssets, fxCurveValuation.baseDate.Value, fxCurveValuation.fxForwardCurve.extrapolationPermitted, fxCurveValuation.fxForwardCurve.interpolationMethod); } ((FxCurveValuation)PricingStructureValuation).fxForwardCurve = fxCurveValuation.fxForwardCurve; SetInterpolator(PricingStructureValuation.baseDate.Value); }
private void InitialiseInstance(ILogger logger, ICoreCache cache, string nameSpace, NamedValueSet properties, FxRateSet assetSet, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar) { PricingStructureData = new PricingStructureData(CurveType.Parent, AssetClass.Equity, properties); var curveId = new EquityCurveIdentifier(properties); PricingStructureIdentifier = curveId; Holder = new PricingStructureAlgorithmsHolder(logger, cache, nameSpace, curveId.PricingStructureType, curveId.Algorithm); DateTime baseDate = PricingStructureIdentifier.BaseDate; //Set the spot date; SettlementDate = GetSettlementDate(logger, cache, nameSpace, GetEquityCurveId(), fixingCalendar, rollCalendar, baseDate); //TODO //FixingCalendar = null; //RollCalendar = null; // The bootstrapper to use BootstrapperName = Holder.GetValue("Bootstrapper"); Tolerance = double.Parse(Holder.GetValue("Tolerance")); bool extrapolationPermitted = bool.Parse(Holder.GetValue("ExtrapolationPermitted")); InterpolationMethod interpolationMethod = InterpolationMethodHelper.Parse(Holder.GetValue("BootstrapperInterpolation")); var termCurve = new TermCurve { extrapolationPermitted = extrapolationPermitted, extrapolationPermittedSpecified = true, interpolationMethod = interpolationMethod }; PriceableEquityAssets = PriceableAssetFactory.CreatePriceableEquityAssets(logger, cache, nameSpace, baseDate, assetSet, fixingCalendar, rollCalendar); termCurve.point = EquityBootstrapper.Bootstrap(PriceableEquityAssets, baseDate, termCurve.extrapolationPermitted, termCurve.interpolationMethod, Tolerance); // Pull out the fx curve and fx curve valuation Pair <PricingStructure, PricingStructureValuation> fpmlData = CreateFpmlPair(logger, cache, nameSpace, baseDate, (EquityCurveIdentifier)PricingStructureIdentifier, assetSet, termCurve, fixingCalendar, rollCalendar); SetFpmlData(fpmlData); // Interpolate the DiscountFactor curve based on the respective curve interpolation SetInterpolator(baseDate); }
/// <summary> /// Initializes a new instance of the <see cref="GenericVolatilityCurve"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="cache">The cache.</param> /// <param name="nameSpace">The nameSpace</param> /// <param name="fpmlData">The FPML data.</param> /// <param name="properties">The properties for the pricing structure.</param> /// <param name="fixingCalendar">The fixingCalendar. If the curve is already bootstrapped, then this can be null.</param> /// <param name="rollCalendar">The rollCalendar. If the curve is already bootstrapped, then this can be null.</param> public GenericVolatilityCurve(ILogger logger, ICoreCache cache, String nameSpace, Pair <PricingStructure, PricingStructureValuation> fpmlData, NamedValueSet properties, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar) : base(logger, cache, nameSpace, fpmlData, properties, fixingCalendar, rollCalendar) { PricingStructureData = new PricingStructureData(CurveType.Parent, AssetClass.Rates, properties); var curveId = GetCurveId(); Initialize(properties, Holder); //Set the underlying asset information. if (properties != null) { var instrument = properties.GetString("Instrument", false); Asset = new AnyAssetReference { href = instrument }; } if (fpmlData == null) { return; } FixingCalendar = fixingCalendar; PaymentCalendar = rollCalendar; if (DayCounter == null) { DayCounter = DayCounterHelper.Parse("ACT/365.FIXED"); if (Holder != null) { string dayCountBasis = Holder.GetValue("DayCounter"); DayCounter = DayCounterHelper.Parse(dayCountBasis); } } // the curve is already built, so don't rebuild //Process the matrix SetInterpolator(((VolatilityMatrix)PricingStructureValuation).dataPoints, curveId.Algorithm, curveId.PricingStructureType); SetFpMLData(fpmlData, false); }