//------------------------------------------------------------------------- // notional schedule private static NotionalSchedule parseNotionalSchedule(CsvRow row, string leg) { NotionalSchedule.Builder builder = NotionalSchedule.builder(); // basics Currency currency = Currency.of(getValueWithFallback(row, leg, CURRENCY_FIELD)); builder.currency(currency); builder.amount(ValueSchedule.of(LoaderUtils.parseDouble(getValueWithFallback(row, leg, NOTIONAL_FIELD)))); // fx reset Optional <FxIndex> fxIndexOpt = findValue(row, leg, FX_RESET_INDEX_FIELD).map(s => FxIndex.of(s)); Optional <Currency> notionalCurrencyOpt = findValue(row, leg, NOTIONAL_CURRENCY_FIELD).map(s => Currency.of(s)); Optional <FxResetFixingRelativeTo> fxFixingRelativeToOpt = findValue(row, leg, FX_RESET_RELATIVE_TO_FIELD).map(s => FxResetFixingRelativeTo.of(s)); Optional <DaysAdjustment> fxResetAdjOpt = parseDaysAdjustment(row, leg, FX_RESET_OFFSET_DAYS_FIELD, FX_RESET_OFFSET_CAL_FIELD, FX_RESET_OFFSET_ADJ_CNV_FIELD, FX_RESET_OFFSET_ADJ_CAL_FIELD); if (fxIndexOpt.Present) { FxIndex fxIndex = fxIndexOpt.get(); FxResetCalculation.Builder fxResetBuilder = FxResetCalculation.builder(); fxResetBuilder.index(fxIndex); fxResetBuilder.referenceCurrency(notionalCurrencyOpt.orElse(fxIndex.CurrencyPair.other(currency))); fxFixingRelativeToOpt.ifPresent(v => fxResetBuilder.fixingRelativeTo(v)); fxResetAdjOpt.ifPresent(v => fxResetBuilder.fixingDateOffset(v)); builder.fxReset(fxResetBuilder.build()); } else if (notionalCurrencyOpt.Present || fxFixingRelativeToOpt.Present || fxResetAdjOpt.Present) { throw new System.ArgumentException("Swap trade FX Reset must define field '" + leg + FX_RESET_INDEX_FIELD + "'"); } // optionals findValue(row, leg, NOTIONAL_INITIAL_EXCHANGE_FIELD).map(s => LoaderUtils.parseBoolean(s)).ifPresent(v => builder.initialExchange(v)); findValue(row, leg, NOTIONAL_INTERMEDIATE_EXCHANGE_FIELD).map(s => LoaderUtils.parseBoolean(s)).ifPresent(v => builder.intermediateExchange(v)); findValue(row, leg, NOTIONAL_FINAL_EXCHANGE_FIELD).map(s => LoaderUtils.parseBoolean(s)).ifPresent(v => builder.finalExchange(v)); return(builder.build()); }
//------------------------------------------------------------------------- // fixed rate calculation private static RateCalculation parseFixedRateCalculation(CsvRow row, string leg, Currency currency, DayCount defaultFixedLegDayCount) { FixedRateCalculation.Builder builder = FixedRateCalculation.builder(); // basics double fixedRate = LoaderUtils.parseDoublePercent(getValue(row, leg, FIXED_RATE_FIELD)); DayCount dayCount = findValue(row, leg, DAY_COUNT_FIELD).map(s => LoaderUtils.parseDayCount(s)).orElse(defaultFixedLegDayCount); if (dayCount == null) { throw new System.ArgumentException("Swap leg must define day count using '" + leg + DAY_COUNT_FIELD + "'"); } builder.dayCount(dayCount); builder.rate(ValueSchedule.of(fixedRate)); // initial stub double?initialStubRateOpt = findValue(row, leg, INITIAL_STUB_RATE_FIELD).map(s => LoaderUtils.parseDoublePercent(s)); double?initialStubAmountOpt = findValue(row, leg, INITIAL_STUB_AMOUNT_FIELD).map(s => LoaderUtils.parseDouble(s)); if (initialStubRateOpt.HasValue && initialStubAmountOpt.HasValue) { throw new System.ArgumentException("Swap leg must not define both '" + leg + INITIAL_STUB_RATE_FIELD + "' and '" + leg + INITIAL_STUB_AMOUNT_FIELD + "'"); } initialStubRateOpt.ifPresent(v => builder.initialStub(FixedRateStubCalculation.ofFixedRate(v))); initialStubAmountOpt.ifPresent(v => builder.initialStub(FixedRateStubCalculation.ofKnownAmount(CurrencyAmount.of(currency, v)))); // final stub double?finalStubRateOpt = findValue(row, leg, FINAL_STUB_RATE_FIELD).map(s => LoaderUtils.parseDoublePercent(s)); double?finalStubAmountOpt = findValue(row, leg, FINAL_STUB_AMOUNT_FIELD).map(s => LoaderUtils.parseDouble(s)); if (finalStubRateOpt.HasValue && finalStubAmountOpt.HasValue) { throw new System.ArgumentException("Swap leg must not define both '" + leg + FINAL_STUB_RATE_FIELD + "' and '" + leg + FINAL_STUB_AMOUNT_FIELD + "'"); } finalStubRateOpt.ifPresent(v => builder.finalStub(FixedRateStubCalculation.ofFixedRate(v))); finalStubAmountOpt.ifPresent(v => builder.finalStub(FixedRateStubCalculation.ofKnownAmount(CurrencyAmount.of(currency, v)))); return(builder.build()); }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case 1905311443: // dayCount this.dayCount_Renamed = (DayCount)newValue; break; case 3493088: // rate this.rate_Renamed = (ValueSchedule)newValue; break; case 1233359378: // initialStub this.initialStub_Renamed = (FixedRateStubCalculation)newValue; break; case 355242820: // finalStub this.finalStub_Renamed = (FixedRateStubCalculation)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
// variable fixed rate private static SwapTrade parseVariableRates(SwapTrade trade, IList <CsvRow> variableRows) { ImmutableList.Builder <ValueStep> stepBuilder = ImmutableList.builder(); foreach (CsvRow row in variableRows) { LocalDate date = LoaderUtils.parseDate(row.getValue(START_DATE_FIELD)); row.findValue(FIXED_RATE_FIELD).map(str => LoaderUtils.parseDoublePercent(str)).ifPresent(fixedRate => stepBuilder.add(ValueStep.of(date, ValueAdjustment.ofReplace(fixedRate)))); } ImmutableList <ValueStep> varRates = stepBuilder.build(); if (varRates.Empty) { return(trade); } // adjust the trade, inserting the variable rates ImmutableList.Builder <SwapLeg> legBuilder = ImmutableList.builder(); foreach (SwapLeg swapLeg in trade.Product.Legs) { RateCalculationSwapLeg leg = (RateCalculationSwapLeg)swapLeg; if (leg.Calculation is FixedRateCalculation) { FixedRateCalculation baseCalc = (FixedRateCalculation)leg.Calculation; FixedRateCalculation calc = baseCalc.toBuilder().rate(ValueSchedule.of(baseCalc.Rate.InitialValue, varRates)).build(); legBuilder.add(leg.toBuilder().calculation(calc).build()); } else { legBuilder.add(leg); } } return(replaceLegs(trade, legBuilder.build())); }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case 575402001: // currency this.currency_Renamed = (Currency)newValue; break; case -449555555: // fxReset this.fxReset_Renamed = (FxResetCalculation)newValue; break; case -1413853096: // amount this.amount_Renamed = (ValueSchedule)newValue; break; case -511982201: // initialExchange this.initialExchange_Renamed = (bool?)newValue.Value; break; case -2147112388: // intermediateExchange this.intermediateExchange_Renamed = (bool?)newValue.Value; break; case -1048781383: // finalExchange this.finalExchange_Renamed = (bool?)newValue.Value; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case 100346066: // index this.index_Renamed = (PriceIndex)newValue; break; case 106898: // lag this.lag_Renamed = (Period)newValue; break; case -1409010088: // indexCalculationMethod this.indexCalculationMethod_Renamed = (PriceIndexCalculationMethod)newValue; break; case 922631823: // firstIndexValue this.firstIndexValue_Renamed = (double?)newValue; break; case -91774989: // gearing this.gearing_Renamed = (ValueSchedule)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(FixedRateCalculation beanToCopy) { this.dayCount_Renamed = beanToCopy.DayCount; this.rate_Renamed = beanToCopy.Rate; this.initialStub_Renamed = beanToCopy.initialStub; this.finalStub_Renamed = beanToCopy.finalStub; }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case -885469925: // payReceive this.payReceive_Renamed = (PayReceive)newValue; break; case 304659814: // accrualSchedule this.accrualSchedule_Renamed = (PeriodicSchedule)newValue; break; case -1499086147: // paymentSchedule this.paymentSchedule_Renamed = (PaymentSchedule)newValue; break; case -1413853096: // amount this.amount_Renamed = (ValueSchedule)newValue; break; case 575402001: // currency this.currency_Renamed = (Currency)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(InflationRateCalculation beanToCopy) { this.index_Renamed = beanToCopy.Index; this.lag_Renamed = beanToCopy.Lag; this.indexCalculationMethod_Renamed = beanToCopy.IndexCalculationMethod; this.firstIndexValue_Renamed = beanToCopy.firstIndexValue; this.gearing_Renamed = beanToCopy.gearing; }
/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(KnownAmountSwapLeg beanToCopy) { this.payReceive_Renamed = beanToCopy.PayReceive; this.accrualSchedule_Renamed = beanToCopy.AccrualSchedule; this.paymentSchedule_Renamed = beanToCopy.PaymentSchedule; this.amount_Renamed = beanToCopy.Amount; this.currency_Renamed = beanToCopy.Currency; }
static CapitalIndexedBondTest() { IList <ValueStep> steps = new List <ValueStep>(); steps.Add(ValueStep.of(1, ValueAdjustment.ofReplace(COUPONS[1]))); steps.Add(ValueStep.of(2, ValueAdjustment.ofReplace(COUPONS[2]))); steps.Add(ValueStep.of(3, ValueAdjustment.ofReplace(COUPONS[3]))); COUPON = ValueSchedule.of(COUPONS[0], steps); }
/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(NotionalSchedule beanToCopy) { this.currency_Renamed = beanToCopy.Currency; this.fxReset_Renamed = beanToCopy.fxReset; this.amount_Renamed = beanToCopy.Amount; this.initialExchange_Renamed = beanToCopy.InitialExchange; this.intermediateExchange_Renamed = beanToCopy.IntermediateExchange; this.finalExchange_Renamed = beanToCopy.FinalExchange; }
private FixedRateCalculation(DayCount dayCount, ValueSchedule rate, FixedRateStubCalculation initialStub, FixedRateStubCalculation finalStub) { JodaBeanUtils.notNull(dayCount, "dayCount"); JodaBeanUtils.notNull(rate, "rate"); this.dayCount = dayCount; this.rate = rate; this.initialStub = initialStub; this.finalStub = finalStub; }
/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(OvernightRateCalculation beanToCopy) { this.dayCount_Renamed = beanToCopy.DayCount; this.index_Renamed = beanToCopy.Index; this.accrualMethod_Renamed = beanToCopy.AccrualMethod; this.negativeRateMethod_Renamed = beanToCopy.NegativeRateMethod; this.rateCutOffDays_Renamed = beanToCopy.RateCutOffDays; this.gearing_Renamed = beanToCopy.gearing; this.spread_Renamed = beanToCopy.spread; }
public virtual void test_summarize_irs_weird() { PeriodicSchedule accrual = PeriodicSchedule.of(date(2018, 2, 12), date(2020, 2, 12), Frequency.P3M, BusinessDayAdjustment.NONE, SHORT_INITIAL, false); PaymentSchedule payment = PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build(); NotionalSchedule notional = NotionalSchedule.of(GBP, ValueSchedule.builder().initialValue(1_000_000).stepSequence(ValueStepSequence.of(date(2018, 8, 12), date(2019, 8, 12), Frequency.P6M, ofDeltaAmount(-50_000))).build()); RateCalculationSwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(accrual).paymentSchedule(payment).notionalSchedule(notional).calculation(FixedRateCalculation.builder().dayCount(ACT_360).rate(ValueSchedule.builder().initialValue(0.0012).stepSequence(ValueStepSequence.of(date(2018, 8, 12), date(2019, 8, 12), Frequency.P6M, ofDeltaAmount(0.0001))).build()).build()).build(); RateCalculationSwapLeg recLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(accrual).paymentSchedule(payment).notionalSchedule(notional).calculation(IborRateCalculation.builder().index(IborIndices.GBP_LIBOR_3M).gearing(ValueSchedule.of(1.1)).spread(ValueSchedule.of(0.002)).build()).build(); Swap test = Swap.of(payLeg, recLeg); assertEquals(test.summaryDescription(), "2Y GBP 1mm variable Rec GBP-LIBOR-3M * 1.1 + 0.2% / Pay 0.12% variable : 12Feb18-12Feb20"); }
/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(IborCapFloorLeg beanToCopy) { this.payReceive_Renamed = beanToCopy.PayReceive; this.paymentSchedule_Renamed = beanToCopy.PaymentSchedule; this.paymentDateOffset_Renamed = beanToCopy.PaymentDateOffset; this.currency_Renamed = beanToCopy.Currency; this.notional_Renamed = beanToCopy.Notional; this.calculation_Renamed = beanToCopy.Calculation; this.capSchedule_Renamed = beanToCopy.capSchedule; this.floorSchedule_Renamed = beanToCopy.floorSchedule; }
private NotionalSchedule(Currency currency, FxResetCalculation fxReset, ValueSchedule amount, bool initialExchange, bool intermediateExchange, bool finalExchange) { JodaBeanUtils.notNull(currency, "currency"); JodaBeanUtils.notNull(amount, "amount"); this.currency = currency; this.fxReset = fxReset; this.amount = amount; this.initialExchange = initialExchange; this.intermediateExchange = intermediateExchange; this.finalExchange = finalExchange; validate(); }
private InflationRateCalculation(PriceIndex index, Period lag, PriceIndexCalculationMethod indexCalculationMethod, double?firstIndexValue, ValueSchedule gearing) { JodaBeanUtils.notNull(index, "index"); JodaBeanUtils.notNull(lag, "lag"); JodaBeanUtils.notNull(indexCalculationMethod, "indexCalculationMethod"); this.index = index; this.lag = lag; this.indexCalculationMethod = indexCalculationMethod; this.firstIndexValue = firstIndexValue; this.gearing = gearing; validate(); }
private KnownAmountSwapLeg(PayReceive payReceive, PeriodicSchedule accrualSchedule, PaymentSchedule paymentSchedule, ValueSchedule amount, Currency currency) { JodaBeanUtils.notNull(payReceive, "payReceive"); JodaBeanUtils.notNull(accrualSchedule, "accrualSchedule"); JodaBeanUtils.notNull(paymentSchedule, "paymentSchedule"); JodaBeanUtils.notNull(amount, "amount"); JodaBeanUtils.notNull(currency, "currency"); this.payReceive = payReceive; this.accrualSchedule = accrualSchedule; this.paymentSchedule = paymentSchedule; this.amount = amount; this.currency = currency; }
// Converts an FpML 'Schedule' to a {@code ValueSchedule}. private ValueSchedule parseSchedule(XmlElement scheduleEl, double initialValue, ValueStepSequence seq, FpmlDocument document) { IList <XmlElement> stepEls = scheduleEl.getChildren("step"); ImmutableList.Builder <ValueStep> stepBuilder = ImmutableList.builder(); foreach (XmlElement stepEl in stepEls) { LocalDate stepDate = document.parseDate(stepEl.getChild("stepDate")); double stepValue = document.parseDecimal(stepEl.getChild("stepValue")); stepBuilder.add(ValueStep.of(stepDate, ValueAdjustment.ofReplace(stepValue))); } return(ValueSchedule.builder().initialValue(initialValue).steps(stepBuilder.build()).stepSequence(seq).build()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ImmutableConstructor private IborCapFloorLeg(com.opengamma.strata.product.common.PayReceive payReceive, com.opengamma.strata.basics.schedule.PeriodicSchedule paymentSchedule, com.opengamma.strata.basics.date.DaysAdjustment paymentDateOffset, com.opengamma.strata.basics.currency.Currency currency, com.opengamma.strata.basics.value.ValueSchedule notional, com.opengamma.strata.product.swap.IborRateCalculation calculation, com.opengamma.strata.basics.value.ValueSchedule capSchedule, com.opengamma.strata.basics.value.ValueSchedule floorSchedule) private IborCapFloorLeg(PayReceive payReceive, PeriodicSchedule paymentSchedule, DaysAdjustment paymentDateOffset, Currency currency, ValueSchedule notional, IborRateCalculation calculation, ValueSchedule capSchedule, ValueSchedule floorSchedule) { this.payReceive = ArgChecker.notNull(payReceive, "payReceive"); this.paymentSchedule = ArgChecker.notNull(paymentSchedule, "paymentSchedule"); this.paymentDateOffset = ArgChecker.notNull(paymentDateOffset, "paymentDateOffset"); this.currency = currency != null ? currency : calculation.Index.Currency; this.notional = notional; this.calculation = ArgChecker.notNull(calculation, "calculation"); this.capSchedule = capSchedule; this.floorSchedule = floorSchedule; ArgChecker.isTrue(!this.PaymentSchedule.StubConvention.Present || this.PaymentSchedule.StubConvention.get().Equals(StubConvention.NONE), "Stub period is not allowed"); ArgChecker.isFalse(this.CapSchedule.Present == this.FloorSchedule.Present, "One of cap schedule and floor schedule should be empty"); ArgChecker.isTrue(this.Calculation.Index.Tenor.Period.Equals(this.PaymentSchedule.Frequency.Period), "Payment frequency period should be the same as index tenor period"); }
private OvernightRateCalculation(DayCount dayCount, OvernightIndex index, OvernightAccrualMethod accrualMethod, NegativeRateMethod negativeRateMethod, int rateCutOffDays, ValueSchedule gearing, ValueSchedule spread) { JodaBeanUtils.notNull(dayCount, "dayCount"); JodaBeanUtils.notNull(index, "index"); JodaBeanUtils.notNull(accrualMethod, "accrualMethod"); JodaBeanUtils.notNull(negativeRateMethod, "negativeRateMethod"); ArgChecker.notNegative(rateCutOffDays, "rateCutOffDays"); this.dayCount = dayCount; this.index = index; this.accrualMethod = accrualMethod; this.negativeRateMethod = negativeRateMethod; this.rateCutOffDays = rateCutOffDays; this.gearing = gearing; this.spread = spread; }
// the notional, with trailing space if present private string notional(SwapLeg leg) { if (leg is RateCalculationSwapLeg) { RateCalculationSwapLeg rcLeg = (RateCalculationSwapLeg)leg; NotionalSchedule notionalSchedule = rcLeg.NotionalSchedule; ValueSchedule amount = notionalSchedule.Amount; double notional = amount.InitialValue; string vary = amount.Steps.Count > 0 || amount.StepSequence.Present ? " variable" : ""; Currency currency = notionalSchedule.FxReset.map(fxr => fxr.ReferenceCurrency).orElse(rcLeg.Currency); return(SummarizerUtils.amount(currency, notional) + vary); } if (leg is RatePeriodSwapLeg) { RatePeriodSwapLeg rpLeg = (RatePeriodSwapLeg)leg; return(SummarizerUtils.amount(rpLeg.PaymentPeriods.get(0).NotionalAmount)); } return(""); }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case -885469925: // payReceive this.payReceive_Renamed = (PayReceive)newValue; break; case -1499086147: // paymentSchedule this.paymentSchedule_Renamed = (PeriodicSchedule)newValue; break; case -716438393: // paymentDateOffset this.paymentDateOffset_Renamed = (DaysAdjustment)newValue; break; case 575402001: // currency this.currency_Renamed = (Currency)newValue; break; case 1585636160: // notional this.notional_Renamed = (ValueSchedule)newValue; break; case -934682935: // calculation this.calculation_Renamed = (IborRateCalculation)newValue; break; case -596212599: // capSchedule this.capSchedule_Renamed = (ValueSchedule)newValue; break; case -1562227005: // floorSchedule this.floorSchedule_Renamed = (ValueSchedule)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
//------------------------------------------------------------------------- public virtual void test_AmortizingFixedVsLibor3mSwap() { ValueAdjustment stepReduction = ValueAdjustment.ofDeltaAmount(-3_000_000); IList <ValueStep> steps = new List <ValueStep>(); for (int i = 1; i < 28; i++) { steps.Add(ValueStep.of(i, stepReduction)); } ValueSchedule notionalSchedule = ValueSchedule.of(100_000_000, steps); SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(USD, notionalSchedule)).calculation(FixedRateCalculation.builder().dayCount(THIRTY_U_360).rate(ValueSchedule.of(0.016)).build()).build(); SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(USD, notionalSchedule)).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build(); ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(receiveLeg, payLeg)).build().resolve(REF_DATA); DiscountingSwapTradePricer pricer = swapPricer(); CurrencyAmount pv = pricer.presentValue(trade, provider()).getAmount(USD); assertEquals(pv.Amount, -1850080.2895532502, TOLERANCE_PV); }
// parses the swap internal Swap parseSwap(FpmlDocument document, XmlElement tradeEl, TradeInfoBuilder tradeInfoBuilder) { XmlElement swapEl = tradeEl.getChild("swap"); ImmutableList <XmlElement> legEls = swapEl.getChildren("swapStream"); ImmutableList.Builder <SwapLeg> legsBuilder = ImmutableList.builder(); foreach (XmlElement legEl in legEls) { // calculation XmlElement calcPeriodAmountEl = legEl.getChild("calculationPeriodAmount"); XmlElement calcEl = calcPeriodAmountEl.findChild("calculation").orElse(XmlElement.ofChildren("calculation", ImmutableList.of())); PeriodicSchedule accrualSchedule = parseSwapAccrualSchedule(legEl, document); PaymentSchedule paymentSchedule = parseSwapPaymentSchedule(legEl, calcEl, document); // known amount or rate calculation Optional <XmlElement> knownAmountOptEl = calcPeriodAmountEl.findChild("knownAmountSchedule"); if (knownAmountOptEl.Present) { XmlElement knownAmountEl = knownAmountOptEl.get(); document.validateNotPresent(legEl, "stubCalculationPeriodAmount"); document.validateNotPresent(legEl, "resetDates"); // pay/receive and counterparty PayReceive payReceive = document.parsePayerReceiver(legEl, tradeInfoBuilder); ValueSchedule amountSchedule = parseSchedule(knownAmountEl, document); // build legsBuilder.add(KnownAmountSwapLeg.builder().payReceive(payReceive).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).amount(amountSchedule).currency(document.parseCurrency(knownAmountEl.getChild("currency"))).build()); } else { document.validateNotPresent(calcEl, "fxLinkedNotionalSchedule"); document.validateNotPresent(calcEl, "futureValueNotional"); // pay/receive and counterparty PayReceive payReceive = document.parsePayerReceiver(legEl, tradeInfoBuilder); NotionalSchedule notionalSchedule = parseSwapNotionalSchedule(legEl, calcEl, document); RateCalculation calculation = parseSwapCalculation(legEl, calcEl, accrualSchedule, document); // build legsBuilder.add(RateCalculationSwapLeg.builder().payReceive(payReceive).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).notionalSchedule(notionalSchedule).calculation(calculation).build()); } } return(Swap.of(legsBuilder.build())); }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case 1905311443: // dayCount this.dayCount_Renamed = (DayCount)newValue; break; case 100346066: // index this.index_Renamed = (OvernightIndex)newValue; break; case -1335729296: // accrualMethod this.accrualMethod_Renamed = (OvernightAccrualMethod)newValue; break; case 1969081334: // negativeRateMethod this.negativeRateMethod_Renamed = (NegativeRateMethod)newValue; break; case -92095804: // rateCutOffDays this.rateCutOffDays_Renamed = (int?)newValue.Value; break; case -91774989: // gearing this.gearing_Renamed = (ValueSchedule)newValue; break; case -895684237: // spread this.spread_Renamed = (ValueSchedule)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
//----------------------------------------------------------------------- public virtual void fixedSwapLeg() { // a PeriodicSchedule generates a schedule of accrual periods // - interest is accrued every 3 months from 2014-02-12 to 2014-07-31 // - accrual period dates are adjusted "modified following" using the "GBLO" holiday calendar // - there will be a long initial stub // - the regular accrual period dates will be at the end-of-month PeriodicSchedule accrualSchedule = PeriodicSchedule.builder().startDate(LocalDate.of(2014, 2, 12)).endDate(LocalDate.of(2016, 7, 31)).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.GBLO)).frequency(Frequency.P3M).stubConvention(StubConvention.LONG_INITIAL).rollConvention(RollConventions.EOM).build(); // a PaymentSchedule generates a schedule of payment periods, based on the accrual schedule // - payments are every 6 months // - payments are 2 business days after the end of the period // - straight compounding is used (the payments are less frequent than the accrual, so compounding occurs) PaymentSchedule paymentSchedule = PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentRelativeTo(PaymentRelativeTo.PERIOD_END).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, HolidayCalendarIds.GBLO)).compoundingMethod(CompoundingMethod.STRAIGHT).build(); // a NotionalSchedule generates a schedule of notional amounts, based on the payment schedule // - in this simple case the notional is 1 million GBP and does not change NotionalSchedule notionalSchedule = NotionalSchedule.of(Currency.GBP, 1_000_000); // a RateCalculationSwapLeg can represent a fixed or floating swap leg // - a FixedRateCalculation is used to represent a fixed rate // - the "Act/Act ISDA" day count is used // - the rate starts at 0.8% and reduces to 0.7% RateCalculationSwapLeg swapLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).notionalSchedule(notionalSchedule).calculation(FixedRateCalculation.builder().dayCount(DayCounts.ACT_ACT_ISDA).rate(ValueSchedule.of(0.008, ValueStep.of(LocalDate.of(2015, 1, 31), ValueAdjustment.ofReplace(0.007)))).build()).build(); // a ResolvedSwapLeg has all the dates of the cash flows // it remains valid so long as the holiday calendar does not change ResolvedSwapLeg resolvedLeg = swapLeg.resolve(ReferenceData.standard()); Console.WriteLine("===== Fixed ====="); Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(swapLeg)); Console.WriteLine(); Console.WriteLine("===== Fixed resolved ====="); Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(resolvedLeg)); Console.WriteLine(); }
//------------------------------------------------------------------------- // inflation rate calculation private static RateCalculation parseInflationRateCalculation(CsvRow row, string leg, PriceIndex priceIndex, Currency currency) { InflationRateCalculation.Builder builder = InflationRateCalculation.builder(); // basics builder.index(priceIndex); builder.lag(parseInflationLag(findValue(row, leg, INFLATION_LAG_FIELD), currency)); builder.indexCalculationMethod(parseInflationMethod(findValue(row, leg, INFLATION_METHOD_FIELD), currency)); // optionals findValue(row, leg, INFLATION_FIRST_INDEX_VALUE_FIELD).map(s => LoaderUtils.parseDouble(s)).ifPresent(v => builder.firstIndexValue(v)); findValue(row, leg, GEARING_FIELD).map(s => LoaderUtils.parseDouble(s)).ifPresent(v => builder.gearing(ValueSchedule.of(v))); return(builder.build()); }
//------------------------------------------------------------------------- // overnight rate calculation private static RateCalculation parseOvernightRateCalculation(CsvRow row, string leg, OvernightIndex overnightIndex, OvernightAccrualMethod accrualMethod) { OvernightRateCalculation.Builder builder = OvernightRateCalculation.builder(); // basics builder.index(overnightIndex); builder.accrualMethod(findValue(row, leg, ACCRUAL_METHOD_FIELD).map(s => OvernightAccrualMethod.of(s)).orElse(accrualMethod)); // optionals findValue(row, leg, DAY_COUNT_FIELD).map(s => LoaderUtils.parseDayCount(s)).ifPresent(v => builder.dayCount(v)); findValue(row, leg, RATE_CUT_OFF_DAYS_FIELD).map(s => Convert.ToInt32(s)).ifPresent(v => builder.rateCutOffDays(v)); findValue(row, leg, NEGATIVE_RATE_METHOD_FIELD).map(s => NegativeRateMethod.of(s)).ifPresent(v => builder.negativeRateMethod(v)); findValue(row, leg, GEARING_FIELD).map(s => LoaderUtils.parseDouble(s)).ifPresent(v => builder.gearing(ValueSchedule.of(v))); findValue(row, leg, SPREAD_FIELD).map(s => LoaderUtils.parseDoublePercent(s)).ifPresent(v => builder.spread(ValueSchedule.of(v))); return(builder.build()); }