///// <summary> ///// Builds the market. ///// </summary> ///// <param name="market">The market.</param> ///// <param name="pricingStructureTerms">The pricing structure terms.</param> ///// <param name="resultsContainer">The results container.</param> ///// <returns></returns> //public static IMarketEnvironment BuildMarket(string market, IDictionary<string, IDictionary<string, object>> pricingStructureTerms, NamedValueSet resultsContainer) //{ // const string cLowerRateCurve = "ratecurve"; // const string cLowerFXCurve = "fxcurve"; // const string cLowerVolSurface = "ratevolatilitymatrix"; // const string cLowerVolCube = "ratevolatilitycube"; // const string cPricingStructureTypeKey = CurveProp.PricingStructureType; // IDictionary<string, List<string>> curveTOLegRefMap = new Dictionary<string, List<string>>(); // IDictionary<string, IRateCurveTerms> rateCurveTOCurveTermsMap = new Dictionary<string, IRateCurveTerms>(); // IDictionary<string, IFXCurveTerms> fxCurveTOCurveTermsMap = new Dictionary<string, IFXCurveTerms>(); // IDictionary<string, IVolatilitySurfaceTerms> volSurfaceTOSurfaceTermsMap = new Dictionary<string, IVolatilitySurfaceTerms>(); // IDictionary<string, IVolatilitySurfaceTerms> volCubeTOCubeTermsMap = new Dictionary<string, IVolatilitySurfaceTerms>(); // foreach (string pricingStructureTermsRef in pricingStructureTerms.Keys) // { // IDictionary<string, object> termProps = pricingStructureTerms[pricingStructureTermsRef]; // if (termProps == null) continue; // var propKeys = new List<string>(termProps.Keys); // string psTypeKey = propKeys.Find(item => string.Compare(item, cPricingStructureTypeKey, true) == 0); // if (string.IsNullOrEmpty(psTypeKey)) // { // continue; // } // IPricingStructureTerms curveTerms; // switch (termProps[psTypeKey].ToString().ToLowerInvariant()) // { // case cLowerRateCurve: // curveTerms = new RateCurveTerms(termProps); // UpdateMap(pricingStructureTermsRef, (IRateCurveTerms)curveTerms, rateCurveTOCurveTermsMap, curveTOLegRefMap, curveTerms.ReferenceKey); // break; // case cLowerFXCurve: // curveTerms = new FXCurveTerms(termProps); // UpdateMap(pricingStructureTermsRef, (IFXCurveTerms)curveTerms, fxCurveTOCurveTermsMap, curveTOLegRefMap, curveTerms.ReferenceKey); // break; // case cLowerVolSurface: // curveTerms = new VolatilitySurfaceTerms(termProps); // UpdateMap(pricingStructureTermsRef, (VolatilitySurfaceTerms)curveTerms, volSurfaceTOSurfaceTermsMap, curveTOLegRefMap, curveTerms.ReferenceKey); // break; // case cLowerVolCube: // curveTerms = new VolatilitySurfaceTerms(termProps); // UpdateMap(pricingStructureTermsRef, (VolatilitySurfaceTerms)curveTerms, volCubeTOCubeTermsMap, curveTOLegRefMap, curveTerms.ReferenceKey); // break; // } // } // IMarketEnvironment marketEnvironment = Create(market, rateCurveTOCurveTermsMap, fxCurveTOCurveTermsMap, volSurfaceTOSurfaceTermsMap, volCubeTOCubeTermsMap, curveTOLegRefMap); // if (marketEnvironment != null) // { // IDictionary<string, IPricingStructure> structures = marketEnvironment.GetPricingStructures(); // resultsContainer.Add(ParsePricingStructures(structures)); // } // return marketEnvironment; //} /// <summary> /// Validates the market. /// </summary> /// <param name="pricingStructures"></param> /// <param name="market"></param> public static void ValidateMarket(string[] pricingStructures, IMarketEnvironment market) { var missingStructures = new List <string>(); if (market == null) { throw new ArgumentNullException(nameof(market), "A valid market has not been supplied"); } IDictionary <string, IPricingStructure> ps = market.GetPricingStructures(); if (market != null && ps.Count == 0) { throw new ApplicationException($"{market.Id} market does not contain any curves"); } if (ps.Count <= 0) { } else { missingStructures.AddRange(pricingStructures.Where(structure => !StructureExists(ps, structure))); if (missingStructures.Count > 0) { throw new ApplicationException( $"{string.Join(", ", missingStructures.ToArray())} curves not found in {market.Id} market"); } } }
/// <summary> /// Initializes a new instance of the <see cref="InstrumentControllerData"/> class. /// </summary> /// <param name="assetValuation">The asset valuation.</param> /// <param name="market">The market.</param> /// <param name="valuationDate">The valuation date.</param> /// <param name="reportingCurrency">The reporting currency.</param> public InstrumentControllerData(AssetValuation assetValuation, IMarketEnvironment market, DateTime valuationDate, Currency reportingCurrency) { AssetValuation = assetValuation; MarketEnvironment = market; ValuationDate = valuationDate; ReportingCurrency = reportingCurrency; }
/// <summary> /// Prices the product. /// </summary> /// <param name="reportingParty"></param> /// <param name="valuationDate"></param> /// <param name="market"></param> /// <returns></returns> public double GetParRate(string reportingParty, DateTime valuationDate, IMarketEnvironment market) { var modelData = CreateInstrumentModelData(new List <string> { InstrumentMetrics.ImpliedQuote.ToString() }, valuationDate, market, PriceableProduct.PaymentCurrencies[0], reportingParty); var av = PriceableProduct.Calculate(modelData); return((double)av.quote[0].value); }
/// <summary> /// Stores the structure. /// </summary> /// <param name="marketEnvironment">The market environment.</param> /// <param name="name">The name.</param> /// <param name="pricingStructure">The pricing structure.</param> /// <returns></returns> public static IMarketEnvironment StoreStructure(IMarketEnvironment marketEnvironment, string name, IPricingStructure pricingStructure) { var market = (MarketEnvironment)marketEnvironment; if (!StructureExists(marketEnvironment, name)) { market.AddPricingStructure(name, pricingStructure); } return(market); }
/// <summary> /// Initializes a new instance of the <see cref="InstrumentControllerData"/> class. /// </summary> /// <param name="assetValuation">The asset valuation.</param> /// <param name="market">The market.</param> /// <param name="valuationDate">The valuation date.</param> /// <param name="reportingCurrency">The reporting currency.</param> /// <param name="baseCalculationParty">The base party.</param> /// <param name="isReportingCounterpartyRequired">Is the reporting party required to be one of the trade parties. The default is [false]. </param> public InstrumentControllerData(AssetValuation assetValuation, IMarketEnvironment market, DateTime valuationDate, Currency reportingCurrency, IIdentifier baseCalculationParty, Boolean isReportingCounterpartyRequired) { AssetValuation = assetValuation; MarketEnvironment = market; ValuationDate = valuationDate; ReportingCurrency = reportingCurrency; BaseCalculationParty = baseCalculationParty; IsReportingCounterpartyRequired = isReportingCounterpartyRequired; }
/// <summary> /// Prices the product. /// </summary> /// <param name="logger"></param> /// <param name="cache"></param> /// <param name="reportingParty"></param> /// <param name="deposit"></param> /// <param name="valuationDate"></param> /// <param name="market"></param> /// <returns></returns> public static double GetParRate(ILogger logger, ICoreCache cache, string reportingParty, TermDeposit deposit, DateTime valuationDate, IMarketEnvironment market) { var agreement = new TermDepositPricer(logger, cache, deposit, reportingParty); var modelData = CreateInstrumentModelData(new[] { "ImpliedQuote" }, valuationDate, market, agreement.Currency.Value); var av = agreement.Calculate(modelData); return((double)av.quote[0].value); }
/// <summary> /// Adds the specified market environment. /// </summary> /// <param name="marketEnvironment">The market environment.</param> public static void Add(IMarketEnvironment marketEnvironment) { lock (_marketEnvironments) { if (_marketEnvironments.ContainsKey(marketEnvironment.Id)) { _marketEnvironments.Remove(marketEnvironment.Id); } _marketEnvironments.Add(marketEnvironment.Id, marketEnvironment); } }
/// <summary> /// Prices the product. /// </summary> /// <param name="logger"></param> /// <param name="cache"></param> /// <param name="fixingCalendar"></param> /// <param name="paymentCalendar"></param> /// <param name="fra"></param> /// <param name="valuationDate"></param> /// <param name="market"></param> /// <param name="nameSpace"></param> /// <returns></returns> public static double GetParRate(ILogger logger, ICoreCache cache, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, Fra fra, DateTime valuationDate, IMarketEnvironment market, String nameSpace) { var agreement = new FraPricer(logger, cache, fixingCalendar, paymentCalendar, fra, nameSpace); var modelData = CreateInstrumentModelData(new[] { "ImpliedQuote" }, valuationDate, market, "AUD"); var av = agreement.Calculate(modelData); return((double)av.quote[0].value); }
static public void ProcessFxLegResultsWithCurrency(InstrumentControllerBase instrumentController, string[] metrics, DateTime baseDate, string currency) { Assert.IsNotNull(instrumentController); //Double[] times = { 0, 1, 2, 3, 4, 5 }; //Double[] dfs = { 1, 0.98, 0.96, 0.91, 0.88, 0.85}; IMarketEnvironment market = CreateFxLegTestEnvironment(baseDate); IInstrumentControllerData controllerData = CreateInstrumentModelData(metrics, baseDate, market, currency); Assert.IsNotNull(controllerData); var results = instrumentController.Calculate(controllerData); Debug.Print("Id : {0}", instrumentController.Id); foreach (var metric in results.quote) { Debug.Print("Id : {0} Metric Name : {1} Metric Value : {2}", instrumentController.Id, metric.measureType.Value, metric.value); } }
public void CreateStructuredFloorTest() { #region Initialise QRLib.PricingStructures.ClearCache(); string rateCurveId = BuildMarket(_baseDate); IMarketEnvironment marketEnvironment = ObjectCacheHelper.GetMarket(_marketEnvironmentId); #endregion #region Define the Swap const string id = "TestStructuredFloor"; object[,] capFloorTerms = { { "DealReferenceIdentifier", id }, { "BasePartyBuySellsInd", "Sells" }, { "CounterpartyName", "ANZ" }, { "DealType", "Floor" }, }; object[,] streamTerms = { { "NotionalAmount", "1000000" }, { "Currency", "AUD" }, { "DayCountConvention", "ACT/365.FIXED" }, { "DiscountingType", "Standard" }, { "DiscountCurveReference", rateCurveId }, { "ForwardCurveReference", rateCurveId }, { "VolatilityCurveReference", _volatilityStructureId }, { "RateIndexName", "AUD-LIBOR-BBA" }, { "RateIndexTenor", "6m" }, { "StrikePrice", "0.07" }, }; const double notionalAmount = -1000000; object[,] couponMatrix = { { "StartDate", "EndDate", "NotionalAmount", "StrikePrice" }, { new DateTime(2009, 09, 04), new DateTime(2010, 03, 01), notionalAmount, "0.07"}, { new DateTime(2010, 03, 01), new DateTime(2010, 09, 01), notionalAmount, "0.07"}, { new DateTime(2010, 09, 01), new DateTime(2011, 03, 01), notionalAmount, "0.07"}, { new DateTime(2011, 03, 01), new DateTime(2011, 09, 05), notionalAmount, "0.07"}, }; #endregion #region Define the Valuation Criteria string[] requiredMetrics = { "NPV", "BreakEvenRate" }; #endregion #region Create & Value the Swap string returnedId = QRLib.Rates.InterestRateCapFloor.CreateStructured(capFloorTerms, streamTerms, couponMatrix); Assert.AreEqual(id, returnedId); InterestRateCapFloor capFloor = ProductHelper.Get <InterestRateCapFloor>(id); Assert.IsNotNull(capFloor); CreditSettings creditSettings = new CreditSettings(ServerStore.Client); IDictionary <string, object> valuation = capFloor.BasicValuation(_baseDate, marketEnvironment, requiredMetrics, creditSettings); #endregion #region Validate the Results Assert.AreEqual(CapBreakEvenRate, Convert.ToDouble(valuation["BreakEvenRate"]), 0.0000001); Assert.AreEqual(_pv, Convert.ToDouble(valuation["NPV"]), 3); #endregion #region Reset QRLib.PricingStructures.ClearCache(); #endregion }
public void CreateAmortisedFloorTest() { #region Initialise QRLib.PricingStructures.ClearCache(); string rateCurveId = BuildMarket(_baseDate); IMarketEnvironment marketEnvironment = ObjectCacheHelper.GetMarket(_marketEnvironmentId); #endregion #region Define the Swap const string id = "TestAmortisedFloor"; object[,] capFloorTerms = { { "DealReferenceIdentifier", id }, { "BasePartyBuySellsInd", "Sells" }, { "CounterpartyName", "ANZ" }, { "DealType", "Floor" }, { "EffectiveDate", _baseDate }, { "TerminationDate", _baseDate.AddYears(2) }, { "AdjustCalculationDates", true }, }; object[,] streamTerms = { { "NotionalAmount", "1000000" }, { "Currency", "AUD" }, { "ScheduleGeneration", "Forward" }, { "BusinessCenters", "Sydney" }, { "CouponPeriod", "6m" }, { "RollDay", "1" }, { "CouponDateAdjustment", "FOLLOWING" }, { "DayCountConvention", "ACT/365.FIXED" }, { "DiscountingType", "Standard" }, { "DiscountCurveReference", rateCurveId }, { "FixedOrObservedRate", "0.07" }, { "ObservedRateSpecified", "FALSE" }, { "ForwardCurveReference", rateCurveId }, { "FixingDateBusinessCenters", "Sydney" }, { "FixingDateResetInterval", "0D" }, { "FixingDateAdjustmentConvention", "NONE" }, { "RateIndexName", "AUD-LIBOR-BBA" }, { "RateIndexTenor", "6m" }, { "Spread", "0" }, { "VolatilityCurveReference", _volatilityStructureId }, { "StrikePrice", "0.07" }, }; #endregion #region Define the Valuation Criteria string[] requiredMetrics = { "NPV", "BreakEvenRate" }; #endregion #region Create & Value the Swap string returnedId = QRLib.Rates.InterestRateCapFloor.CreateAmortised(capFloorTerms, streamTerms, null); Assert.AreEqual(id, returnedId); InterestRateCapFloor capFloor = ProductHelper.Get <InterestRateCapFloor>(id); Assert.IsNotNull(capFloor); CreditSettings creditSettings = new CreditSettings(ServerStore.Client); IDictionary <string, object> valuation = capFloor.BasicValuation(_baseDate, marketEnvironment, requiredMetrics, creditSettings); #endregion #region Validate the Results Assert.AreEqual(CapBreakEvenRate, Convert.ToDouble(valuation["BreakEvenRate"]), 0.0000001); Assert.AreEqual(_pv, Convert.ToDouble(valuation["NPV"]), 3); #endregion #region Reset QRLib.PricingStructures.ClearCache(); #endregion }
/// <summary> /// Creates the asset controller data. /// </summary> /// <param name="metrics">The metrics.</param> /// <param name="baseDate">The base date.</param> /// <param name="market">The market.</param> /// <returns></returns> public IAssetControllerData CreateAssetControllerData(string[] metrics, DateTime baseDate, IMarketEnvironment market) { var bav = new BasicAssetValuation(); var quotes = new BasicQuotation[metrics.Length]; var index = 0; foreach (var metric in metrics) { var quotation = new BasicQuotation { valueSpecified = true, value = 0.0m, measureType = new AssetMeasureType { Value = metric } }; quotes[index] = quotation; index++; } bav.quote = quotes; return(new AssetControllerData(bav, baseDate, market)); }
/// <summary> /// Initializes a new instance of the <see cref="AssetControllerData"/> class. /// </summary> /// <param name="basicAssetValuation">The basic asset valuation.</param> /// <param name="valuationDate">The valuation date.</param> /// <param name="market">The market.</param> public AssetControllerData(BasicAssetValuation basicAssetValuation, DateTime valuationDate, IMarketEnvironment market) { BasicAssetValuation = basicAssetValuation; ValuationDate = valuationDate; MarketEnvironment = market; }
/// <summary> /// Initializes a new instance of the <see cref="InstrumentControllerData"/> class. /// </summary> /// <param name="assetValuation">The asset valuation.</param> /// <param name="market">The market.</param> /// <param name="valuationDate">The valuation date.</param> public InstrumentControllerData(AssetValuation assetValuation, IMarketEnvironment market, DateTime valuationDate) { AssetValuation = assetValuation; MarketEnvironment = market; ValuationDate = valuationDate; }
/// <summary> /// Initializes a new instance of the <see cref="InstrumentControllerData"/> class. /// </summary> /// <param name="assetValuation">The valuation set.</param> /// <param name="market">The market.</param> public InstrumentControllerData(AssetValuation assetValuation, IMarketEnvironment market) { AssetValuation = assetValuation; MarketEnvironment = market; }
static internal IInstrumentControllerData CreateInstrumentModelData(string[] metrics, DateTime baseDate, IMarketEnvironment market) { var bav = new AssetValuation(); var quotes = new Quotation[metrics.Length]; var index = 0; foreach (var metric in metrics) { quotes[index] = QuotationHelper.Create(0.0m, metric); index++; } bav.quote = quotes; return(new InstrumentControllerData(bav, market, baseDate)); }
static internal IInstrumentControllerData CreateInstrumentModelData(string[] metrics, DateTime baseDate, IMarketEnvironment market, string reportingCurrency) { var bav = new AssetValuation(); var curreny = Currency.Parse(reportingCurrency); var quotes = new Quotation[metrics.Length]; var index = 0; foreach (var metric in metrics) { quotes[index] = QuotationHelper.Create(0.0m, metric, "DecimalValue"); index++; } bav.quote = quotes; return(new InstrumentControllerData(bav, market, baseDate, curreny)); }
public static IInstrumentControllerData CreateInstrumentModelData(List <string> metrics, DateTime baseDate, IMarketEnvironment market, string reportingCurrency, string baseParty) { var bav = new AssetValuation(); var currency = CurrencyHelper.Parse(reportingCurrency); var quotes = new Quotation[metrics.Count]; var index = 0; foreach (var metric in metrics) { quotes[index] = QuotationHelper.Create(0.0m, metric, "DecimalValue", baseDate); index++; } bav.quote = quotes; return(new InstrumentControllerData(bav, market, baseDate, currency, new PartyIdentifier(baseParty))); }
/// <summary> /// Structures the exists. /// </summary> /// <param name="marketEnvironment">The market environment.</param> /// <param name="name">The name.</param> /// <returns></returns> internal static Boolean StructureExists(IMarketEnvironment marketEnvironment, string name) { return(StructureExists(marketEnvironment.GetPricingStructures(), name)); }
/// <summary> /// Returns the npv. /// </summary> /// <param name="reportingParty"></param> /// <param name="baseCurrency"></param> /// <param name="valuationDate"></param> /// <param name="market"></param> /// <returns></returns> public double GetNPV(string reportingParty, string baseCurrency, DateTime valuationDate, IMarketEnvironment market) { var modelData = CreateInstrumentModelData(new List <string> { InstrumentMetrics.NPV.ToString() }, valuationDate, market, baseCurrency, reportingParty); var av = PriceableProduct.Calculate(modelData); return((double)av.quote[0].value); }
/// <summary> /// Initializes a new instance of the <see cref="InstrumentControllerData"/> class. /// </summary> /// <param name="assetValuation">The asset valuation.</param> /// <param name="market">The market.</param> /// <param name="valuationDate">The valuation date.</param> /// <param name="reportingCurrency">The reporting currency.</param> /// <param name="baseCalculationParty">The base party.</param> public InstrumentControllerData(AssetValuation assetValuation, IMarketEnvironment market, DateTime valuationDate, Currency reportingCurrency, IIdentifier baseCalculationParty) : this(assetValuation, market, valuationDate, reportingCurrency, baseCalculationParty, false) { }
protected static IInstrumentControllerData CreateInstrumentModelData(string[] metrics, DateTime valuationDate, IMarketEnvironment market, string reportingCurrency, IIdentifier baseCounterParty) { var bav = new AssetValuation(); var currency = CurrencyHelper.Parse(reportingCurrency); var quotes = new Quotation[metrics.Length]; var index = 0; foreach (var metric in metrics) { quotes[index] = QuotationHelper.Create(0.0m, metric); index++; } bav.quote = quotes; return(new InstrumentControllerData(bav, market, valuationDate, currency, baseCounterParty)); }
static public IAssetControllerData CreateModelData(string[] metrics, DateTime baseDate, IMarketEnvironment market) { var bav = new BasicAssetValuation(); var quotes = new BasicQuotation[metrics.Length]; var index = 0; foreach (var metric in metrics) { quotes[index] = BasicQuotationHelper.Create(0.0m, metric); index++; } bav.quote = quotes; return(new AssetControllerData(bav, baseDate, market)); }