// variable notional private static SwapTrade parseVariableNotional(SwapTrade trade, IList <CsvRow> variableRows) { // parse notionals ImmutableList.Builder <ValueStep> stepBuilder = ImmutableList.builder(); foreach (CsvRow row in variableRows) { LocalDate date = LoaderUtils.parseDate(row.getValue(START_DATE_FIELD)); row.findValue(NOTIONAL_FIELD).map(str => LoaderUtils.parseDouble(str)).ifPresent(notional => stepBuilder.add(ValueStep.of(date, ValueAdjustment.ofReplace(notional)))); } ImmutableList <ValueStep> varNotionals = stepBuilder.build(); if (varNotionals.Empty) { return(trade); } // adjust the trade, inserting the variable notionals ImmutableList.Builder <SwapLeg> legBuilder = ImmutableList.builder(); foreach (SwapLeg swapLeg in trade.Product.Legs) { RateCalculationSwapLeg leg = (RateCalculationSwapLeg)swapLeg; NotionalSchedule notionalSchedule = leg.NotionalSchedule.toBuilder().amount(ValueSchedule.of(leg.NotionalSchedule.Amount.InitialValue, varNotionals)).build(); legBuilder.add(leg.toBuilder().notionalSchedule(notionalSchedule).build()); } return(replaceLegs(trade, legBuilder.build())); }
static DiscountingCmsLegPricerTest() { NOTIONAL_STEPS.Add(ValueStep.of(1, ValueAdjustment.ofReplace(NOTIONAL_VALUE_1))); NOTIONAL_STEPS.Add(ValueStep.of(2, ValueAdjustment.ofReplace(NOTIONAL_VALUE_2))); NOTIONAL_STEPS.Add(ValueStep.of(3, ValueAdjustment.ofReplace(NOTIONAL_VALUE_3))); }
// 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())); }