Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply reset periods to IRS #2675

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,10 @@ public final class IborIndices {
*/
public static final IborIndex ZAR_JIBAR_12M = IborIndex.of("ZAR-JIBAR-12M");

/**
* 7 Days Repo in CFETS
*/
public static final IborIndex CNY_REPO_1W = IborIndex.of("CNY-REPO-1W");
//-------------------------------------------------------------------------
/**
* Restricted constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ CAD-CDOR-3M,CAD,TRUE,Act/365F,CATO,0,CATO,CATO,3M,ModifiedFollowing,10:15,Americ
CAD-CDOR-6M,CAD,FALSE,Act/365F,CATO,0,CATO,CATO,6M,ModifiedFollowing,10:15,America/Toronto,Act/365F
CAD-CDOR-12M,CAD,FALSE,Act/365F,CATO,0,CATO,CATO,12M,ModifiedFollowing,10:15,America/Toronto,Act/365F
,,,,,,,,,,,,
CNY-REPO-1W,CNY,TRUE,Act/365F,CNBE,0,CNBE,CNBE,1W,Following,11:30,Asia/Shanghai,Act/365F
CNY-REPO-1W,CNY,TRUE,Act/365F,CNBE,0,CNBE,CNBE,1W,NoAdjust,11:30,Asia/Shanghai,Act/365F
,,,,,,,,,,,,
CZK-PRIBOR-1W,CZK,TRUE,Act/360,CZPR,2,CZPR,CZPR,1W,Following,11:00,Europe/Prague,ACT/360
CZK-PRIBOR-2W,CZK,TRUE,Act/360,CZPR,2,CZPR,CZPR,2W,Following,11:00,Europe/Prague,ACT/360
Expand Down Expand Up @@ -304,4 +304,4 @@ ZAR-JIBAR-1M,ZAR,TRUE,Act/365F,ZAJO,0,ZAJO,ZAJO,1M,ModifiedFollowing,10:00,Afric
ZAR-JIBAR-3M,ZAR,TRUE,Act/365F,ZAJO,0,ZAJO,ZAJO,3M,ModifiedFollowing,10:00,Africa/Johannesburg,Act/365F
ZAR-JIBAR-6M,ZAR,TRUE,Act/365F,ZAJO,0,ZAJO,ZAJO,6M,ModifiedFollowing,10:00,Africa/Johannesburg,Act/365F
ZAR-JIBAR-9M,ZAR,FALSE,Act/365F,ZAJO,0,ZAJO,ZAJO,9M,ModifiedFollowing,10:00,Africa/Johannesburg,Act/365F
ZAR-JIBAR-12M,ZAR,TRUE,Act/365F,ZAJO,0,ZAJO,ZAJO,12M,ModifiedFollowing,10:00,Africa/Johannesburg,Act/365F
ZAR-JIBAR-12M,ZAR,TRUE,Act/365F,ZAJO,0,ZAJO,ZAJO,12M,ModifiedFollowing,10:00,Africa/Johannesburg,Act/365F
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (C) 2018 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.strata.pricer.impl.rate;

import java.time.LocalDate;

import com.opengamma.strata.market.explain.ExplainKey;
import com.opengamma.strata.market.explain.ExplainMapBuilder;
import com.opengamma.strata.market.sensitivity.PointSensitivityBuilder;
import com.opengamma.strata.pricer.rate.IborIndexRates;
import com.opengamma.strata.pricer.rate.RateComputationFn;
import com.opengamma.strata.pricer.rate.RatesProvider;
import com.opengamma.strata.product.rate.IborAveragedFixing;
import com.opengamma.strata.product.rate.IborAveragedRateComputation;

/**
* Rate computation implementation for Cfets convention, in which a rate is based on the compounding of multiple fixings of a
* single Ibor floating rate index.
* <p>
* The rate computation queries the rates from the {@code RatesProvider} and weighted-average them.
* There is no convexity adjustment computed in this implementation.
*/
public class CfetsForwardIborAveragedRateComputationFn
implements RateComputationFn<IborAveragedRateComputation> {

/**
* Default instance.
*/
public static final CfetsForwardIborAveragedRateComputationFn DEFAULT = new CfetsForwardIborAveragedRateComputationFn();
@Override
public double rate(IborAveragedRateComputation computation, LocalDate startDate, LocalDate endDate,
RatesProvider provider) {
IborIndexRates rates = provider.iborIndexRates(computation.getIndex());

// take (rate * weight) for each fixing and divide by total weight
double fv = computation.getFixings().stream()
.mapToDouble(fixing -> futureValue(fixing, rates))
.reduce(1, (left, right) -> left * right);
return (fv - 1) / computation.getTotalWeight();
}

// Compute the rate adjusted by the weight for one IborAverageFixing.
private double futureValue(IborAveragedFixing fixing, IborIndexRates rates) {
double rate = fixing.getFixedRate().orElse(rates.rate(fixing.getObservation()));
return 1 + rate * fixing.getWeight();
}

@Override
public PointSensitivityBuilder rateSensitivity(
IborAveragedRateComputation computation,
LocalDate startDate,
LocalDate endDate,
RatesProvider provider) {

IborIndexRates rates = provider.iborIndexRates(computation.getIndex());

// combine the weighted sensitivity to each fixing
// omit fixed rates as they have no sensitivity to a curve
return computation.getFixings().stream()
.filter(fixing -> !fixing.getFixedRate().isPresent())
.map(fixing -> weightedSensitivity(fixing, computation.getTotalWeight(), rates))
.reduce(PointSensitivityBuilder.none(), PointSensitivityBuilder::combinedWith);
}

// Compute the weighted sensitivity for one IborAverageFixing.
private PointSensitivityBuilder weightedSensitivity(
IborAveragedFixing fixing,
double totalWeight,
IborIndexRates rates) {

return rates.ratePointSensitivity(fixing.getObservation())
.multipliedBy(fixing.getWeight() / totalWeight);
}

@Override
public double explainRate(IborAveragedRateComputation computation, LocalDate startDate, LocalDate endDate,
RatesProvider provider, ExplainMapBuilder builder) {
IborIndexRates rates = provider.iborIndexRates(computation.getIndex());
for (IborAveragedFixing fixing : computation.getFixings()) {
rates.explainRate(fixing.getObservation(), builder, child -> child.put(ExplainKey.WEIGHT, fixing.getWeight()));
}
double rate = rate(computation, startDate, endDate, provider);
builder.put(ExplainKey.COMBINED_RATE, rate);
return rate;
}
}
Loading