S++Core systems, human-reviewable
DEMO SOURCE · SPP / APP / PHYRead the book

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 {6    BigDecimal(19, 2) amount;7    BigDecimal(19, 2) unit;8    int days;9}1011Role InterestProduct {12    BigDecimal(19, 2) qualifiedAmount;13    BigDecimal(19, 2) product;14}1516atomic check checkInterestPeriod(InterestPeriod) {17    require(18        normal.amount >= 0 && normal.unit > 0 && normal.days >= 0,19        RejectionCode.INVALID_INTEREST_PERIOD20    );21}2223atomic check checkBankDate(BankDate) {24    require(start.encoded != null && start.encoded != 0, RejectionCode.EEC28);25    require(start.encoded >= 10000101 && start.encoded <= 99991231, RejectionCode.EE374);26    require(isGregorianDate(start.encoded), RejectionCode.EE374);27}2829atomic check checkBankDays(BankDate, PeriodEnd, InterestCalendar) {30    require(start.epochDay <= end.epochDay, RejectionCode.E1175);31    require(32        interestCalendar.convention == "ACT"33            || interestCalendar.convention == "360365"34            || interestCalendar.convention == "360360",35        RejectionCode.EEC2836    );37}3839atomic calculate calculateInterestProduct(InterestPeriod, InterestProduct) {40    interestProduct.qualifiedAmount = roundDown( normal.amount / normal.unit, 0 ) * normal.unit;41    interestProduct.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 {48    int encoded;49    int year;50    int month;51    int day;52    int 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 {62    String convention;63}6465atomic calculate decodeBankDate(BankDate) {66    start.year = dateYear(start.encoded);67    start.month = dateMonth(start.encoded);68    start.day = dateDay(start.encoded);69    start.epochDay = dateEpochDay(start.encoded);70}7172atomic calculate calculateBankDays(BankDate, PeriodEnd, InterestCalendar, InterestPeriod) {73    if (interestCalendar.convention == "ACT") {74        normal.days = end.epochDay - start.epochDay;75    } else {76        normal.days = 36077            * (end.year78            - start.year)79            + 3080            * (end.month81            - start.month)82            + min(end.day, 30)83            - min(start.day, 30);84    }85}