My appreciation!
I tried:
-------------------------------------------------
Public Function BondPrice(alpha,beta,gama)
For i = 1 To beta
temp = (alpha * 100) / ((1 + gama) ^ i)
BondPrice = BondPrice + temp
Next i
End Function
------------------------------------------------
But when I loop this function in my subroutine I get all the cells with the same answer.
--------------------------------------------
Public Sub hw3
'dim part neglected
alpha=inputbox("coupon")
beta=inputbox("maturity")
gama=input box("yield")
For i = 1 To 11
Cells(i + 7, 3).Value = BondPrice(alpha, beta, gama)
Next i
End Sub
--------------------------------------------------
And I know what the problem is.
In the function you suggested:
BondPrice=BondPrice+temp
This is a nice idea,
but in order to get the sum I have to loop it.
And when I loop it, the BondPrice gets reset to 0 again.
That's why I came up with the idea of matrix because in matrix I can make it dynamic such as
-------------------------------------------------------------
For i = 1 To beta
matrix(10, i) = ((alpha ) * 100) / (1 + (gama ) ^ i)
Next i
------------------------------------------------------------
matrix(10,1) will be p1, and matrix(10, 2) will be p2. But then I'll have to sum it up by function and that's a violation.
10 in the matrix was nothing.
Any thoughts?
Bookmarks