// Converts an FpML 'NonNegativeAmountSchedule' to a {@code ValueStepSequence}. private ValueStepSequence parseAmountSchedule(XmlElement scheduleEl, double initialValue, FpmlDocument document) { Frequency freq = document.parseFrequency(scheduleEl.getChild("stepFrequency")); LocalDate start = document.parseDate(scheduleEl.getChild("firstNotionalStepDate")); LocalDate end = document.parseDate(scheduleEl.getChild("lastNotionalStepDate")); Optional <XmlElement> amountElOpt = scheduleEl.findChild("notionalStepAmount"); if (amountElOpt.Present) { double amount = document.parseDecimal(amountElOpt.get()); return(ValueStepSequence.of(start, end, freq, ValueAdjustment.ofDeltaAmount(amount))); } double rate = document.parseDecimal(scheduleEl.getChild("notionalStepRate")); string relativeTo = scheduleEl.findChild("stepRelativeTo").map(el => el.Content).orElse("Previous"); if (relativeTo.Equals("Previous")) { return(ValueStepSequence.of(start, end, freq, ValueAdjustment.ofDeltaMultiplier(rate))); } else if (relativeTo.Equals("Initial")) { // data model does not support 'relative to initial' but can calculate amount here double amount = initialValue * rate; return(ValueStepSequence.of(start, end, freq, ValueAdjustment.ofDeltaAmount(amount))); } else { throw new FpmlParseException(Messages.format("Unknown 'stepRelativeTo' value '{}', expected 'Initial' or 'Previous'", relativeTo)); } }
public PaintShopSourceParams AdjustChannels(ValueAdjustment red, ValueAdjustment green, ValueAdjustment blue, ValueAdjustment alpha) { RedAdjustment = red; GreenAdjustment = green; BlueAdjustment = blue; AlphaAdjustment = alpha; return(this); }
static SabrExtrapolationReplicationCmsLegPricerTest() { FLOOR_STEPS.Add(ValueStep.of(1, ValueAdjustment.ofReplace(FLOOR_VALUE_1))); FLOOR_STEPS.Add(ValueStep.of(2, ValueAdjustment.ofReplace(FLOOR_VALUE_2))); FLOOR_STEPS.Add(ValueStep.of(3, ValueAdjustment.ofReplace(FLOOR_VALUE_3))); 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))); }
static IborCapFloorLegTest() { FLOOR_STEPS.Add(ValueStep.of(1, ValueAdjustment.ofReplace(STRIKES[1]))); FLOOR_STEPS.Add(ValueStep.of(2, ValueAdjustment.ofReplace(STRIKES[2]))); FLOOR_STEPS.Add(ValueStep.of(3, ValueAdjustment.ofReplace(STRIKES[3]))); NOTIONAL_STEPS.Add(ValueStep.of(1, ValueAdjustment.ofReplace(NOTIONALS[1]))); NOTIONAL_STEPS.Add(ValueStep.of(2, ValueAdjustment.ofReplace(NOTIONALS[2]))); NOTIONAL_STEPS.Add(ValueStep.of(3, ValueAdjustment.ofReplace(NOTIONALS[3]))); }
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); }
// 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()); }
//------------------------------------------------------------------------- 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); }
//----------------------------------------------------------------------- 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(); }
static CmsLegTest() { FLOOR_STEPS.Add(ValueStep.of(1, ValueAdjustment.ofReplace(0.02))); NOTIONAL_STEPS.Add(ValueStep.of(1, ValueAdjustment.ofReplace(1.2e6))); }
static CmsTradeCalculationFunctionTest() { 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))); }
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 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())); }
// 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())); }