SAS - 计算未来利息和贷款摊销付款的现值
SAS - Calculating the present value of future interest and amortization payments of loans
我想计算数据集中贷款的未来利息和摊销付款(固定摊销和年金)的现值 (PV)。折扣率应该是 inflation 例如2%。我在 SAS 中看到了 finance 函数,但它需要每个现金流,由于数据集的性质,这很困难。
例如如果您借 100,000 100 个月(固定摊销),您将每月偿还(摊销)1,000。但由于 inflation(例如 2%),100 个月的还款与 1 个月的实际还款不同。利息成本也是如此。
最后,我希望在我的数据集之后有列显示所有未来利息和摊销付款的现值。
如果可能的话,我希望在数据步骤中得到解决方案。
我的数据集示例
data have;
call streaminit(12345);
do i = 1 to 5;
loanAmount = abs(rand("normal", 300E3, 200E3));
interestRateNominalAnnual = abs(rand('normal',0.05,0.05));
maturityMonth = abs(rand("normal", 120, 24));
output;
end;
format loanAmount comma10. interestRateNominalAnnual 5.2 maturityMonth 3.0;
run;
想要
loanAmount
interestRateNominalAnnual
maturityMonth
PV interest
PV Amortization
352,847
0.10
140
189,445
0.13
90
271,693
0.10
122
545,052
0.04
127
70,121
0.03
109
options cmplib=work.ORBA;
proc fcmp outlib=work.ORBA.pv; * Present value;
subroutine pvLoan( /* input */
loanAmount,
maturityMonth,
interestRateAnnual,
inflationAnnual,
/* output */
amortizationSumAnnuity,
interestSumAnnuity,
invoiceSumAnnuity,
amortizationSumFlat,
interestSumFlat,
invoiceSumFlat,
pvAmortizationSumAnnuity,
pvInterestSumAnnuity,
pvInvoiceSumAnnuity,
pvAmortizationSumFlat,
pvInterestSumFlat,
pvInvoiceSumFlat);
outargs amortizationSumAnnuity, interestSumAnnuity, invoiceSumAnnuity,
amortizationSumFlat, interestSumFlat, invoiceSumFlat,
pvAmortizationSumAnnuity, pvInterestSumAnnuity, pvInvoiceSumAnnuity,
pvAmortizationSumFlat, pvInterestSumFlat, pvInvoiceSumFlat;
if missing(loanAmount) or missing(maturityMonth) or missing(interestRateAnnual) then
do;
pvAmortizationSumAnnuity = .;
pvInterestSumAnnuity = .;
pvInvoiceSumAnnuity = .;
pvAmortizationSumFlat = .;
pvInterestSumFlat = .;
pvInvoiceSumFlat = .;
end;
else
do;
inflationMonth = sum(exp((log(sum(1,inflationAnnual)))/12),-1);
do maturityPeriod = 1 to maturityMonth;
* ------------------------------------------------------------------------------------------;
* ANNUITY;
* ------------------------------------------------------------------------------------------;
fv = 0; * Specifies the future value after the last payment is made;
paymentDueDate = 0; * Specifies whether the payments occur at the beginning or end of a period. 0 represents the end-of-period payments;
* NOMINAL VALUE;
* If the interest rate is zero you only amortize. Equal to flat amortization;
if interestRateAnnual = 0 then
do;
amortizationAnnuity = loanAmount / maturityMonth;
interestPaymentAnnuity = 0;
invoiceAnnuity = sum(amortizationAnnuity, interestPaymentAnnuity);
end;
else
do;
amortizationAnnuity = abs(finance('ppmt', interestRateAnnual/12, maturityPeriod, maturityMonth, loanAmount, paymentDueDate));
invoiceAnnuity = abs(finance('pmt', interestRateAnnual/12, maturityMonth, loanAmount, fv, paymentDueDate));
interestPaymentAnnuity = abs(sum(invoiceAnnuity, - amortizationAnnuity));
end;
* Cumulative nominal flat amortization;
amortizationSumAnnuity = sum(amortizationSumAnnuity, amortizationAnnuity);
interestSumAnnuity = sum(interestSumAnnuity, interestPaymentAnnuity);
invoiceSumAnnuity = sum(amortizationSumAnnuity, interestSumAnnuity);
* PRESENT VALUE;
* Present value of the interest and amortization for a annuity;
pvAmortizationAnnuity = amortizationAnnuity / ((1+inflationMonth)**maturityPeriod);
pvInterestAnnuity = interestPaymentAnnuity / ((1+inflationMonth)**maturityPeriod);
pvInvoiceAnnuity = sum(pvAmortizationAnnuity, pvInterestAnnuity);
* Cumulative present value annuity;
pvAmortizationSumAnnuity = sum(pvAmortizationSumAnnuity, pvAmortizationAnnuity);
pvInterestSumAnnuity = sum(pvInterestSumAnnuity, pvInterestAnnuity);
pvInvoiceSumAnnuity = sum(pvAmortizationSumAnnuity, pvInterestSumAnnuity);
* ------------------------------------------------------------------------------------------;
* FLAT AMORTIZATION;
* ------------------------------------------------------------------------------------------;
* NOMINAL VALUE;
* Payment in period n;
amortizationFlat = loanAmount / maturityMonth;
interestPaymentFlat = (sum(loanAmount, -amortizationFlat*(maturityPeriod-1)) * interestRateAnnual/12);
invoiceFlat = sum(amortizationFlat, interestPaymentFlat);
* Cumulative nominal flat amortization;
amortizationSumFlat = sum(amortizationSumFlat, amortizationFlat);
interestSumFlat = sum(interestSumFlat, interestPaymentFlat);
invoiceSumFlat = sum(amortizationSumFlat, interestSumFlat);
* PRESENT VALUE;
* Present value of the interest and amortization for flat amortization;
pvAmortizationFlat = amortizationFlat / ((1+inflationMonth)**maturityPeriod);
pvInterestFlat = interestPaymentFlat / ((1+inflationMonth)**maturityPeriod);
pvInvoiceFlat = sum(pvAmortizationFlat, pvInterestFlat);
* Cumulative present value flat amortization;
pvAmortizationSumFlat = sum(pvAmortizationSumFlat, pvAmortizationFlat);
pvInterestSumFlat = sum(pvInterestSumFlat, pvInterestFlat);
pvInvoiceSumFlat = sum(pvAmortizationSumFlat, pvInterestSumFlat);
end;
end;
endsub;
run;
data have;
call streaminit(12345);
do i = 1 to 5;
loanAmount = abs(floor(rand("normal", 300E3, 200E3)));
maturityMonth = abs(floor(rand("normal", 120, 24)));
interestRateAnnual = abs(rand('normal',0.05,0.05));
output;
end;
format loanAmount maturityMonth comma10. interestRateAnnual percent10.2;
drop i;
run;
data want;
set have;
* Call the subroutine and performe the calculations;
call pvLoan( /* input */
loanAmount,
maturityMonth,
interestRateAnnual,
0.02,
/* output */
amortizationSumAnnuity,
interestSumAnnuity,
invoiceSumAnnuity,
amortizationSumFlat,
interestSumFlat,
invoiceSumFlat,
pvAmortizationSumAnnuity,
pvInterestSumAnnuity,
pvInvoiceSumAnnuity,
pvAmortizationSumFlat,
pvInterestSumFlat,
pvInvoiceSumFlat);
format _numeric_ comma20. interestRateAnnual percent5.2;
run;
我想计算数据集中贷款的未来利息和摊销付款(固定摊销和年金)的现值 (PV)。折扣率应该是 inflation 例如2%。我在 SAS 中看到了 finance 函数,但它需要每个现金流,由于数据集的性质,这很困难。
例如如果您借 100,000 100 个月(固定摊销),您将每月偿还(摊销)1,000。但由于 inflation(例如 2%),100 个月的还款与 1 个月的实际还款不同。利息成本也是如此。
最后,我希望在我的数据集之后有列显示所有未来利息和摊销付款的现值。
如果可能的话,我希望在数据步骤中得到解决方案。
我的数据集示例
data have;
call streaminit(12345);
do i = 1 to 5;
loanAmount = abs(rand("normal", 300E3, 200E3));
interestRateNominalAnnual = abs(rand('normal',0.05,0.05));
maturityMonth = abs(rand("normal", 120, 24));
output;
end;
format loanAmount comma10. interestRateNominalAnnual 5.2 maturityMonth 3.0;
run;
想要
loanAmount | interestRateNominalAnnual | maturityMonth | PV interest | PV Amortization |
---|---|---|---|---|
352,847 | 0.10 | 140 | ||
189,445 | 0.13 | 90 | ||
271,693 | 0.10 | 122 | ||
545,052 | 0.04 | 127 | ||
70,121 | 0.03 | 109 |
options cmplib=work.ORBA;
proc fcmp outlib=work.ORBA.pv; * Present value;
subroutine pvLoan( /* input */
loanAmount,
maturityMonth,
interestRateAnnual,
inflationAnnual,
/* output */
amortizationSumAnnuity,
interestSumAnnuity,
invoiceSumAnnuity,
amortizationSumFlat,
interestSumFlat,
invoiceSumFlat,
pvAmortizationSumAnnuity,
pvInterestSumAnnuity,
pvInvoiceSumAnnuity,
pvAmortizationSumFlat,
pvInterestSumFlat,
pvInvoiceSumFlat);
outargs amortizationSumAnnuity, interestSumAnnuity, invoiceSumAnnuity,
amortizationSumFlat, interestSumFlat, invoiceSumFlat,
pvAmortizationSumAnnuity, pvInterestSumAnnuity, pvInvoiceSumAnnuity,
pvAmortizationSumFlat, pvInterestSumFlat, pvInvoiceSumFlat;
if missing(loanAmount) or missing(maturityMonth) or missing(interestRateAnnual) then
do;
pvAmortizationSumAnnuity = .;
pvInterestSumAnnuity = .;
pvInvoiceSumAnnuity = .;
pvAmortizationSumFlat = .;
pvInterestSumFlat = .;
pvInvoiceSumFlat = .;
end;
else
do;
inflationMonth = sum(exp((log(sum(1,inflationAnnual)))/12),-1);
do maturityPeriod = 1 to maturityMonth;
* ------------------------------------------------------------------------------------------;
* ANNUITY;
* ------------------------------------------------------------------------------------------;
fv = 0; * Specifies the future value after the last payment is made;
paymentDueDate = 0; * Specifies whether the payments occur at the beginning or end of a period. 0 represents the end-of-period payments;
* NOMINAL VALUE;
* If the interest rate is zero you only amortize. Equal to flat amortization;
if interestRateAnnual = 0 then
do;
amortizationAnnuity = loanAmount / maturityMonth;
interestPaymentAnnuity = 0;
invoiceAnnuity = sum(amortizationAnnuity, interestPaymentAnnuity);
end;
else
do;
amortizationAnnuity = abs(finance('ppmt', interestRateAnnual/12, maturityPeriod, maturityMonth, loanAmount, paymentDueDate));
invoiceAnnuity = abs(finance('pmt', interestRateAnnual/12, maturityMonth, loanAmount, fv, paymentDueDate));
interestPaymentAnnuity = abs(sum(invoiceAnnuity, - amortizationAnnuity));
end;
* Cumulative nominal flat amortization;
amortizationSumAnnuity = sum(amortizationSumAnnuity, amortizationAnnuity);
interestSumAnnuity = sum(interestSumAnnuity, interestPaymentAnnuity);
invoiceSumAnnuity = sum(amortizationSumAnnuity, interestSumAnnuity);
* PRESENT VALUE;
* Present value of the interest and amortization for a annuity;
pvAmortizationAnnuity = amortizationAnnuity / ((1+inflationMonth)**maturityPeriod);
pvInterestAnnuity = interestPaymentAnnuity / ((1+inflationMonth)**maturityPeriod);
pvInvoiceAnnuity = sum(pvAmortizationAnnuity, pvInterestAnnuity);
* Cumulative present value annuity;
pvAmortizationSumAnnuity = sum(pvAmortizationSumAnnuity, pvAmortizationAnnuity);
pvInterestSumAnnuity = sum(pvInterestSumAnnuity, pvInterestAnnuity);
pvInvoiceSumAnnuity = sum(pvAmortizationSumAnnuity, pvInterestSumAnnuity);
* ------------------------------------------------------------------------------------------;
* FLAT AMORTIZATION;
* ------------------------------------------------------------------------------------------;
* NOMINAL VALUE;
* Payment in period n;
amortizationFlat = loanAmount / maturityMonth;
interestPaymentFlat = (sum(loanAmount, -amortizationFlat*(maturityPeriod-1)) * interestRateAnnual/12);
invoiceFlat = sum(amortizationFlat, interestPaymentFlat);
* Cumulative nominal flat amortization;
amortizationSumFlat = sum(amortizationSumFlat, amortizationFlat);
interestSumFlat = sum(interestSumFlat, interestPaymentFlat);
invoiceSumFlat = sum(amortizationSumFlat, interestSumFlat);
* PRESENT VALUE;
* Present value of the interest and amortization for flat amortization;
pvAmortizationFlat = amortizationFlat / ((1+inflationMonth)**maturityPeriod);
pvInterestFlat = interestPaymentFlat / ((1+inflationMonth)**maturityPeriod);
pvInvoiceFlat = sum(pvAmortizationFlat, pvInterestFlat);
* Cumulative present value flat amortization;
pvAmortizationSumFlat = sum(pvAmortizationSumFlat, pvAmortizationFlat);
pvInterestSumFlat = sum(pvInterestSumFlat, pvInterestFlat);
pvInvoiceSumFlat = sum(pvAmortizationSumFlat, pvInterestSumFlat);
end;
end;
endsub;
run;
data have;
call streaminit(12345);
do i = 1 to 5;
loanAmount = abs(floor(rand("normal", 300E3, 200E3)));
maturityMonth = abs(floor(rand("normal", 120, 24)));
interestRateAnnual = abs(rand('normal',0.05,0.05));
output;
end;
format loanAmount maturityMonth comma10. interestRateAnnual percent10.2;
drop i;
run;
data want;
set have;
* Call the subroutine and performe the calculations;
call pvLoan( /* input */
loanAmount,
maturityMonth,
interestRateAnnual,
0.02,
/* output */
amortizationSumAnnuity,
interestSumAnnuity,
invoiceSumAnnuity,
amortizationSumFlat,
interestSumFlat,
invoiceSumFlat,
pvAmortizationSumAnnuity,
pvInterestSumAnnuity,
pvInvoiceSumAnnuity,
pvAmortizationSumFlat,
pvInterestSumFlat,
pvInvoiceSumFlat);
format _numeric_ comma20. interestRateAnnual percent5.2;
run;