Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Merge feature/AP-197-refactor-schedule-generation #34

Merged
merged 4 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion artifacts/ACTUSTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-12T10:18:18.352Z"
"updatedAt": "2019-12-12T14:54:18.525Z"
}
6 changes: 3 additions & 3 deletions artifacts/ANNEngine.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion artifacts/BaseEngine.json
Original file line number Diff line number Diff line change
Expand Up @@ -2066,5 +2066,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-12T10:18:18.404Z"
"updatedAt": "2019-12-12T14:54:18.633Z"
}
2 changes: 1 addition & 1 deletion artifacts/BokkyPooBahsDateTimeLibrary.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-10T15:52:56.912Z"
"updatedAt": "2019-12-12T14:54:18.847Z"
}
2 changes: 1 addition & 1 deletion artifacts/BusinessDayConvention.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-12T10:18:18.356Z"
"updatedAt": "2019-12-12T14:54:18.533Z"
}
2 changes: 1 addition & 1 deletion artifacts/CECEngine.json
Original file line number Diff line number Diff line change
Expand Up @@ -2066,5 +2066,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-12T10:18:18.409Z"
"updatedAt": "2019-12-12T14:54:18.640Z"
}
2 changes: 1 addition & 1 deletion artifacts/CEGEngine.json
Original file line number Diff line number Diff line change
Expand Up @@ -2066,5 +2066,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-12T10:18:18.416Z"
"updatedAt": "2019-12-12T14:54:18.656Z"
}
2 changes: 1 addition & 1 deletion artifacts/ContractDefaultConvention.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-12T10:18:18.359Z"
"updatedAt": "2019-12-12T14:54:18.539Z"
}
2 changes: 1 addition & 1 deletion artifacts/ContractRoleConvention.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-12T10:18:18.360Z"
"updatedAt": "2019-12-12T14:54:18.541Z"
}
2 changes: 1 addition & 1 deletion artifacts/Core.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,5 +368,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-12T10:18:18.371Z"
"updatedAt": "2019-12-12T14:54:18.564Z"
}
2 changes: 1 addition & 1 deletion artifacts/DayCountConvention.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-12T10:18:18.364Z"
"updatedAt": "2019-12-12T14:54:18.552Z"
}
2 changes: 1 addition & 1 deletion artifacts/EndOfMonthConvention.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-12T10:18:18.370Z"
"updatedAt": "2019-12-12T14:54:18.561Z"
}
2 changes: 1 addition & 1 deletion artifacts/IEngine.json
Original file line number Diff line number Diff line change
Expand Up @@ -1735,5 +1735,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-12T10:18:18.422Z"
"updatedAt": "2019-12-12T14:54:18.668Z"
}
2 changes: 1 addition & 1 deletion artifacts/Migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-10T15:52:56.898Z"
"updatedAt": "2019-12-12T14:54:18.826Z"
}
6 changes: 3 additions & 3 deletions artifacts/PAMEngine.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion artifacts/POF.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,5 +368,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-12T10:18:18.447Z"
"updatedAt": "2019-12-12T14:54:18.728Z"
}
2 changes: 1 addition & 1 deletion artifacts/STF.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,5 +368,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-12T10:18:18.478Z"
"updatedAt": "2019-12-12T14:54:18.776Z"
}
2 changes: 1 addition & 1 deletion artifacts/SafeMath.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-10T15:52:56.942Z"
"updatedAt": "2019-12-12T14:54:18.885Z"
}
2 changes: 1 addition & 1 deletion artifacts/Schedule.json
Original file line number Diff line number Diff line change
Expand Up @@ -323,5 +323,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-12T10:18:18.377Z"
"updatedAt": "2019-12-12T14:54:18.573Z"
}
2 changes: 1 addition & 1 deletion artifacts/SignedMath.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-10T15:52:56.780Z"
"updatedAt": "2019-12-12T14:54:18.581Z"
}
2 changes: 1 addition & 1 deletion artifacts/SignedSafeMath.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-10T15:52:56.939Z"
"updatedAt": "2019-12-12T14:54:18.882Z"
}
2 changes: 1 addition & 1 deletion artifacts/TestPOF.json
Original file line number Diff line number Diff line change
Expand Up @@ -3198,5 +3198,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-12T10:18:18.509Z"
"updatedAt": "2019-12-12T14:54:18.867Z"
}
2 changes: 1 addition & 1 deletion artifacts/TestSTF.json
Original file line number Diff line number Diff line change
Expand Up @@ -4749,5 +4749,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-12T10:18:18.515Z"
"updatedAt": "2019-12-12T14:54:18.875Z"
}
2 changes: 1 addition & 1 deletion artifacts/Utils.json
Original file line number Diff line number Diff line change
Expand Up @@ -323,5 +323,5 @@
"version": "0.5.2+commit.1df8f40c.Emscripten.clang"
},
"networks": {},
"updatedAt": "2019-12-12T10:18:18.382Z"
"updatedAt": "2019-12-12T14:54:18.588Z"
}
66 changes: 38 additions & 28 deletions contracts/Engines/ANNEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ contract ANNEngine is BaseEngine, STF, POF {
if (isInPeriod(terms.maturityDate, segmentStart, segmentEnd) == true) {
_eventSchedule[index] = encodeEvent(EventType.MD, terms.maturityDate);
index++;
_eventSchedule[index] = encodeEvent(EventType.IP, terms.maturityDate);
index++;
// _eventSchedule[index] = encodeEvent(EventType.IP, terms.maturityDate);
// index++;
}

return _eventSchedule;
Expand All @@ -122,46 +122,58 @@ contract ANNEngine is BaseEngine, STF, POF {
{
bytes32[MAX_EVENT_SCHEDULE_SIZE] memory _eventSchedule;

if (eventType == EventType.IP || eventType == EventType.IPCI) {
if (eventType == EventType.IP) {
uint256 index = 0;

// interest payment related (covers pre-repayment period only,
// starting with PRANX interest is paid following the PR schedule)
if (terms.cycleOfInterestPayment.isSet == true &&
terms.cycleAnchorDateOfInterestPayment != 0 &&
terms.cycleAnchorDateOfInterestPayment < terms.cycleAnchorDateOfPrincipalRedemption)
{
if (
terms.cycleOfInterestPayment.isSet == true
&& terms.cycleAnchorDateOfInterestPayment != 0
) {
uint256[MAX_CYCLE_SIZE] memory interestPaymentSchedule = computeDatesFromCycleSegment(
terms.cycleAnchorDateOfInterestPayment,
terms.cycleAnchorDateOfPrincipalRedemption, // pure IP schedule ends at beginning of combined IP/PR schedule
terms.maturityDate,
terms.cycleOfInterestPayment,
false, // do not create an event for cycleAnchorDateOfPrincipalRedemption as covered with the PR schedule
true,
segmentStart,
segmentEnd
);
for (uint8 i = 0; i < MAX_CYCLE_SIZE; i++) {
if (interestPaymentSchedule[i] == 0) break;
if (interestPaymentSchedule[i] <= terms.capitalizationEndDate) continue;
if (isInPeriod(interestPaymentSchedule[i], segmentStart, segmentEnd) == false) continue;
if (
terms.capitalizationEndDate != 0 &&
interestPaymentSchedule[i] <= terms.capitalizationEndDate
) {
if (interestPaymentSchedule[i] == terms.capitalizationEndDate) continue;
_eventSchedule[index] = encodeEvent(EventType.IPCI, interestPaymentSchedule[i]);
index++;
} else {
_eventSchedule[index] = encodeEvent(EventType.IP, interestPaymentSchedule[i]);
index++;
}
_eventSchedule[index] = encodeEvent(EventType.IP, interestPaymentSchedule[i]);
index++;
}
}
// capitalization end date
}

if (eventType == EventType.IPCI) {
uint256 index = 0;

// IPCI
if (
terms.capitalizationEndDate != 0 &&
terms.capitalizationEndDate < terms.cycleAnchorDateOfPrincipalRedemption
terms.cycleOfInterestPayment.isSet == true
&& terms.cycleAnchorDateOfInterestPayment != 0
&& terms.capitalizationEndDate != 0
&& terms.capitalizationEndDate < terms.cycleAnchorDateOfPrincipalRedemption
) {
if (isInPeriod(terms.capitalizationEndDate, segmentStart, segmentEnd)) {
_eventSchedule[index] = encodeEvent(EventType.IPCI, terms.capitalizationEndDate);
IPS memory cycleOfInterestCapitalization = terms.cycleOfInterestPayment;
cycleOfInterestCapitalization.s = S.SHORT;

uint256[MAX_CYCLE_SIZE] memory interestPaymentSchedule = computeDatesFromCycleSegment(
terms.cycleAnchorDateOfInterestPayment,
terms.capitalizationEndDate,
cycleOfInterestCapitalization,
true,
segmentStart,
segmentEnd
);
for (uint8 i = 0; i < MAX_CYCLE_SIZE; i++) {
if (interestPaymentSchedule[i] == 0) break;
if (isInPeriod(interestPaymentSchedule[i], segmentStart, segmentEnd) == false) continue;
_eventSchedule[index] = encodeEvent(EventType.IPCI, interestPaymentSchedule[i]);
index++;
}
}
Expand Down Expand Up @@ -192,7 +204,7 @@ contract ANNEngine is BaseEngine, STF, POF {
if (eventType == EventType.PR) {
uint256 index = 0;

// principal redemption related (covers also interest events post PRANX)
// principal redemption
uint256[MAX_CYCLE_SIZE] memory principalRedemptionSchedule = computeDatesFromCycleSegment(
terms.cycleAnchorDateOfPrincipalRedemption,
terms.maturityDate,
Expand All @@ -206,8 +218,6 @@ contract ANNEngine is BaseEngine, STF, POF {
if (isInPeriod(principalRedemptionSchedule[i], segmentStart, segmentEnd) == false) continue;
_eventSchedule[index] = encodeEvent(EventType.PR, principalRedemptionSchedule[i]);
index++;
_eventSchedule[index] = encodeEvent(EventType.IP, principalRedemptionSchedule[i]);
index++;
}
}

Expand Down
59 changes: 34 additions & 25 deletions contracts/Engines/PAMEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,14 @@ contract PAMEngine is BaseEngine, STF, POF {
{
bytes32[MAX_EVENT_SCHEDULE_SIZE] memory _eventSchedule;

if (eventType == EventType.IP || eventType == EventType.IPCI) {
if (eventType == EventType.IP) {
uint256 index = 0;

// interest payment related (e.g. for reoccurring interest payments)
if (terms.nominalInterestRate != 0 && (
terms.cycleOfInterestPayment.isSet == true && terms.cycleAnchorDateOfInterestPayment != 0)
// interest payment related (covers pre-repayment period only,
// starting with PRANX interest is paid following the PR schedule)
if (
terms.cycleOfInterestPayment.isSet == true
&& terms.cycleAnchorDateOfInterestPayment != 0
) {
uint256[MAX_CYCLE_SIZE] memory interestPaymentSchedule = computeDatesFromCycleSegment(
terms.cycleAnchorDateOfInterestPayment,
Expand All @@ -127,33 +129,40 @@ contract PAMEngine is BaseEngine, STF, POF {
segmentStart,
segmentEnd
);
if (terms.capitalizationEndDate != 0) {
if (isInPeriod(terms.capitalizationEndDate, segmentStart, segmentEnd)) {
_eventSchedule[index] = encodeEvent(EventType.IPCI, terms.capitalizationEndDate);
index++;
}
}
for (uint8 i = 0; i < MAX_CYCLE_SIZE; i++) {
if (interestPaymentSchedule[i] == 0) break;
if (interestPaymentSchedule[i] <= terms.capitalizationEndDate) continue;
if (isInPeriod(interestPaymentSchedule[i], segmentStart, segmentEnd) == false) continue;
if (
terms.capitalizationEndDate != 0 &&
interestPaymentSchedule[i] <= terms.capitalizationEndDate
) {
if (interestPaymentSchedule[i] == terms.capitalizationEndDate) continue;
_eventSchedule[index] = encodeEvent(EventType.IPCI, interestPaymentSchedule[i]);
index++;
} else {
_eventSchedule[index] = encodeEvent(EventType.IP, interestPaymentSchedule[i]);
index++;
}
_eventSchedule[index] = encodeEvent(EventType.IP, interestPaymentSchedule[i]);
index++;
}
}
}

if (eventType == EventType.IPCI) {
uint256 index = 0;

// IPCI
if (
terms.cycleOfInterestPayment.isSet == true
&& terms.cycleAnchorDateOfInterestPayment != 0
&& terms.capitalizationEndDate != 0
) {
IPS memory cycleOfInterestCapitalization = terms.cycleOfInterestPayment;
cycleOfInterestCapitalization.s = S.SHORT;

// capitalization end date
else if (terms.capitalizationEndDate != 0) {
if (isInPeriod(terms.capitalizationEndDate, segmentStart, segmentEnd)) {
_eventSchedule[index] = encodeEvent(EventType.IPCI, terms.capitalizationEndDate);
uint256[MAX_CYCLE_SIZE] memory interestPaymentSchedule = computeDatesFromCycleSegment(
terms.cycleAnchorDateOfInterestPayment,
terms.capitalizationEndDate,
cycleOfInterestCapitalization,
true,
segmentStart,
segmentEnd
);
for (uint8 i = 0; i < MAX_CYCLE_SIZE; i++) {
if (interestPaymentSchedule[i] == 0) break;
if (isInPeriod(interestPaymentSchedule[i], segmentStart, segmentEnd) == false) continue;
_eventSchedule[index] = encodeEvent(EventType.IPCI, interestPaymentSchedule[i]);
index++;
}
}
Expand Down
25 changes: 22 additions & 3 deletions test/Engines/ANN/TestANNEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,21 @@ const {
contract('ANNEngine', () => {

const computeEventScheduleSegment = async (terms, segmentStart, segmentEnd) => {
const generatingTerms = parseTermsToGeneratingTerms(terms);

// fix for new schedule generation
generatingTerms.cycleAnchorDateOfInterestPayment = generatingTerms.cycleAnchorDateOfPrincipalRedemption;
generatingTerms.cycleOfInterestPayment = generatingTerms.cycleOfPrincipalRedemption;

const _eventSchedule = [];

_eventSchedule.push(... await this.ANNEngineInstance.computeNonCyclicScheduleSegment(
terms,
generatingTerms,
segmentStart,
segmentEnd
));
_eventSchedule.push(... await this.ANNEngineInstance.computeCyclicScheduleSegment(
terms,
generatingTerms,
segmentStart,
segmentEnd,
4 // FP
Expand All @@ -30,14 +36,27 @@ contract('ANNEngine', () => {
terms,
segmentStart,
segmentEnd,
7 // IPCI
));
_eventSchedule.push(... await this.ANNEngineInstance.computeCyclicScheduleSegment(
generatingTerms,
segmentStart,
segmentEnd,
8 // IP
));
_eventSchedule.push(... await this.ANNEngineInstance.computeCyclicScheduleSegment(
terms,
generatingTerms,
segmentStart,
segmentEnd,
15 // PR
));
_eventSchedule.push(... await this.ANNEngineInstance.computeCyclicScheduleSegment(
generatingTerms,
segmentStart,
segmentEnd,
18 // RR
));


return sortEvents(removeNullEvents(_eventSchedule));
}
Expand Down
Loading