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

Brl conventions #1828

Merged
merged 36 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a8e8898
Rebase back to just conventions for a code review purpose. Some clean…
r-weeks Oct 17, 2018
cc8c379
Updated test
r-weeks Oct 17, 2018
8742a99
Fixed Accrual type
r-weeks Oct 17, 2018
404045a
Forgot these conventions too.
r-weeks Oct 17, 2018
f3f0f11
New doc and names accrual methods. I think it's best to remove the en…
r-weeks Oct 18, 2018
7de5b87
Checkstyle
r-weeks Oct 18, 2018
d72944a
Code review changes and new naming convention.
r-weeks Oct 18, 2018
70bec67
Minor check style and space at end of class
r-weeks Oct 18, 2018
396881e
Fix test
r-weeks Oct 18, 2018
a169810
Much better name. Takes into account the daily compounding.
r-weeks Oct 19, 2018
09f331f
Refactor to allow Future Value notional.
r-weeks Oct 22, 2018
00ee503
Tests for future value notional and auto method
r-weeks Oct 23, 2018
112ef39
More tests.
r-weeks Oct 23, 2018
89bb2b4
checkstyle
r-weeks Oct 23, 2018
4b3ce85
joda beans reinitialised
r-weeks Oct 23, 2018
199db5b
Discussions with Mark suggest the following name convention.
r-weeks Oct 24, 2018
0926644
Name consistency.
r-weeks Oct 24, 2018
70726d1
lets put fvn in fixed raste calculation
r-weeks Oct 24, 2018
519be8b
got the new computation in place for the fixed side
r-weeks Oct 24, 2018
09449e4
modified fixed rate calculation test
r-weeks Oct 24, 2018
b905dc0
Checkstyles and more tests.
r-weeks Oct 24, 2018
3bbecb6
test for new computation
r-weeks Oct 24, 2018
a22002b
regenerate joda beans
r-weeks Oct 24, 2018
6ddba3c
Fixed rate swap convention now accepts a future value notional
r-weeks Oct 25, 2018
40d4ec4
Test for Fixed rate swap convention now accepts a future value notional
r-weeks Oct 25, 2018
9b70b25
checkstyle
r-weeks Oct 25, 2018
4bd7010
Merge with master
r-weeks Oct 25, 2018
b33a703
Update test
r-weeks Oct 25, 2018
d09244f
Enum for fixed accrual method
r-weeks Oct 25, 2018
9ab22fe
Updated Fixed rate swap leg convention so that it now create a future…
r-weeks Oct 26, 2018
2d2c50e
check style
r-weeks Oct 26, 2018
4dc7258
Brazilian swap changes
jodastephen Nov 2, 2018
e2131c3
Brazilian swap changes
jodastephen Nov 2, 2018
cf79bcd
Brazilian swap changes
jodastephen Nov 2, 2018
3df36b9
Code review changes
r-weeks Nov 9, 2018
704c384
Minor fixups
jodastephen Nov 9, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,329 @@
/*
* Copyright (C) 2018 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.strata.product.rate;

import java.io.Serializable;
import java.util.Map;
import java.util.NoSuchElementException;

import org.joda.beans.Bean;
import org.joda.beans.BeanBuilder;
import org.joda.beans.ImmutableBean;
import org.joda.beans.JodaBeanUtils;
import org.joda.beans.MetaBean;
import org.joda.beans.MetaProperty;
import org.joda.beans.gen.BeanDefinition;
import org.joda.beans.gen.ImmutableConstructor;
import org.joda.beans.gen.PropertyDefinition;
import org.joda.beans.impl.direct.DirectMetaBean;
import org.joda.beans.impl.direct.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;
import org.joda.beans.impl.direct.DirectPrivateBeanBuilder;

import com.google.common.collect.ImmutableSet;
import com.opengamma.strata.basics.index.Index;

/**
* Defines a known annual fixed rate of interest that follows overnight compounding.
* <p>
* An interest rate that is specified in the contract.
* This is typically used in the fixed legs of a Brazilian swap.
*/
@BeanDefinition(builderScope = "private")
public final class FixedOvernightCompoundedAnnualRateComputation
implements RateComputation, ImmutableBean, Serializable {

/**
* The fixed rate for overnight compounding.
* A 5% rate will be expressed as 0.05.
*/
@PropertyDefinition
private final double rate;
/**
* The accrual factor.
*/
@PropertyDefinition
private final double accrualFactor;
/**
* The calculated simple rate.
*/
private final double simpleRate; // not a property

//-------------------------------------------------------------------------
/**
* Obtains an instance from the rate and accrual factor.
*
* @param rate the fixed rate
* @param accrualFactor the accrual factor
* @return the fixed rate computation
*/
public static FixedOvernightCompoundedAnnualRateComputation of(double rate, double accrualFactor) {
return new FixedOvernightCompoundedAnnualRateComputation(rate, accrualFactor);
}

//-------------------------------------------------------------------------
@ImmutableConstructor
private FixedOvernightCompoundedAnnualRateComputation(double rate, double accrualFactor) {
this.rate = rate;
this.accrualFactor = accrualFactor;
this.simpleRate = (Math.pow(1 + rate, accrualFactor) - 1) / accrualFactor;
}

//-------------------------------------------------------------------------
/**
* Calculates the simple interest rate associated with the compounded rate.
*
* @return the simple rate
*/
public double getSimpleRate() {
return simpleRate;
}

//-------------------------------------------------------------------------
@Override
public void collectIndices(ImmutableSet.Builder<Index> builder) {
// no indices to add
}

//------------------------- AUTOGENERATED START -------------------------
/**
* The meta-bean for {@code FixedOvernightCompoundedAnnualRateComputation}.
* @return the meta-bean, not null
*/
public static FixedOvernightCompoundedAnnualRateComputation.Meta meta() {
return FixedOvernightCompoundedAnnualRateComputation.Meta.INSTANCE;
}

static {
MetaBean.register(FixedOvernightCompoundedAnnualRateComputation.Meta.INSTANCE);
}

/**
* The serialization version id.
*/
private static final long serialVersionUID = 1L;

@Override
public FixedOvernightCompoundedAnnualRateComputation.Meta metaBean() {
return FixedOvernightCompoundedAnnualRateComputation.Meta.INSTANCE;
}

//-----------------------------------------------------------------------
/**
* Gets the fixed rate for overnight compounding.
* A 5% rate will be expressed as 0.05.
* @return the value of the property
*/
public double getRate() {
return rate;
}

//-----------------------------------------------------------------------
/**
* Gets the accrual factor.
* @return the value of the property
*/
public double getAccrualFactor() {
return accrualFactor;
}

//-----------------------------------------------------------------------
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
FixedOvernightCompoundedAnnualRateComputation other = (FixedOvernightCompoundedAnnualRateComputation) obj;
return JodaBeanUtils.equal(rate, other.rate) &&
JodaBeanUtils.equal(accrualFactor, other.accrualFactor);
}
return false;
}

@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(rate);
hash = hash * 31 + JodaBeanUtils.hashCode(accrualFactor);
return hash;
}

@Override
public String toString() {
StringBuilder buf = new StringBuilder(96);
buf.append("FixedOvernightCompoundedAnnualRateComputation{");
buf.append("rate").append('=').append(rate).append(',').append(' ');
buf.append("accrualFactor").append('=').append(JodaBeanUtils.toString(accrualFactor));
buf.append('}');
return buf.toString();
}

//-----------------------------------------------------------------------
/**
* The meta-bean for {@code FixedOvernightCompoundedAnnualRateComputation}.
*/
public static final class Meta extends DirectMetaBean {
/**
* The singleton instance of the meta-bean.
*/
static final Meta INSTANCE = new Meta();

/**
* The meta-property for the {@code rate} property.
*/
private final MetaProperty<Double> rate = DirectMetaProperty.ofImmutable(
this, "rate", FixedOvernightCompoundedAnnualRateComputation.class, Double.TYPE);
/**
* The meta-property for the {@code accrualFactor} property.
*/
private final MetaProperty<Double> accrualFactor = DirectMetaProperty.ofImmutable(
this, "accrualFactor", FixedOvernightCompoundedAnnualRateComputation.class, Double.TYPE);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"rate",
"accrualFactor");

/**
* Restricted constructor.
*/
private Meta() {
}

@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case 3493088: // rate
return rate;
case -1540322338: // accrualFactor
return accrualFactor;
}
return super.metaPropertyGet(propertyName);
}

@Override
public BeanBuilder<? extends FixedOvernightCompoundedAnnualRateComputation> builder() {
return new FixedOvernightCompoundedAnnualRateComputation.Builder();
}

@Override
public Class<? extends FixedOvernightCompoundedAnnualRateComputation> beanType() {
return FixedOvernightCompoundedAnnualRateComputation.class;
}

@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return metaPropertyMap$;
}

//-----------------------------------------------------------------------
/**
* The meta-property for the {@code rate} property.
* @return the meta-property, not null
*/
public MetaProperty<Double> rate() {
return rate;
}

/**
* The meta-property for the {@code accrualFactor} property.
* @return the meta-property, not null
*/
public MetaProperty<Double> accrualFactor() {
return accrualFactor;
}

//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case 3493088: // rate
return ((FixedOvernightCompoundedAnnualRateComputation) bean).getRate();
case -1540322338: // accrualFactor
return ((FixedOvernightCompoundedAnnualRateComputation) bean).getAccrualFactor();
}
return super.propertyGet(bean, propertyName, quiet);
}

@Override
protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
metaProperty(propertyName);
if (quiet) {
return;
}
throw new UnsupportedOperationException("Property cannot be written: " + propertyName);
}

}

//-----------------------------------------------------------------------
/**
* The bean-builder for {@code FixedOvernightCompoundedAnnualRateComputation}.
*/
private static final class Builder extends DirectPrivateBeanBuilder<FixedOvernightCompoundedAnnualRateComputation> {

private double rate;
private double accrualFactor;

/**
* Restricted constructor.
*/
private Builder() {
}

//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case 3493088: // rate
return rate;
case -1540322338: // accrualFactor
return accrualFactor;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}

@Override
public Builder set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case 3493088: // rate
this.rate = (Double) newValue;
break;
case -1540322338: // accrualFactor
this.accrualFactor = (Double) newValue;
break;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
return this;
}

@Override
public FixedOvernightCompoundedAnnualRateComputation build() {
return new FixedOvernightCompoundedAnnualRateComputation(
rate,
accrualFactor);
}

//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(96);
buf.append("FixedOvernightCompoundedAnnualRateComputation.Builder{");
buf.append("rate").append('=').append(JodaBeanUtils.toString(rate)).append(',').append(' ');
buf.append("accrualFactor").append('=').append(JodaBeanUtils.toString(accrualFactor));
buf.append('}');
return buf.toString();
}

}

//-------------------------- AUTOGENERATED END --------------------------
}
Loading