我正在尝试为摊销成本制作一个“会计”模型。我将制作一个包含实际付款日期的数组,一个包含“摊销成本”的数组,另一个数组显示报告日的值(例如 31.12)。我已经手动完成了这个,但是希望它通过“一键”来执行这些操作,只需更改输入数据。我对 VBA 很陌生(仅仅几天),到目前为止,我一直在为“付款日期”数组苦苦挣扎,显示债券的现金流。
到目前为止,我有以下代码
Sub LoanAmortization()
'----------------------------------------------------------------------------------------------------------------------------------------------
'1)Define the arrays and variables that will be used along the process
'----------------------------------------------------------------------------------------------------------------------------------------------
'Dim Trends As Workbook 'Variable to refer to the workbook
Dim initLoanBal As Double 'Initial bond amount
Dim DayCountBasis As Double 'Day count convention
Dim BegDate As Date 'Date of bond repayment
Dim MaturityDate As Date 'Date of bond repayment
Dim TransCost As Double 'Transactioncosts on bonds
Dim PayFreq As Double 'Frequency of coupon payments on bond (e.g. quarterly)
Dim initRate As Double 'Interest rate on bond
Dim CashFlowArray() As Integer 'Array of Cash flows on bond
Dim CouponFreqString As String
Dim NomRate As Double 'Rate used for cash flow calculation
Dim i As Long
''----------------------------------------------------------------------------------------------------------------------------------------------
''2)Set variables for the calculation
''----------------------------------------------------------------------------------------------------------------------------------------------
initLoanBal = ThisWorkbook.Worksheets("Amortisering").Range("D3").Value
TransCost = Worksheets("Amortisering").Range("D4").Value
initRate = Worksheets("Amortisering").Range("D5").Value
Spread = Worksheets("Amortisering").Range("D6").Value
DayCountBasis = Worksheets("Amortisering").Range("D7").Value
CouponFreq = Worksheets("Amortisering").Range("E8").Value
CouponFreqString = Worksheets("Amortisering").Range("D8").Value
BegDate = Worksheets("Amortisering").Range("D9").Value
MaturityDate = Worksheets("Amortisering").Range("D10").Value
NomRate = initRate + Spread
'----------------------------------
'Format variables for the calculation
'----------------------------------
Cells(5, 4).Select
Selection.Value = initRate
Selection.NumberFormat = "0.00%"
Cells(6, 4).Select
Selection.NumberFormat = "0.00%"
'-----------------------------------------------------------
'Set cash flows dates
'-----------------------------------------------------------
NoPeriods = DateDiff(CouponFreqString, BegDate, MaturityDate, vbMonday)
' Number of periods ("payments") on the bond
Range("G29") = BegDate
Range("F31") = BegDate
Range("G31").NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""??_);_(@_)"
For i = 1 To NoPeriods
Cells(29, 7 + i) = DateAdd(CouponFreqString, i, BegDate)
Cells(31 + i, 6) = DateAdd(CouponFreqString, i, BegDate)
Next i
'----------------------------------------------
'Set number of days dager
'----------------------------------------------
For i = 1 To NoPeriods ' No. days between payments (daycount convention)
Cells(30, 7 + i) = WorksheetFunction.YearFrac(Cells(29, 6 + i), Cells(29, 7 + i), DayCountBasis)
Next i
'----------------------------------------------
'Cash flow array
'----------------------------------------------
For c = 1 To NoPeriods
For i = 1 To NoPeriods
Cells(30 + i, 7 + c) = initLoanBal * NomRate * Cells(30, 7 + c)
Next i
Next c
Range("G31") = -initLoanBal + TransCost
End Sub
目标
所以问题出现在“现金流数组”部分。1. 最终目标是使用 XIRR 根据 NomRate 计算每个期间的有效利率。
我希望 NomRate 在每个时期都不同,因为浮动利率会发生变化。
我希望每一行的最终付款等于利息支付和贷款的偿还(即initLoanBal)。
我希望第一笔现金流等于上期计算的摊销成本。
我希望数组每次迭代减少 1
请参阅图像以了解我希望它的外观(绿色值是下一个数组中的“摊销成本值”,即摊销成本值)