Skip to content

Commit

Permalink
Merge pull request #25 from SolumXplain/xplain-rebase
Browse files Browse the repository at this point in the history
Xplain rebase
  • Loading branch information
ntaylorSolum authored Nov 18, 2024
2 parents 0a08438 + 69bcca7 commit ce4e88b
Show file tree
Hide file tree
Showing 161 changed files with 17,991 additions and 274 deletions.
27 changes: 25 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ executors:
JAVA_TOOL_OPTIONS: -XX:MaxRAM=3572m
MAVEN_OPTS: -Xmx1g

#----------------------------------------------------------------------------
jdk21:
docker:
- image: cimg/openjdk:21.0
working_directory: ~/repo
environment:
JAVA_TOOL_OPTIONS: -XX:MaxRAM=3572m
MAVEN_OPTS: -Xmx1g

#############################################################################
# reusable commands
Expand All @@ -45,9 +53,13 @@ commands:
- run:
name: Initializing Maven
command: |
mvn --version
mkdir -p ./.mvn
echo "-e -B -DtrimStackTrace=false --settings $( pwd )/.circleci/maven-settings.xml" > ./.mvn/maven.config
cat ./.mvn/maven.config
echo "-e" >> ./.mvn/maven.config
echo "-B" >> ./.mvn/maven.config
echo "-DtrimStackTrace=false" >> ./.mvn/maven.config
echo "--settings" >> ./.mvn/maven.config
echo "$( pwd )/.circleci/maven-settings.xml" >> ./.mvn/maven.config
mvn --version
#----------------------------------------------------------------------------
Expand Down Expand Up @@ -259,6 +271,15 @@ jobs:
- maven_install
- maven_test

build21:
executor: jdk21
steps:
- checkout
- with_maven:
actions:
- maven_install
- maven_test

#----------------------------------------------------------------------------
release:
executor: jdk8
Expand Down Expand Up @@ -314,6 +335,8 @@ workflows:
context: OG-OSS
- build17:
context: OG-OSS
- build21:
context: OG-OSS

#----------------------------------------------------------------------------
# release based on a tag
Expand Down
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ updates:
interval: weekly
time: "02:30"
open-pull-requests-limit: 20
rebase-strategy: "disabled"
reviewers:
- jodastephen
assignees:
Expand Down
7 changes: 5 additions & 2 deletions .github/mergify.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
queue_rules:
- name: default
conditions:
merge_conditions:
- "label=auto-merge"
- "check-success=build"
merge_method: squash

pull_request_rules:
- name: Auto-Merge
description: Merge branch once conditions pass
conditions:
- "label=auto-merge"
- "status-success=build"
Expand All @@ -14,9 +16,10 @@ pull_request_rules:
- "title~=^((?!(wip|WIP)).)*$"
actions:
queue:
method: squash
name: default

- name: Delete-Branch
description: Delete branch once PR merged
conditions:
- "merged"
actions:
Expand Down
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.opengamma.strata</groupId>
<artifactId>strata-examples</artifactId>
<version>2.12.22-xplain-6</version>
<version>2.12.45-xplain</version>
<packaging>jar</packaging>
<name>Strata-Examples</name>
<description>Example code to demonstrate use of Strata</description>
Expand Down
2 changes: 1 addition & 1 deletion modules/basics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.opengamma.strata</groupId>
<artifactId>strata-parent</artifactId>
<version>2.12.22-xplain-6</version>
<version>2.12.45-xplain</version>
<relativePath>..</relativePath>
</parent>
<artifactId>strata-basics</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ public boolean isNegative() {
* @return an amount based on this with the amount negated
*/
public CurrencyAmount negated() {
// Zero is treated as a special case to avoid creating -0.0 which produces surprising equality behaviour
return new CurrencyAmount(currency, amount == 0d ? 0d : -amount);
return new CurrencyAmount(currency, -amount);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,7 @@ private static void addHungarianSaturdays(List<LocalDate> holidays, Set<LocalDat
// dates of published fixings - https://twitter.com/Banxico
// http://www.banxico.org.mx/SieInternet/consultarDirectorioInternetAction.do?accion=consultarCuadro&idCuadro=CF111&locale=en
// http://www.gob.mx/cms/uploads/attachment/file/161094/calendario_vacaciones2016.pdf
// https://comunicacionsocial.diputados.gob.mx/index.php/boletines/la-camara-de-diputados-declaro-el-1-de-octubre-de-cada-seis-a-os-como-dia-de-descanso-obligatorio
static ImmutableHolidayCalendar generateMexicoCity() {
List<LocalDate> holidays = new ArrayList<>(2000);
for (int year = 1950; year <= 2099; year++) {
Expand All @@ -1186,6 +1187,10 @@ static ImmutableHolidayCalendar generateMexicoCity() {
holidays.add(date(year, 5, 1));
// independence
holidays.add(date(year, 9, 16));
// inaguration day - occurring once in every 6 years (2024, 2030, etc).
if (year >= 2024 && (year + 4) % 6 == 0) {
holidays.add(date(year, 10, 1));
}
// dead
holidays.add(date(year, 11, 2));
// revolution
Expand All @@ -1196,7 +1201,7 @@ static ImmutableHolidayCalendar generateMexicoCity() {
holidays.add(date(year, 12, 25));
}
removeSatSun(holidays);
return ImmutableHolidayCalendar.of(HolidayCalendarId.of("MXMC"), holidays, SATURDAY, SUNDAY);
return ImmutableHolidayCalendar.of(HolidayCalendarIds.MXMC, holidays, SATURDAY, SUNDAY);
}

// generate BRBD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentSkipListMap;

import org.joda.convert.FromString;
import org.joda.convert.ToString;
Expand All @@ -19,8 +19,9 @@
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.opengamma.strata.collect.ArgChecker;
import com.opengamma.strata.collect.MapStream;
import com.opengamma.strata.collect.io.PropertiesFile;
import com.opengamma.strata.collect.io.ResourceLocator;

Expand All @@ -41,15 +42,17 @@ public final class Country
/**
* Loads the ISO alpha-2 and alpha-3 country codes into a bidirectional map.
*/
private static final Supplier<ImmutableBiMap<String, String>> COUNTRY_CODES = Suppliers.memoize(() ->
ImmutableBiMap.copyOf(PropertiesFile.of(
ResourceLocator.ofClasspath(Country.class, "country.properties").getCharSource())
.getProperties().asMap()));
private static final Supplier<ImmutableBiMap<String, Country>> COUNTRY_CODES = Suppliers.memoize(() ->
ImmutableBiMap.copyOf(MapStream.of(PropertiesFile.of(
ResourceLocator.ofClasspath(Country.class, "country.properties").getCharSource())
.getProperties().asMap())
.mapValues(Country::of)
.toMap()));

/**
* A cache of instances.
*/
private static final ConcurrentMap<String, Country> CACHE = new ConcurrentHashMap<>();
private static final ConcurrentMap<String, Country> CACHE = new ConcurrentSkipListMap<>();
/**
* The matcher for the code.
*/
Expand Down Expand Up @@ -256,11 +259,12 @@ public final class Country
* <p>
* This contains all the countries that have been defined at the point
* that the method is called.
*
*
* @return an immutable set containing all registered countries
*/
public static Set<Country> getAvailableCountries() {
return ImmutableSet.copyOf(CACHE.values());
COUNTRY_CODES.get();
return ImmutableSortedSet.copyOf(CACHE.values());
}

//-------------------------------------------------------------------------
Expand Down Expand Up @@ -316,9 +320,8 @@ public static Country parse(String countryCode) {
* @throws IllegalArgumentException if the country code is invalid
*/
public static Country of3Char(String countryCode) {
ArgChecker.matches(CODE_MATCHER, 3, 3, countryCode, "countryCode", "[A-Z][A-Z]");
ArgChecker.matches(CODE_MATCHER, 3, 3, countryCode, "countryCode", "[A-Z][A-Z][A-Z]");
return Optional.ofNullable(COUNTRY_CODES.get().get(countryCode))
.map(alpha2Code -> of(alpha2Code.toUpperCase(Locale.ENGLISH)))
.orElseThrow(() -> new IllegalArgumentException("Unknown country code: " + countryCode));
}

Expand Down Expand Up @@ -359,8 +362,8 @@ public String getCode() {
* @throws IllegalArgumentException if the country is invalid
*/
public String getCode3Char() {
if (COUNTRY_CODES.get().containsValue(this.getCode())) {
return COUNTRY_CODES.get().inverse().get(this.getCode());
if (COUNTRY_CODES.get().containsValue(this)) {
return COUNTRY_CODES.get().inverse().get(this);
} else {
throw new IllegalArgumentException("Unknown country: " + this.getCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ public Schedule createSchedule(ReferenceData refData, boolean combinePeriodsIfNe
adj = new ArrayList<>(adj);
unadj = new ArrayList<>(unadj);
for (int i = 0; i < adj.size() - 1; i++) {
if (adj.get(i).equals(adj.get(i + 1))) {
while (i < adj.size() - 1 && adj.get(i).equals(adj.get(i + 1))) {
adj.remove(i);
unadj.remove(i);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,18 @@ private void validate() {
List<ValueStep> resolve(List<ValueStep> existingSteps, RollConvention rollConv) {
ImmutableList.Builder<ValueStep> steps = ImmutableList.builder();
steps.addAll(existingSteps);
LocalDate prev = firstStepDate;
LocalDate date = firstStepDate;
while (!date.isAfter(lastStepDate)) {
LocalDate prev = rollConv.adjust(firstStepDate);
LocalDate date = rollConv.adjust(firstStepDate);
LocalDate adjustedLastStepDate = rollConv.adjust(lastStepDate);
while (!date.isAfter(adjustedLastStepDate)) {
steps.add(ValueStep.of(date, adjustment));
prev = date;
date = rollConv.next(date, frequency);
}
if (!prev.equals(lastStepDate)) {
if (!prev.equals(adjustedLastStepDate)) {
throw new IllegalArgumentException(Messages.format(
"ValueStepSequence lastStepDate did not match frequency '{}' using roll convention '{}', {} != {}",
frequency, rollConv, lastStepDate, prev));
frequency, rollConv, adjustedLastStepDate, prev));
}
return steps.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@
2020=Jan01,Feb10,Apr06,Apr13,Apr14,Apr15,May01,May06,Jul06,Jul28,Aug12,Oct13,Oct23,Dec07,Dec10,Dec31
2021=Jan01,Feb26,Apr06,Apr13,Apr14,Apr15,May03,May26,Jul26,Jul28,Aug12,Oct13,Oct25,Dec06,Dec10,Dec31
2022=Jan03,Feb16,Apr06,Apr13,Apr14,Apr15,May02,May16,Jul13,Jul28,Aug12,Oct13,Oct24,Dec05,Dec12
2023=Jan02,Mar06,Apr06,Apr13,Apr14,May01,Jun05,Jul28,Aug01,Aug14,Oct13,Oct23,Dec05,Dec11
2024=Jan01,Jan02,Feb26,Apr08,Apr15,Apr16,May01,May22,Jul22,Jul29,Aug12,Oct14,Oct23,Dec05,Dec10,Dec31
2025=Jan01,Feb12,Apr07,Apr14,Apr15,May01,May12,Jul10,Jul28,Aug12,Oct13,Oct23,Dec05,Dec10,Dec31
2026=Jan01,Jan02,Mar03,Apr06,Apr13,Apr14,Apr15,May01,Jun01,Jul28,Jul29,Aug12,Oct13,Oct23,Dec07,Dec10,Dec31
2027=Jan01,Feb22,Apr06,Apr13,Apr14,Apr15,May03,May20,Jul19,Jul28,Aug12,Oct13,Oct25,Dec06,Dec10,Dec31
2028=Jan03,Feb10,Apr06,Apr13,Apr14,May01,May08,Jul06,Jul28,Aug14,Oct13,Oct23,Dec05,Dec11
2029=Jan01,Jan02,Feb27,Apr06,Apr13,Apr16,May01,May28,Jul25,Jul30,Aug13,Oct15,Oct23,Dec05,Dec10,Dec31
2030=Jan01,Feb18,Apr08,Apr15,Apr16,May01,May16,Jul15,Jul29,Aug12,Oct14,Oct23,Dec05,Dec10,Dec31
2031=Jan01,Mar07,Apr07,Apr14,Apr15,May01,Jun04,Jul28,Aug04,Aug12,Oct13,Oct23,Dec05,Dec10,Dec31
2032=Jan01,Jan02,Feb25,Apr06,Apr13,Apr14,Apr15,May03,May24,Jul22,Jul28,Aug12,Oct13,Oct25,Dec06,Dec10,Dec31
2033=Jan03,Feb14,Apr06,Apr13,Apr14,Apr15,May02,May13,Jul11,Jul28,Aug12,Oct13,Oct24,Dec05,Dec12
2023=Jan02,Mar06,Apr06,Apr13,Apr14,May01,May04,May05,Jun05,Jul28,Aug01,Aug14,Oct13,Oct23,Dec05,Dec11,Dec29
2024=Jan01,Jan02,Feb26,Apr08,Apr15,Apr16,May01,May06,May22,Jul22,Jul29,Aug12,Oct14,Oct23,Dec05,Dec10,Dec30,Dec31
2025=Jan01,Feb12,Apr07,Apr14,Apr15,May01,May05,May12,Jul10,Jul28,Aug12,Oct13,Oct23,Dec05,Dec10,Dec31
2026=Jan01,Jan02,Mar03,Apr06,Apr13,Apr14,Apr15,May01,May04,Jun01,Jul28,Jul29,Aug12,Oct13,Oct23,Dec07,Dec10,Dec31
2027=Jan01,Feb22,Apr06,Apr13,Apr14,Apr15,May03,May04,May20,Jul19,Jul28,Aug12,Oct13,Oct25,Dec06,Dec10,Dec31
2028=Jan03,Feb10,Apr06,Apr13,Apr14,May01,May04,May08,Jul06,Jul28,Aug14,Oct13,Oct23,Dec05,Dec11
2029=Jan01,Jan02,Feb27,Apr06,Apr13,Apr16,May01,May04,May28,Jul25,Jul30,Aug13,Oct15,Oct23,Dec05,Dec10,Dec31
2030=Jan01,Feb18,Apr08,Apr15,Apr16,May01,May06,May16,Jul15,Jul29,Aug12,Oct14,Oct23,Dec05,Dec10,Dec31
2031=Jan01,Mar07,Apr07,Apr14,Apr15,May01,May04,Jun04,Jul28,Aug04,Aug12,Oct13,Oct23,Dec05,Dec10,Dec31
2032=Jan01,Jan02,Feb25,Apr06,Apr13,Apr14,Apr15,May03,May04,May24,Jul22,Jul28,Aug12,Oct13,Oct25,Dec06,Dec10,Dec31
2033=Jan03,Feb14,Apr06,Apr13,Apr14,Apr15,May02,May04,May13,Jul11,Jul28,Aug12,Oct13,Oct24,Dec05,Dec12
2034=Jan02,Mar06,Apr06,Apr13,Apr14,May01,Jun01,Jul28,Jul31,Aug14,Oct13,Oct23,Dec05,Dec11
2035=Jan01,Jan02,Feb22,Apr06,Apr13,Apr16,May01,May21,Jul20,Jul30,Aug13,Oct15,Oct23,Dec05,Dec10,Dec31
2036=Jan01,Feb12,Apr07,Apr14,Apr15,May01,May12,Jul08,Jul28,Aug12,Oct13,Oct23,Dec05,Dec10,Dec31
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,8 @@ public static Object[][] data_mxmc() {
md(5, 1), md(9, 16), md(11, 2), md(11, 16), md(12, 12), md(12, 25))},
{2016, mds(2016, md(1, 1), md(2, 1), md(3, 21), md(3, 24), md(3, 25),
md(5, 1), md(9, 16), md(11, 2), md(11, 21), md(12, 12), md(12, 25))},
{2024, mds(2024, md(1, 1), md(2, 5), md(3, 18), md(3, 28), md(3, 29),
md(5, 1), md(9, 16), md(10, 1), md(11, 2), md(11, 18), md(12, 12), md(12, 25))},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ public void test_getAvailable() {
assertThat(available.contains(Country.CA)).isTrue();
}

@Test
public void test_new_Country_included_in_getAvailable() {
Set<Country> available = Country.getAvailableCountries();
assertThat(available.size()).isGreaterThan(0);
Country.of("XZ");
Set<Country> updatedAvailable = Country.getAvailableCountries();
assertThat(updatedAvailable.size() - available.size()).isEqualTo(1);
}

//-----------------------------------------------------------------------
@Test
public void test_of_String() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static com.opengamma.strata.basics.date.HolidayCalendarIds.NO_HOLIDAYS;
import static com.opengamma.strata.basics.date.HolidayCalendarIds.SAT_SUN;
import static com.opengamma.strata.basics.schedule.Frequency.P12M;
import static com.opengamma.strata.basics.schedule.Frequency.P1D;
import static com.opengamma.strata.basics.schedule.Frequency.P1M;
import static com.opengamma.strata.basics.schedule.Frequency.P1W;
import static com.opengamma.strata.basics.schedule.Frequency.P2M;
Expand Down Expand Up @@ -73,6 +74,7 @@
import com.opengamma.strata.basics.date.BusinessDayConvention;
import com.opengamma.strata.basics.date.HolidayCalendar;
import com.opengamma.strata.basics.date.HolidayCalendarId;
import com.opengamma.strata.basics.date.HolidayCalendarIds;
import com.opengamma.strata.basics.date.HolidayCalendars;

/**
Expand Down Expand Up @@ -1208,6 +1210,49 @@ public HolidayCalendarId getId() {
assertThat(schedule.getPeriod(2).getStartDate()).isEqualTo(date(2020, 10, 9));
}

@Test
public void test_combinePeriodsWhenNecessary_1d_createSchedule_duplicate_exception() {
HolidayCalendarId id = SAT_SUN;
HolidayCalendar calendar = HolidayCalendars.SAT_SUN;

ReferenceData referenceData = ImmutableReferenceData.of(id, calendar);
BusinessDayAdjustment businessDayAdjustment = BusinessDayAdjustment.of(MODIFIED_FOLLOWING, id);
PeriodicSchedule defn = PeriodicSchedule.builder()
.startDate(date(2020, 9, 18))
.endDate(date(2020, 12, 18))
.frequency(P1D)
.businessDayAdjustment(businessDayAdjustment)
.stubConvention(SHORT_FINAL)
.rollConvention(null)
.build();

Schedule schedule = defn.createSchedule(referenceData, true);
assertThat(schedule.getPeriods()).hasSize(65);
assertThat(schedule.getPeriod(0).getStartDate()).isEqualTo(date(2020, 9, 18));
assertThat(schedule.getPeriod(0).getEndDate()).isEqualTo(date(2020, 9, 21));
}

@Test
public void test_combinePeriodsWhenNecessary_1d_createSchedule() {
HolidayCalendarId id = SAT_SUN;
HolidayCalendar calendar = HolidayCalendars.SAT_SUN;

ReferenceData referenceData = ImmutableReferenceData.of(id, calendar);
BusinessDayAdjustment businessDayAdjustment = BusinessDayAdjustment.of(MODIFIED_FOLLOWING, id);
PeriodicSchedule defn = PeriodicSchedule.builder()
.startDate(date(2020, 9, 18))
.endDate(date(2020, 12, 18))
.frequency(P1D)
.businessDayAdjustment(businessDayAdjustment)
.stubConvention(SHORT_FINAL)
.rollConvention(null)
.build();

assertThatExceptionOfType(ScheduleException.class)
.isThrownBy(() -> defn.createSchedule(referenceData, false))
.withMessageMatching(".*duplicate adjusted dates.*");
}

@Test
public void test_emptyWhenAdjusted_twoPeriods_createUnadjustedDates() {
PeriodicSchedule defn = PeriodicSchedule.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ public void test_resolve() {
assertThat(steps.get(3)).isEqualTo(ValueStep.of(date(2016, 10, 20), ADJ));
}

@Test
public void test_resolve_with_roll_convention() {
ValueStepSequence test = ValueStepSequence.of(date(2022, 9, 21), date(2026, 9, 21), Frequency.P12M, ADJ);
List<ValueStep> steps = test.resolve(ImmutableList.of(), RollConventions.IMM);
assertThat(steps.size()).isEqualTo(5);
assertThat(steps.get(0)).isEqualTo(ValueStep.of(date(2022, 9, 21), ADJ));
assertThat(steps.get(1)).isEqualTo(ValueStep.of(date(2023, 9, 20), ADJ));
assertThat(steps.get(2)).isEqualTo(ValueStep.of(date(2024, 9, 18), ADJ));
assertThat(steps.get(3)).isEqualTo(ValueStep.of(date(2025, 9, 17), ADJ));
assertThat(steps.get(4)).isEqualTo(ValueStep.of(date(2026, 9, 16), ADJ));
}

@Test
public void test_resolve_invalid() {
ValueStepSequence test = ValueStepSequence.of(date(2016, 4, 20), date(2016, 10, 20), Frequency.P12M, ADJ);
Expand Down
Loading

0 comments on commit ce4e88b

Please sign in to comment.