public virtual void test_createTrade_withFee() { TenorCdsTemplate base1 = TenorCdsTemplate.of(TENOR_10Y, CONV1); TenorCdsTemplate base2 = TenorCdsTemplate.of(AccrualStart.NEXT_DAY, TENOR_2Y, CONV2); LocalDate tradeDate = LocalDate.of(2015, 5, 5); AdjustablePayment payment1 = AdjustablePayment.of(EUR, NOTIONAL_2M, CONV1.SettlementDateOffset.adjust(tradeDate, REF_DATA)); AdjustablePayment payment2 = AdjustablePayment.of(USD, NOTIONAL_2M, CONV2.SettlementDateOffset.adjust(tradeDate, REF_DATA)); LocalDate startDate1 = date(2015, 3, 20); LocalDate endDate1 = date(2025, 6, 20); LocalDate startDate2 = date(2015, 5, 6); LocalDate endDate2 = date(2017, 6, 20); CdsTrade test1 = base1.createTrade(LEGAL_ENTITY, tradeDate, BUY, NOTIONAL_2M, 0.05d, payment1, REF_DATA); CdsTrade test2 = base2.createTrade(LEGAL_ENTITY, tradeDate, BUY, NOTIONAL_2M, 0.05d, payment2, REF_DATA); Cds expected1 = Cds.of(BUY, LEGAL_ENTITY, CONV1.Currency, NOTIONAL_2M, startDate1, endDate1, Frequency.P3M, CONV1.SettlementDateOffset.Calendar, 0.05d); PeriodicSchedule sch1 = expected1.PaymentSchedule; expected1 = expected1.toBuilder().paymentSchedule(sch1.toBuilder().startDateBusinessDayAdjustment(sch1.BusinessDayAdjustment).rollConvention(RollConventions.DAY_20).build()).build(); Cds expected2 = Cds.of(BUY, LEGAL_ENTITY, CONV2.Currency, NOTIONAL_2M, startDate2, endDate2, Frequency.P3M, CONV2.SettlementDateOffset.Calendar, 0.05d); PeriodicSchedule sch2 = expected2.PaymentSchedule; expected2 = expected2.toBuilder().paymentSchedule(sch2.toBuilder().startDateBusinessDayAdjustment(sch2.BusinessDayAdjustment).rollConvention(RollConventions.DAY_20).build()).build(); assertEquals(test1.Info.TradeDate, tradeDate); assertEquals(test1.UpfrontFee, payment1); assertEquals(test1.Product, expected1); assertEquals(test2.Info.TradeDate, tradeDate); assertEquals(test2.UpfrontFee, payment2); assertEquals(test2.Product, expected2); }
//------------------------------------------------------------------------- public virtual void coverage() { coverImmutableBean(PRODUCT_STD); Cds other = Cds.builder().buySell(SELL).legalEntityId(StandardId.of("OG", "EFG")).currency(JPY).notional(1d).fixedRate(0.01).dayCount(ACT_365F).paymentSchedule(PeriodicSchedule.builder().businessDayAdjustment(BusinessDayAdjustment.of(BusinessDayConventions.FOLLOWING, JPTO)).startDate(LocalDate.of(2014, 1, 4)).endDate(LocalDate.of(2020, 11, 20)).startDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).endDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).frequency(P6M).rollConvention(RollConventions.NONE).stubConvention(StubConvention.SHORT_FINAL).build()).paymentOnDefault(PaymentOnDefault.NONE).protectionStart(ProtectionStartOfDay.NONE).stepinDateOffset(DaysAdjustment.NONE).settlementDateOffset(DaysAdjustment.NONE).build(); coverBeanEquals(PRODUCT_STD, other); }
public virtual void parSpreadQuoteTest() { int nPillars = MATURITIES.Length; IList <Cds> products = new List <Cds>(nPillars); IList <CdsQuote> quotes = new List <CdsQuote>(nPillars); double[] parSpreads = new double[] { 0.00769041167742121, 0.010780108645654813, 0.014587245777777417, 0.017417253343028126, 0.01933997409465104, 0.022289540511698912, 0.025190509434219924 }; for (int i = 0; i < nPillars; ++i) { products.Add(Cds.of(BUY, LEGAL_ENTITY, GBP, 1.0e6, START_DATE, MATURITIES[i], Frequency.P3M, DEFAULT_CALENDAR, parSpreads[i])); quotes.Add(CdsQuote.of(CdsQuoteConvention.PAR_SPREAD, parSpreads[i])); } TradeInfo info = TradeInfo.builder().tradeDate(TODAY).settlementDate(products[0].SettlementDateOffset.adjust(TODAY, REF_DATA)).build(); IList <ResolvedCdsTrade> trades = products.Select(p => CdsTrade.builder().product(p).info(info).build().resolve(REF_DATA)).ToList(); IList <CdsQuote> pufsComp = CONV.quotesFromParSpread(trades, quotes, RATES_PROVIDER, CdsQuoteConvention.POINTS_UPFRONT, REF_DATA); IList <CdsQuote> pufsMfComp = CONV_MARKIT_FIX.quotesFromParSpread(trades, quotes, RATES_PROVIDER, CdsQuoteConvention.POINTS_UPFRONT, REF_DATA); IList <CdsQuote> qssComp = CONV.quotesFromParSpread(trades, quotes, RATES_PROVIDER, CdsQuoteConvention.QUOTED_SPREAD, REF_DATA); IList <CdsQuote> qssMfComp = CONV_MARKIT_FIX.quotesFromParSpread(trades, quotes, RATES_PROVIDER, CdsQuoteConvention.QUOTED_SPREAD, REF_DATA); for (int i = 0; i < nPillars; ++i) { assertEquals(pufsComp[i].QuotedValue, 0d, TOL); assertTrue(pufsComp[i].QuoteConvention.Equals(CdsQuoteConvention.POINTS_UPFRONT)); assertEquals(pufsMfComp[i].QuotedValue, 0d, TOL); assertTrue(pufsMfComp[i].QuoteConvention.Equals(CdsQuoteConvention.POINTS_UPFRONT)); } for (int i = 0; i < nPillars; ++i) { CdsQuote qsRe = CONV.quotedSpreadFromPointsUpfront(trades[i], pufsComp[i], RATES_PROVIDER, REF_DATA); CdsQuote qsMfRe = CONV_MARKIT_FIX.quotedSpreadFromPointsUpfront(trades[i], pufsMfComp[i], RATES_PROVIDER, REF_DATA); assertEquals(qsRe.QuotedValue, qssComp[i].QuotedValue, TOL); assertEquals(qsMfRe.QuotedValue, qssMfComp[i].QuotedValue, TOL); } }
private CdsTrade(TradeInfo info, Cds product, AdjustablePayment upfrontFee) { JodaBeanUtils.notNull(info, "info"); JodaBeanUtils.notNull(product, "product"); this.info = info; this.product = product; this.upfrontFee = upfrontFee; }
// // GET: /Movies/random public ActionResult Random() { var cds = new Cds() { nome = "Black Album", estilo = " Metal" }; return(View(cds)); }
//------------------------------------------------------------------------- public virtual void coverage() { CdsTrade test1 = sut(); coverImmutableBean(test1); Cds product = Cds.of(BUY, LEGAL_ENTITY, USD, 1.e9, START_DATE, END_DATE, P3M, SAT_SUN, 0.067); CdsTrade test2 = CdsTrade.builder().product(product).info(TradeInfo.empty()).build(); coverBeanEquals(test1, test2); }
//------------------------------------------------------------------------- public virtual void coverage() { ResolvedCdsTrade test1 = ResolvedCdsTrade.builder().product(PRODUCT).upfrontFee(UPFRONT).info(TRADE_INFO).build(); coverImmutableBean(test1); ResolvedCds product = Cds.of(BUY, LEGAL_ENTITY, USD, 1.e9, START_DATE, END_DATE, Frequency.P6M, SAT_SUN, 0.067).resolve(REF_DATA); ResolvedCdsTrade test2 = ResolvedCdsTrade.builder().product(product).info(TradeInfo.empty()).build(); coverBeanEquals(test1, test2); }
public ActionResult Details(int libraryId, int cdId) { Cds cd = Cds.Find(cdId); Dictionary <string, object> model = new Dictionary <string, object>(); Library library = Library.Find(libraryId); model.Add("cd", cd); model.Add("library", library); return(View(cd)); }
void UpdateEntityImageFields(Models.Entity entity) { Log.Progress($"Updating fields for {entity.Name} entity type."); var attributesRequest = new RetrieveEntityRequest { EntityFilters = EntityFilters.Entity, LogicalName = entity.Name }; var meta = ((RetrieveEntityResponse)Cds.Execute(attributesRequest)).EntityMetadata; var imageField = entity.Fields.Get("entityimage"); var imageIdField = entity.Fields.Get("entityimageid"); if (!string.IsNullOrEmpty(meta.PrimaryImageAttribute)) { if (imageField == null) { // Add field. Log.Information($"Field {Field.EntityImage.Name} being ADDED to schema."); entity.Fields.Add(Field.EntityImage); } else { // Update field. Log.Verbose($"Field {imageField.Name} being UPDATED in schema."); entity.Fields.Set(Field.EntityImage); } if (imageIdField == null) { // Add field. Log.Information($"Field {Field.EntityImageId.Name} being ADDED to schema."); entity.Fields.Add(Field.EntityImageId); } else { // Update field. Log.Verbose($"Field {imageIdField.Name} being UPDATED in schema."); entity.Fields.Set(Field.EntityImageId); } } else { if (imageField != null) { // Feature not enabled connected environment. Log.Warning($"Field {imageField.Name} being REMOVED from schema because this feature is not in the connected environment."); entity.Fields.Remove(imageField); } if (imageIdField != null) { // Feature not enabled connected environment. Log.Warning($"Field {imageIdField.Name} being REMOVED from schema because this feature is not in the connected environment."); entity.Fields.Remove(imageIdField); } } }
//------------------------------------------------------------------------- public virtual FunctionRequirements requirements(CdsTrade trade, ISet <Measure> measures, CalculationParameters parameters, ReferenceData refData) { // extract data from product Cds product = trade.Product; StandardId legalEntityId = product.LegalEntityId; Currency currency = product.Currency; // use lookup to build requirements CreditRatesMarketDataLookup lookup = parameters.getParameter(typeof(CreditRatesMarketDataLookup)); return(lookup.requirements(legalEntityId, currency)); }
//------------------------------------------------------------------------- public virtual void test_createTrade() { DatesCdsTemplate @base = DatesCdsTemplate.of(START, END, CONV1); LocalDate tradeDate = LocalDate.of(2015, 5, 5); CdsTrade test = @base.createTrade(LEGAL_ENTITY, tradeDate, BUY, NOTIONAL_2M, 0.05d, REF_DATA); Cds expected = Cds.of(BUY, LEGAL_ENTITY, CONV1.Currency, NOTIONAL_2M, START, END, Frequency.P3M, CONV1.SettlementDateOffset.Calendar, 0.05d); PeriodicSchedule sch1 = expected.PaymentSchedule; expected = expected.toBuilder().paymentSchedule(sch1.toBuilder().startDateBusinessDayAdjustment(sch1.BusinessDayAdjustment).rollConvention(RollConventions.DAY_20).build()).build(); assertEquals(test.Info.TradeDate, tradeDate); assertEquals(test.Product, expected); assertEquals(test.UpfrontFee, null); }
public ActionResult CreateCds(int libraryId, string title) { Dictionary <string, object> model = new Dictionary <string, object>(); Library foundLibrary = Library.Find(libraryId); Cds newCd = new Cds(title); foundLibrary.AddCd(newCd); List <Cds> libraryCds = foundLibrary.GetCds(); model.Add("cds", libraryCds); model.Add("library", foundLibrary); return(View("Details", model)); }
public virtual void pricePufTest() { double premium = 150d * ONE_BP; Cds product = Cds.of(BUY, LEGAL_ENTITY, GBP, 1.0e6, START_DATE, END_DATE, Frequency.P3M, DEFAULT_CALENDAR, premium); TradeInfo info = TradeInfo.builder().tradeDate(TODAY).settlementDate(product.SettlementDateOffset.adjust(TODAY, REF_DATA)).build(); ResolvedCdsTrade trade = CdsTrade.builder().product(product).info(info).build().resolve(REF_DATA); NodalCurve cc = CALIB.calibrate(ImmutableList.of(trade), DoubleArray.of(0.0123), DoubleArray.of(0.0), CurveName.of("test"), TODAY, DSC_CURVE, REC_RATES, REF_DATA); CreditRatesProvider rates = RATES_PROVIDER.toImmutableCreditRatesProvider().toBuilder().creditCurves(ImmutableMap.of(Pair.of(LEGAL_ENTITY, GBP), LegalEntitySurvivalProbabilities.of(LEGAL_ENTITY, IsdaCreditDiscountFactors.of(GBP, TODAY, cc)))).build(); double pointsUpFront = CONV.pointsUpfront(trade, rates, REF_DATA); double cleanPrice = CONV.cleanPrice(trade, rates, REF_DATA); double cleanPriceRe = CONV.cleanPriceFromPointsUpfront(pointsUpFront); assertEquals(cleanPrice, cleanPriceRe, TOL); }
public virtual void standardQuoteTest2() { double quotedSpread = 143.4 * ONE_BP; double expectedPuf = -0.2195134271137960; // taken from Excel-ISDA 1.8.2 double premium = 500d * ONE_BP; Cds product = Cds.of(SELL, LEGAL_ENTITY, GBP, 1.0e8, START_DATE, END_DATE, Frequency.P6M, DEFAULT_CALENDAR, premium); TradeInfo info = TradeInfo.builder().tradeDate(TODAY).settlementDate(product.SettlementDateOffset.adjust(TODAY, REF_DATA)).build(); ResolvedCdsTrade trade = CdsTrade.builder().product(product).info(info).build().resolve(REF_DATA); CdsQuote quotedSpreadQuoted = CdsQuote.of(CdsQuoteConvention.QUOTED_SPREAD, quotedSpread); CdsQuote derivedPuf = CONV.pointsUpFrontFromQuotedSpread(trade, quotedSpreadQuoted, RATES_PROVIDER, REF_DATA); assertEquals(derivedPuf.QuotedValue, expectedPuf, 5e-13); assertTrue(derivedPuf.QuoteConvention.Equals(CdsQuoteConvention.POINTS_UPFRONT)); CdsQuote derivedQuotedSpread = CONV.quotedSpreadFromPointsUpfront(trade, derivedPuf, RATES_PROVIDER, REF_DATA); assertEquals(derivedQuotedSpread.QuotedValue, quotedSpread, 1e-15); assertTrue(derivedQuotedSpread.QuoteConvention.Equals(CdsQuoteConvention.QUOTED_SPREAD)); }
public virtual void standardQuoteTest() { double pointsUpFront = 0.007; double expectedParSpread = 0.011112592882846; // taken from Excel-ISDA 1.8.2 double premium = 100d * ONE_BP; Cds product = Cds.of(BUY, LEGAL_ENTITY, GBP, 1.0e6, START_DATE, END_DATE, Frequency.P3M, DEFAULT_CALENDAR, premium); TradeInfo info = TradeInfo.builder().tradeDate(TODAY).settlementDate(product.SettlementDateOffset.adjust(TODAY, REF_DATA)).build(); ResolvedCdsTrade trade = CdsTrade.builder().product(product).info(info).build().resolve(REF_DATA); CdsQuote pufQuote = CdsQuote.of(CdsQuoteConvention.POINTS_UPFRONT, pointsUpFront); CdsQuote quotedSpread = CONV.quotedSpreadFromPointsUpfront(trade, pufQuote, RATES_PROVIDER, REF_DATA); assertEquals(quotedSpread.QuotedValue, expectedParSpread, 1e-14); assertTrue(quotedSpread.QuoteConvention.Equals(CdsQuoteConvention.QUOTED_SPREAD)); CdsQuote derivedPuf = CONV.pointsUpFrontFromQuotedSpread(trade, quotedSpread, RATES_PROVIDER, REF_DATA); assertEquals(derivedPuf.QuotedValue, pointsUpFront, 1e-15); assertTrue(derivedPuf.QuoteConvention.Equals(CdsQuoteConvention.POINTS_UPFRONT)); }
public virtual void test_of() { BusinessDayAdjustment bussAdj = BusinessDayAdjustment.of(FOLLOWING, SAT_SUN); PeriodicSchedule expected = PeriodicSchedule.builder().startDate(START_DATE).endDate(END_DATE).businessDayAdjustment(bussAdj).startDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).endDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).frequency(P3M).rollConvention(RollConventions.NONE).stubConvention(SMART_INITIAL).build(); assertEquals(PRODUCT_STD.PaymentSchedule, expected); assertEquals(PRODUCT_STD.BuySell, BUY); assertEquals(PRODUCT_STD.Currency, USD); assertEquals(PRODUCT_STD.DayCount, ACT_360); assertEquals(PRODUCT_STD.FixedRate, COUPON); assertEquals(PRODUCT_STD.LegalEntityId, LEGAL_ENTITY); assertEquals(PRODUCT_STD.Notional, NOTIONAL); assertEquals(PRODUCT_STD.PaymentOnDefault, ACCRUED_PREMIUM); assertEquals(PRODUCT_STD.ProtectionStart, BEGINNING); assertEquals(PRODUCT_STD.SettlementDateOffset, SETTLE_DAY_ADJ); assertEquals(PRODUCT_STD.StepinDateOffset, STEPIN_DAY_ADJ); Cds test = Cds.of(BUY, LEGAL_ENTITY, USD, NOTIONAL, START_DATE, END_DATE, P3M, SAT_SUN, COUPON); assertEquals(test, PRODUCT_STD); }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case 3237038: // info this.info_Renamed = (TradeInfo)newValue; break; case -309474065: // product this.product_Renamed = (Cds)newValue; break; case 963468344: // upfrontFee this.upfrontFee_Renamed = (AdjustablePayment)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
public virtual void test_builder() { LocalDate startDate = LocalDate.of(2014, 12, 20); LocalDate endDate = LocalDate.of(2020, 10, 20); PeriodicSchedule sch = PeriodicSchedule.of(startDate, endDate, P3M, BusinessDayAdjustment.NONE, SHORT_INITIAL, RollConventions.NONE); Cds test = Cds.builder().paymentSchedule(sch).buySell(SELL).currency(JPY).dayCount(ACT_365F).fixedRate(COUPON).legalEntityId(LEGAL_ENTITY).notional(NOTIONAL).paymentOnDefault(PaymentOnDefault.NONE).protectionStart(ProtectionStartOfDay.NONE).settlementDateOffset(SETTLE_DAY_ADJ).stepinDateOffset(STEPIN_DAY_ADJ).build(); assertEquals(test.PaymentSchedule, sch); assertEquals(test.BuySell, SELL); assertEquals(test.Currency, JPY); assertEquals(test.DayCount, ACT_365F); assertEquals(test.FixedRate, COUPON); assertEquals(test.LegalEntityId, LEGAL_ENTITY); assertEquals(test.Notional, NOTIONAL); assertEquals(test.PaymentOnDefault, PaymentOnDefault.NONE); assertEquals(test.ProtectionStart, ProtectionStartOfDay.NONE); assertEquals(test.SettlementDateOffset, SETTLE_DAY_ADJ); assertEquals(test.StepinDateOffset, STEPIN_DAY_ADJ); assertEquals(test.CrossCurrency, false); assertEquals(test.allPaymentCurrencies(), ImmutableSet.of(JPY)); assertEquals(test.allCurrencies(), ImmutableSet.of(JPY)); }
//------------------------------------------------------------------------- public virtual void test_toTrade() { LocalDate tradeDate = LocalDate.of(2015, 12, 21); // 19, 20 weekend LocalDate startDate = LocalDate.of(2015, 12, 20); LocalDate endDate = LocalDate.of(2020, 12, 20); LocalDate settlementDate = LocalDate.of(2015, 12, 24); TradeInfo info = TradeInfo.builder().tradeDate(tradeDate).settlementDate(settlementDate).build(); Tenor tenor = Tenor.TENOR_5Y; ImmutableCdsConvention @base = ImmutableCdsConvention.of(NAME, GBP, ACT_360, P3M, BUSI_ADJ_STD, SETTLE_DAY_ADJ_STD); Cds product = Cds.builder().legalEntityId(LEGAL_ENTITY).paymentSchedule(PeriodicSchedule.builder().startDate(startDate).endDate(endDate).frequency(P3M).businessDayAdjustment(BUSI_ADJ_STD).startDateBusinessDayAdjustment(BUSI_ADJ_STD).endDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).stubConvention(StubConvention.SMART_INITIAL).rollConvention(RollConventions.DAY_20).build()).buySell(BUY).currency(GBP).dayCount(ACT_360).notional(NOTIONAL).fixedRate(COUPON).paymentOnDefault(PaymentOnDefault.ACCRUED_PREMIUM).protectionStart(ProtectionStartOfDay.BEGINNING).stepinDateOffset(STEPIN_DAY_ADJ).settlementDateOffset(SETTLE_DAY_ADJ_STD).build(); CdsTrade expected = CdsTrade.builder().info(info).product(product).build(); CdsTrade test1 = @base.createTrade(LEGAL_ENTITY, tradeDate, tenor, BUY, NOTIONAL, COUPON, REF_DATA); assertEquals(test1, expected); CdsTrade test2 = @base.createTrade(LEGAL_ENTITY, tradeDate, startDate, tenor, BUY, NOTIONAL, COUPON, REF_DATA); assertEquals(test2, expected); CdsTrade test3 = @base.createTrade(LEGAL_ENTITY, tradeDate, startDate, endDate, BUY, NOTIONAL, COUPON, REF_DATA); assertEquals(test3, expected); CdsTrade test4 = @base.toTrade(LEGAL_ENTITY, info, startDate, endDate, BUY, NOTIONAL, COUPON); assertEquals(test4, expected); AdjustablePayment upfront = AdjustablePayment.of(CurrencyAmount.of(GBP, 0.1 * NOTIONAL), settlementDate); CdsTrade expectedWithUf = CdsTrade.builder().info(info).product(product).upfrontFee(upfront).build(); CdsTrade test5 = @base.createTrade(LEGAL_ENTITY, tradeDate, tenor, BUY, NOTIONAL, COUPON, upfront, REF_DATA); assertEquals(test5, expectedWithUf); CdsTrade test6 = @base.createTrade(LEGAL_ENTITY, tradeDate, startDate, tenor, BUY, NOTIONAL, COUPON, upfront, REF_DATA); assertEquals(test6, expectedWithUf); CdsTrade test7 = @base.createTrade(LEGAL_ENTITY, tradeDate, startDate, endDate, BUY, NOTIONAL, COUPON, upfront, REF_DATA); assertEquals(test7, expectedWithUf); CdsTrade test8 = @base.toTrade(LEGAL_ENTITY, info, startDate, endDate, BUY, NOTIONAL, COUPON, upfront); assertEquals(test8, expectedWithUf); }
/// <summary> /// Creates a trade representing the CDS index at the node. /// <para> /// This uses the observed market data to build the CDS index trade that the node represents. /// The resulting trade is not resolved. /// The notional of the trade is taken from the 'quantity' variable. /// The quantity is signed and will affect whether the trade is Buy or Sell. /// The valuation date is defined by the market data. /// /// </para> /// </summary> /// <param name="quantity"> the quantity or notional of the trade </param> /// <param name="marketData"> the market data required to build a trade for the instrument, including the valuation date </param> /// <param name="refData"> the reference data, used to resolve the trade dates </param> /// <returns> a trade representing the instrument at the node </returns> public CdsIndexCalibrationTrade trade(double quantity, MarketData marketData, ReferenceData refData) { BuySell buySell = quantity > 0 ? BuySell.BUY : BuySell.SELL; LocalDate valuationDate = marketData.ValuationDate; double quoteValue = marketData.getValue(observableId); CdsQuote quote = CdsQuote.of(quoteConvention, quoteValue); double notional = Math.Abs(quantity); CdsTrade cdsTrade = null; if (quoteConvention.Equals(CdsQuoteConvention.PAR_SPREAD)) { cdsTrade = template.createTrade(cdsIndexId, valuationDate, buySell, notional, quoteValue, refData); } else { double coupon = FixedRate.Value; // always success cdsTrade = template.createTrade(cdsIndexId, valuationDate, buySell, notional, coupon, refData); } Cds cdsProduct = cdsTrade.Product; CdsIndexTrade cdsIndex = CdsIndexTrade.builder().info(cdsTrade.Info).product(CdsIndex.builder().buySell(cdsProduct.BuySell).currency(cdsProduct.Currency).notional(cdsProduct.Notional).cdsIndexId(cdsIndexId).legalEntityIds(legalEntityIds).dayCount(cdsProduct.DayCount).paymentSchedule(cdsProduct.PaymentSchedule).fixedRate(cdsProduct.FixedRate).paymentOnDefault(cdsProduct.PaymentOnDefault).protectionStart(cdsProduct.ProtectionStart).settlementDateOffset(cdsProduct.SettlementDateOffset).stepinDateOffset(cdsProduct.StepinDateOffset).build()).build(); return(CdsIndexCalibrationTrade.of(cdsIndex, quote)); }
public ActionResult DeleteAll() { Cds.ClearAll(); return(View()); }
public ActionResult Details(int id) { Cds cd = Cds.Find(id); return(View(cd)); }
public int PageCount() { return(Convert.ToInt32(Math.Ceiling(Cds.Where(p => p.Product.Available > 0).Count() / (double)Constants.PRODUCTS_PER_PAGE))); }
public List <Cd> PaginatedCds() { int start = (CurrentPage - 1) * Constants.PRODUCTS_PER_PAGE; return(Cds.OrderBy(p => p.ProductId).Skip(start).Take(Constants.PRODUCTS_PER_PAGE).ToList()); }
void UpdateRelationships(Models.Entity entity, bool intelligently = false) { Log.Progress($"Updating relationships for {entity.Name} entity type."); var relationshipsRequest = new RetrieveEntityRequest { EntityFilters = EntityFilters.Relationships, LogicalName = entity.Name }; var relationships = ((RetrieveEntityResponse)Cds.Execute(relationshipsRequest)).EntityMetadata.ManyToManyRelationships .Where(r => r.Entity1LogicalName == entity.Name) .ToArray(); // NOTE: CMT doesn't capture SchemaName as name for relationship - but probably should. It uses IntersectEntityName instead. var relationshipsCorrelatedLeft = from meta in relationships join schema in entity.Relationships on meta.IntersectEntityName equals schema.Name into joinGroup from j in joinGroup.DefaultIfEmpty() select(meta, j); var relationshipsCorrelatedRight = from schema in entity.Relationships join meta in relationships on schema.Name equals meta.IntersectEntityName into joinGroup from j in joinGroup.DefaultIfEmpty() select(j, schema); var relationshipsCorrelated = relationshipsCorrelatedRight .Union(relationshipsCorrelatedLeft) .OrderBy(x => x.Item1 != null ? x.Item1.IntersectEntityName : x.Item2.Name) .ToArray(); foreach (var(meta, schema) in relationshipsCorrelated) { if (meta == null) { // Relationship does not exist in connected environment. Log.Warning($"Relationship {schema.Name} being REMOVED from schema."); entity.Relationships.Remove(schema); } else if (schema == null) { if (intelligently) { if (meta.IsCustomRelationship != true) { // Check if this is a foreign relationship. var isForeignRelationship = !CurrentDocument.Entities.Exists(e => e.Name == meta.Entity2LogicalName); if (isForeignRelationship) { // Check if schema already includes relationships with entities not included in schema. var entityHasForeignRelationshipsInSchema = entity.Relationships.Any(r => !CurrentDocument.Entities.Exists(e => e.Name == r.TargetEntity)); if (!entityHasForeignRelationshipsInSchema) { // Assuming that non-custom foreign relationships are not appropriate for automatic inclusion. Log.Information($"Relationship {meta.SchemaName} being IGNORED."); continue; } } } } // Relationship does not exist in schema. Log.Information($"Relationship {meta.SchemaName} being ADDED to schema."); entity.Relationships.Add(Copy.Metadata.ToRelationship(meta)); } else { // Update relationship. Log.Verbose($"Relationship {meta.SchemaName} being UPDATED in schema."); Copy.Metadata.ToRelationship(meta, schema); } } }
void UpdateFields(Models.Entity entity, bool intelligently = false) { if (intelligently) { if (entity.Fields?.Any() != true && entity.Relationships?.Any() == true) { // Assuming only the associations are wanted. Log.Progress($"Skip updating fields for {entity.Name} entity type."); return; } } Log.Progress($"Updating fields for {entity.Name} entity type."); var attributesRequest = new RetrieveEntityRequest { EntityFilters = EntityFilters.Attributes, LogicalName = entity.Name }; var attributes = ((RetrieveEntityResponse)Cds.Execute(attributesRequest)).EntityMetadata.Attributes; var fields = entity.Fields .Where(f => f.Name != Field.EntityImage.Name && f.Name != Field.EntityImageId.Name) .ToArray(); var attributesCorrelatedLeft = from a in attributes join f in fields on a.LogicalName equals f.Name into joinGroup from j in joinGroup.DefaultIfEmpty() select(a, j); var attributesCorrelatedRight = from f in fields join a in attributes on f.Name equals a.LogicalName into joinGroup from j in joinGroup.DefaultIfEmpty() select(j, f); var attributesCorrelated = attributesCorrelatedLeft .Union(attributesCorrelatedRight) .OrderBy(x => x.Item1 != null ? x.Item1.LogicalName : x.Item2.Name) .ToArray(); foreach (var(attribute, field) in attributesCorrelated) { if (attribute == null) { // Attribute does not exist in connected environment. Log.Warning($"Field {field.Name} being REMOVED from schema because it does not exist in the connected environment."); entity.Fields.Remove(field); } else if (Copy.Metadata.IsUnsupported(attribute)) { Log.Silently($"Attribute {attribute.LogicalName} being IGNORED because it is not supported."); if (field != null) { Log.Warning($"Field {field.Name} being REMOVED from schema because it is not supported."); entity.Fields.Remove(field); } } else if (!Copy.Metadata.IsWritable(attribute)) { Log.Silently($"Attribute {attribute.LogicalName} being IGNORED because it is not writable."); if (field != null) { Log.Warning($"Field {field.Name} being REMOVED from schema because it is not writable."); entity.Fields.Remove(field); } } else if (field == null) { // Attribute does not exist in schema. Log.Information($"Attribute {attribute.LogicalName} being ADDED to schema."); entity.Fields.Add(Copy.Metadata.ToField(attribute)); } else { // Update field. Log.Verbose($"Attribute {attribute.LogicalName} being UPDATED in schema."); Copy.Metadata.ToField(attribute, field); } } }
/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(CdsTrade beanToCopy) { this.info_Renamed = beanToCopy.Info; this.product_Renamed = beanToCopy.Product; this.upfrontFee_Renamed = beanToCopy.upfrontFee; }
static IsdaCompliantCreditCurveCalibratorBase() { ImmutableList.Builder <IsdaCreditCurveNode> dscNodeBuilder = ImmutableList.builder(); for (int i = 0; i < NUM_MM; i++) { Tenor tenor = Tenor.ofMonths(MM_MONTHS[i]); dscNodeBuilder.add(DepositIsdaCreditCurveNode.of(QuoteId.of(StandardId.of("OG", ID_VALUES[i])), ADJ_3D, BUS_ADJ, tenor, ACT_360)); } for (int i = NUM_MM; i < NUM_INSTRUMENTS; i++) { Tenor tenor = Tenor.ofYears(SWAP_YEARS[i - NUM_MM]); dscNodeBuilder.add(SwapIsdaCreditCurveNode.of(QuoteId.of(StandardId.of("OG", ID_VALUES[i])), ADJ_3D, BUS_ADJ, tenor, THIRTY_U_360, Frequency.P12M)); } DSC_NODES = dscNodeBuilder.build(); EXP_NODE_CDS = new ResolvedCdsTrade[NUM_TESTS][]; NODE_CDS = new CdsIsdaCreditCurveNode[NUM_TESTS][]; CDS_MARKET_DATA = new ImmutableMarketData[NUM_TESTS]; SPREADS = new double[NUM_TESTS][]; YIELD_CURVES = new ImmutableCreditRatesProvider[NUM_TESTS]; // case0 LocalDate tradeDate0 = LocalDate.of(2011, 6, 19); LocalDate startDate0 = LocalDate.of(2011, 3, 21); YIELD_CURVES[0] = createRatesProvider(tradeDate0, tradeDate0, 1d, 0.4); Period[] tenors = new Period[] { Period.ofMonths(6), Period.ofYears(1), Period.ofYears(3), Period.ofYears(5), Period.ofYears(7), Period.ofYears(10) }; int nTenors = tenors.Length; EXP_NODE_CDS[0] = new ResolvedCdsTrade[nTenors]; NODE_CDS[0] = new CdsIsdaCreditCurveNode[nTenors]; ImmutableMarketDataBuilder builderCredit0 = ImmutableMarketData.builder(tradeDate0); SPREADS[0] = new double[] { 0.00886315689995649, 0.00886315689995649, 0.0133044689825873, 0.0171490070952563, 0.0183903639181293, 0.0194721890639724 }; for (int i = 0; i < nTenors; ++i) { Cds product = Cds.of(BUY, LEGAL_ENTITY, EUR, 1d, startDate0, LocalDate.of(2011, 6, 20).plus(tenors[i]), Frequency.P3M, DEFAULT_CALENDAR, SPREADS[0][i]); EXP_NODE_CDS[0][i] = CdsTrade.builder().info(TradeInfo.builder().settlementDate(product.SettlementDateOffset.adjust(tradeDate0, REF_DATA)).build()).product(product).build().resolve(REF_DATA); CdsConvention conv = ImmutableCdsConvention.of("conv", EUR, ACT_360, Frequency.P3M, BUS_ADJ, CDS_SETTLE_STD); CdsTemplate temp = DatesCdsTemplate.of(startDate0, LocalDate.of(2011, 6, 20).plus(tenors[i]), conv); QuoteId id = QuoteId.of(StandardId.of("OG", tenors[i].ToString())); NODE_CDS[0][i] = CdsIsdaCreditCurveNode.ofParSpread(temp, id, LEGAL_ENTITY); builderCredit0.addValue(id, SPREADS[0][i]); } CDS_MARKET_DATA[0] = builderCredit0.build(); // case1 LocalDate tradeDate1 = LocalDate.of(2011, 3, 21); LocalDate snapDate1 = LocalDate.of(2011, 3, 18); LocalDate effDate1 = LocalDate.of(2011, 3, 20); //note this is a Sunday - for a standard CDS this would roll to the Monday. YIELD_CURVES[1] = createRatesProvider(tradeDate1, snapDate1, 1d, 0.4); tenors = new Period[] { Period.ofMonths(6), Period.ofYears(1), Period.ofYears(3), Period.ofYears(5), Period.ofYears(7), Period.ofYears(10) }; nTenors = tenors.Length; NODE_CDS[1] = new CdsIsdaCreditCurveNode[nTenors]; ImmutableMarketDataBuilder builderCredit1 = ImmutableMarketData.builder(tradeDate1); EXP_NODE_CDS[1] = new ResolvedCdsTrade[nTenors]; SPREADS[1] = new double[] { 0.027, 0.018, 0.012, 0.009, 0.007, 0.006 }; for (int i = 0; i < nTenors; ++i) { Cds product = Cds.of(BUY, LEGAL_ENTITY, EUR, 1d, effDate1, LocalDate.of(2011, 6, 20).plus(tenors[i]), P3M, DEFAULT_CALENDAR, SPREADS[1][i]); EXP_NODE_CDS[1][i] = CdsTrade.builder().info(TradeInfo.builder().settlementDate(product.SettlementDateOffset.adjust(tradeDate1, REF_DATA)).build()).product(product).build().resolve(REF_DATA); CdsConvention conv = ImmutableCdsConvention.builder().name("conv").currency(EUR).dayCount(ACT_360).paymentFrequency(P3M).startDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).businessDayAdjustment(BUS_ADJ).settlementDateOffset(CDS_SETTLE_STD).build(); CdsTemplate temp = DatesCdsTemplate.of(effDate1, LocalDate.of(2011, 6, 20).plus(tenors[i]), conv); QuoteId id = QuoteId.of(StandardId.of("OG", tenors[i].ToString())); NODE_CDS[1][i] = CdsIsdaCreditCurveNode.ofParSpread(temp, id, LEGAL_ENTITY); builderCredit1.addValue(id, SPREADS[1][i]); } CDS_MARKET_DATA[1] = builderCredit1.build(); // case2 LocalDate tradeDate2 = LocalDate.of(2011, 5, 30); LocalDate snapDate2 = LocalDate.of(2011, 5, 29); YIELD_CURVES[2] = createRatesProvider(tradeDate2, snapDate2, 1d, 0.25); LocalDate[] matDates2 = new LocalDate[] { LocalDate.of(2011, 6, 20), LocalDate.of(2012, 5, 30), LocalDate.of(2014, 6, 20), LocalDate.of(2016, 6, 20), LocalDate.of(2018, 6, 20) }; int nMatDates2 = matDates2.Length; NODE_CDS[2] = new CdsIsdaCreditCurveNode[nMatDates2]; ImmutableMarketDataBuilder builderCredit2 = ImmutableMarketData.builder(tradeDate2); EXP_NODE_CDS[2] = new ResolvedCdsTrade[nMatDates2]; SPREADS[2] = new double[] { 0.05, 0.05, 0.05, 0.05, 0.05 }; for (int i = 0; i < nMatDates2; ++i) { Cds product = Cds.of(BUY, LEGAL_ENTITY, EUR, 1d, tradeDate2.plusDays(1), matDates2[i], P3M, DEFAULT_CALENDAR, SPREADS[2][i]).toBuilder().dayCount(THIRTY_U_360).build(); EXP_NODE_CDS[2][i] = CdsTrade.builder().info(TradeInfo.builder().settlementDate(product.SettlementDateOffset.adjust(tradeDate2, REF_DATA)).build()).product(product).build().resolve(REF_DATA); CdsConvention conv = ImmutableCdsConvention.builder().name("conv").currency(EUR).dayCount(THIRTY_U_360).paymentFrequency(P3M).rollConvention(RollConventions.NONE).businessDayAdjustment(BUS_ADJ).settlementDateOffset(CDS_SETTLE_STD).build(); CdsTemplate temp = DatesCdsTemplate.of(tradeDate2.plusDays(1), matDates2[i], conv); QuoteId id = QuoteId.of(StandardId.of("OG", matDates2[i].ToString())); NODE_CDS[2][i] = CdsIsdaCreditCurveNode.ofParSpread(temp, id, LEGAL_ENTITY); builderCredit2.addValue(id, SPREADS[2][i]); } CDS_MARKET_DATA[2] = builderCredit2.build(); // case3 LocalDate tradeDate3 = LocalDate.of(2011, 5, 30); LocalDate snapDate3 = LocalDate.of(2011, 5, 29); LocalDate effDate3 = LocalDate.of(2011, 7, 31); YIELD_CURVES[3] = createRatesProvider(tradeDate3, snapDate3, 1d, 0.25); LocalDate[] matDates3 = new LocalDate[] { LocalDate.of(2011, 11, 30), LocalDate.of(2012, 5, 30), LocalDate.of(2014, 5, 30), LocalDate.of(2016, 5, 30), LocalDate.of(2018, 5, 30), LocalDate.of(2021, 5, 30) }; int nMatDates3 = matDates3.Length; NODE_CDS[3] = new CdsIsdaCreditCurveNode[nMatDates3]; ImmutableMarketDataBuilder builderCredit3 = ImmutableMarketData.builder(tradeDate3); EXP_NODE_CDS[3] = new ResolvedCdsTrade[nMatDates3]; SPREADS[3] = new double[] { 0.07, 0.06, 0.05, 0.055, 0.06, 0.065 }; for (int i = 0; i < nMatDates3; ++i) { Cds product = Cds.builder().buySell(BUY).legalEntityId(LEGAL_ENTITY).currency(EUR).dayCount(ACT_365F).fixedRate(SPREADS[3][i]).notional(1d).paymentSchedule(PeriodicSchedule.builder().businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, DEFAULT_CALENDAR)).startDate(effDate3).endDate(matDates3[i]).startDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).endDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).frequency(Frequency.P6M).rollConvention(RollConventions.NONE).stubConvention(StubConvention.LONG_INITIAL).build()).paymentOnDefault(PaymentOnDefault.ACCRUED_PREMIUM).protectionStart(ProtectionStartOfDay.BEGINNING).stepinDateOffset(DaysAdjustment.ofCalendarDays(1)).settlementDateOffset(CDS_SETTLE_STD).build(); EXP_NODE_CDS[3][i] = CdsTrade.builder().info(TradeInfo.builder().settlementDate(product.SettlementDateOffset.adjust(tradeDate3, REF_DATA)).build()).product(product).build().resolve(REF_DATA); CdsConvention conv = ImmutableCdsConvention.builder().name("conv").currency(EUR).dayCount(ACT_365F).paymentFrequency(Frequency.P6M).rollConvention(RollConventions.NONE).stubConvention(StubConvention.LONG_INITIAL).startDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, DEFAULT_CALENDAR)).settlementDateOffset(CDS_SETTLE_STD).build(); CdsTemplate temp = DatesCdsTemplate.of(effDate3, matDates3[i], conv); QuoteId id = QuoteId.of(StandardId.of("OG", matDates3[i].ToString())); NODE_CDS[3][i] = CdsIsdaCreditCurveNode.ofParSpread(temp, id, LEGAL_ENTITY); builderCredit3.addValue(id, SPREADS[3][i]); } CDS_MARKET_DATA[3] = builderCredit3.build(); // case4: designed to trip the low rates/low spreads branch LocalDate tradeDate4 = LocalDate.of(2014, 1, 14); LocalDate snapDate4 = LocalDate.of(2014, 1, 13); YIELD_CURVES[4] = createRatesProvider(tradeDate4, snapDate4, 1d / 1000d, 0.4); int nSpreads4 = 6; NODE_CDS[4] = new CdsIsdaCreditCurveNode[nSpreads4]; ImmutableMarketDataBuilder builderCredit4 = ImmutableMarketData.builder(tradeDate4); SPREADS[4] = new double[nSpreads4]; Arrays.fill(SPREADS[4], 1.0e-4); EXP_NODE_CDS[4] = new ResolvedCdsTrade[nSpreads4]; for (int i = 0; i < nSpreads4; ++i) { Cds product = Cds.of(BUY, LEGAL_ENTITY, EUR, 1d, LocalDate.of(2013, 12, 20), LocalDate.of(2014, 3, 20).plus(tenors[i]), P3M, DEFAULT_CALENDAR, SPREADS[4][i]); EXP_NODE_CDS[4][i] = CdsTrade.builder().info(TradeInfo.builder().settlementDate(product.SettlementDateOffset.adjust(tradeDate4, REF_DATA)).build()).product(product).build().resolve(REF_DATA); CdsConvention conv = ImmutableCdsConvention.of("conv", EUR, ACT_360, P3M, BUS_ADJ, CDS_SETTLE_STD); CdsTemplate temp = DatesCdsTemplate.of(LocalDate.of(2013, 12, 20), LocalDate.of(2014, 3, 20).plus(tenors[i]), conv); QuoteId id = QuoteId.of(StandardId.of("OG", tenors[i].ToString())); NODE_CDS[4][i] = CdsIsdaCreditCurveNode.ofParSpread(temp, id, LEGAL_ENTITY); builderCredit4.addValue(id, SPREADS[4][i]); } CDS_MARKET_DATA[4] = builderCredit4.build(); }
/// <summary> /// Sets the CDS product that was agreed when the trade occurred. /// <para> /// The product captures the contracted financial details of the trade. /// </para> /// </summary> /// <param name="product"> the new value, not null </param> /// <returns> this, for chaining, not null </returns> public Builder product(Cds product) { JodaBeanUtils.notNull(product, "product"); this.product_Renamed = product; return(this); }
private void Delete() { dataContext.Cds.Remove(SelectedCd); Cds.Remove(SelectedCd); }