bankdeposit-30-agreement-product.spp
bankdeposit/accrual/bankdeposit-30-agreement-product.spp
Download original file · Bank deposit source contents
1domain bankdeposit;23// the legacy product module A: retain the five source slots, traversed 5 down to 1.4// Normal and agreement periods have already been clipped/decoded by calendar services.56Role AgreementBand {7int slot;8BigDecimal(19, 2) threshold;9BigDecimal(19, 2) product;10}1112Role AgreementPolicy {13String mode;14String currency;15boolean enabled;16}1718Role AgreementProduct {19BigDecimal(19, 2) normalProduct;20BigDecimal(19, 2) bandProduct;21BigDecimal(19, 2) remainingAmount;22int selectedSlot;23String appliedMode;24}2526atomic calculate calculateAgreementProduct(27InterestPeriod,28OverlapPeriod,29AgreementPolicy,30AgreementBand[],31AgreementProduct32) {33agreementProduct.normalProduct = roundDown(normal.amount / normal.unit, 0) * normal.unit * normal.days;34agreementProduct.bandProduct = 0;35agreementProduct.remainingAmount = normal.amount;36agreementProduct.selectedSlot = 0;37agreementProduct.appliedMode = agreementPolicy.mode;38if (agreementPolicy.mode != "1" && agreementPolicy.mode != "2") {39if (agreementPolicy.currency == "CNY") {40agreementProduct.appliedMode = "2";41} else {42agreementProduct.appliedMode = "1";43}44}45for (AgreementBand band : agreementBands) {46band.product = 0;47}48if (agreementPolicy.enabled && overlap.days > 0) {49for (AgreementBand band : agreementBands) {50if (agreementProduct.appliedMode == "2") {51if (agreementProduct.remainingAmount > band.threshold) {52band.product = roundDown(53(agreementProduct.remainingAmount - band.threshold) / normal.unit,54055) * normal.unit * overlap.days;56agreementProduct.bandProduct += band.product;57agreementProduct.remainingAmount = band.threshold;58if (band.slot == 1) {59agreementProduct.normalProduct -= roundDown(60(normal.amount - band.threshold) / normal.unit,61062) * normal.unit * overlap.days;63}64}65} else {66if (normal.amount >= band.threshold) {67band.product = roundDown(normal.amount / normal.unit, 0) * normal.unit * overlap.days;68agreementProduct.bandProduct = band.product;69agreementProduct.normalProduct -= band.product;70agreementProduct.selectedSlot = band.slot;71break;72}73}74}75}76}7778atomic check checkAgreementProductInput(InterestPeriod, OverlapPeriod, AgreementBand[]) {79require(normal.amount >= 0 && normal.unit > 0 && normal.days >= 0, RejectionCode.INVALID_INTEREST_PERIOD);80require(81overlap.amount == normal.amount82&& overlap.unit == normal.unit83&& overlap.days >= 084&& overlap.days <= normal.days,85RejectionCode.INVALID_AGREEMENT_PERIOD86);87int expectedSlot = 5;88for (AgreementBand band : agreementBands) {89require(band.slot == expectedSlot && band.threshold >= 0, RejectionCode.INVALID_AGREEMENT_BANDS);90expectedSlot--;91}92require(expectedSlot == 0, RejectionCode.INVALID_AGREEMENT_BANDS);93}9495readonly Scenario serial previewAgreementWindow(96BankDate,97PeriodEnd,98AgreementTerm,99OverlapStart,100OverlapEnd,101InterestPeriod,102OverlapPeriod,103AgreementPolicy104) {105prepareAgreementWindow(106start,107end,108agreementTerm,109clippedStart,110clippedEnd,111normal,112overlap,113agreementPolicy114);115}