Skriver "#Værdi" ved brug af VBA kode.
HejJeg har forsøgt mig med en VBA kode fra en lærerbog, men den vil ikke fungere. Jeg har forsøgt med både den engelske og danske udgave af "ÅR.BRØK" og KUPONDAG.FORRIGE. "INTSPOT" virker fint alene og det gør "ÅR.BRØK" og KUPONDAG.FORRIGE også.
Jeg har skrevet følgende i formlen:
=MYPRICE(B9,B5,B2,C2,100,B6) som svarer til:
MYPRICE(settlement, maturity, coupon rate, spots, notional, frequency, [compound],[fromdate], [basis]), hvor [compound],[fromdate], [basis] ikke er defineret.
Jeg håber der er nogle der kan hjælpe mig, da jeg er rimelig ny på VBA-området.
Jeg vil meget gerne sende Excel-arket, hvis det hjælper nogen...
Vh Martin
Jeg har kopieret følgende fra bogen (pdf):
Public Function INTSPOT(spots, year)
'Interpolates spot rates to year
Dim i As Integer, spotnum As Integer
spotnum = spots.Rows.Count
If Application.WorksheetFunction.Count(spots) = 1 Then
'Single rate given
INTSPOT = spots
Else 'Term structure given
If year <= spots(1, 1) Then
INTSPOT = spots(1, 2)
ElseIf year >= spots(spotnum, 1) Then
INTSPOT = spots(spotnum, 2)
Else
Do
i = i + 1
Loop Until spots(i, 1) > year
INTSPOT = spots(i - 1, 2) + (spots(i, 2) - spots(i - 1, 2)) * _
(year - spots(i - 1, 1)) / _
(spots(i, 1) - spots(i - 1, 1))
End If
End If
End Function
Public Function MYPRICE(settlement As Date, maturity As Date, rate, spots, _
notional, freq As Integer, Optional compound As Integer, _
Optional fromdate As Date, Optional basis As Integer)
'Determines present value of bond cash flows accruing after fromdate
Dim t As Date, y As Double
'Set default values and some error checking
If compound = 0 Then compound = freq
If fromdate = 0 Then fromdate = settlement
If fromdate > maturity Or settlement > maturity Then End
'Determine PV of payment at maturity
t = maturity
y = ÅR.BRØK(settlement, maturity, basis)
MYPRICE = (notional + notional * rate / freq) / _
(1 + INTSPOT(spots, y) / compound) ^ (y * compound)
'Add PVs of coupon payments
t = KUPONDAG.FORRIGE(t - 1, maturity, freq, basis)
Do While t > settlement And t >= fromdate
y = ÅR.BRØK(settlement, t, basis)
MYPRICE = MYPRICE + rate / freq * notional / _
(1 + INTSPOT(spots, y) / compound) ^ (y * compound)
t = KUPONDAG.FORRIGE(t - 1, maturity, freq, basis)
Loop
End Function
