bankdeposit-20-bank-calendar.spp
bankdeposit/accrual/bankdeposit-20-bank-calendar.spp
Download original file · Bank deposit source contents
1domain bankdeposit;23// Business interest-unit quantization, the legacy product module A; dates supplied by shared calendar service.45Role InterestPeriod short normal {6BigDecimal(19, 2) amount;7BigDecimal(19, 2) unit;8int days;9}1011Role InterestProduct {12BigDecimal(19, 2) qualifiedAmount;13BigDecimal(19, 2) product;14}1516atomic check checkInterestPeriod(InterestPeriod) {17require(18normal.amount >= 0 && normal.unit > 0 && normal.days >= 0,19RejectionCode.INVALID_INTEREST_PERIOD20);21}2223atomic check checkBankDate(BankDate) {24require(start.encoded != null && start.encoded != 0, RejectionCode.EEC28);25require(start.encoded >= 10000101 && start.encoded <= 99991231, RejectionCode.EE374);26require(isGregorianDate(start.encoded), RejectionCode.EE374);27}2829atomic check checkBankDays(BankDate, PeriodEnd, InterestCalendar) {30require(start.epochDay <= end.epochDay, RejectionCode.E1175);31require(32interestCalendar.convention == "ACT"33|| interestCalendar.convention == "360365"34|| interestCalendar.convention == "360360",35RejectionCode.EEC2836);37}3839atomic calculate calculateInterestProduct(InterestPeriod, InterestProduct) {40interestProduct.qualifiedAmount = roundDown( normal.amount / normal.unit, 0 ) * normal.unit;41interestProduct.product = interestProduct.qualifiedAmount * normal.days;42}4344// the legacy product module A/the legacy date module function O: start included, end excluded.45// The shared Gregorian functions decode representation; business selects ACT or deposit 360-day policy.4647Role BankDate short start {48int encoded;49int year;50int month;51int day;52int epochDay;53}5455// The end of a period is a distinct participant from its start, so it is a role over BankDate.5657Role PeriodEnd short end;5859take BankDate as PeriodEnd;6061Role InterestCalendar {62String convention;63}6465atomic calculate decodeBankDate(BankDate) {66start.year = dateYear(start.encoded);67start.month = dateMonth(start.encoded);68start.day = dateDay(start.encoded);69start.epochDay = dateEpochDay(start.encoded);70}7172atomic calculate calculateBankDays(BankDate, PeriodEnd, InterestCalendar, InterestPeriod) {73if (interestCalendar.convention == "ACT") {74normal.days = end.epochDay - start.epochDay;75} else {76normal.days = 36077* (end.year78- start.year)79+ 3080* (end.month81- start.month)82+ min(end.day, 30)83- min(start.day, 30);84}85}