Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. program not working...need somehelp

program not working...need somehelp

Scheduled Pinned Locked Moved Visual Basic
graphicshelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Danisto
    wrote on last edited by
    #1

    A quick explanation of what I am trying to achieve: for each bond that is selling in the stock market, there will be an issue date, maturity date, frequency of interest payments and lastly the interest rate. What I want is to have a function that allows me to input a date any time before the bond matures, and give me as an output a series of outstanding cashflows and the corresponding dates. Explanation of the variables in the code Valdate = todays date Ipos = indicator +1 or -1 depending if I have bought or borrowed the bond Notional = amount of bond D1 = date of bond issue D2 = date of maturity Freq = frequency of interest payments Coupon = interest rate V() = vector of all cashflow dates for the bond Cashflow = 2 by p matrix of the bond (dates and corresponding amounts) Code: Function bondcashflow(valdate, ipos, notional, d1, d2, freq, coupon) Dim p, m As Integer Dim v() Dim cashflow() ReDim cashflow(2, p) As Variant Dim n As Long n = Application.Round(DateDiff("d", d1, d2) / 365 * freq, 0) For i = 0 To n - 1 If freq = 1 Then v(i) = DateAdd("yyyy", 1 * i, d1) ElseIf freq = 2 Then v(i) = DateAdd("q", 2 * i, d1) ElseIf freq = 4 Then v(i) = DateAdd("q", 1 * i, d1) ElseIf freq = 12 Then v(i) = DateAdd("m", 1 * i, d1) End If m = 0 If valdate < v(i) Then m = m + 1 End If Next i p = n - m For k = 1 To p cashflow(1, k) = v(k + m - 1) Do While k < p cashflow(2, k) = ipos * coupon * notional Loop Next k cashflow(2, p) = ipos * (notional + coupon * notional) bondcashflow = cashflow End Function

    D S 2 Replies Last reply
    0
    • D Danisto

      A quick explanation of what I am trying to achieve: for each bond that is selling in the stock market, there will be an issue date, maturity date, frequency of interest payments and lastly the interest rate. What I want is to have a function that allows me to input a date any time before the bond matures, and give me as an output a series of outstanding cashflows and the corresponding dates. Explanation of the variables in the code Valdate = todays date Ipos = indicator +1 or -1 depending if I have bought or borrowed the bond Notional = amount of bond D1 = date of bond issue D2 = date of maturity Freq = frequency of interest payments Coupon = interest rate V() = vector of all cashflow dates for the bond Cashflow = 2 by p matrix of the bond (dates and corresponding amounts) Code: Function bondcashflow(valdate, ipos, notional, d1, d2, freq, coupon) Dim p, m As Integer Dim v() Dim cashflow() ReDim cashflow(2, p) As Variant Dim n As Long n = Application.Round(DateDiff("d", d1, d2) / 365 * freq, 0) For i = 0 To n - 1 If freq = 1 Then v(i) = DateAdd("yyyy", 1 * i, d1) ElseIf freq = 2 Then v(i) = DateAdd("q", 2 * i, d1) ElseIf freq = 4 Then v(i) = DateAdd("q", 1 * i, d1) ElseIf freq = 12 Then v(i) = DateAdd("m", 1 * i, d1) End If m = 0 If valdate < v(i) Then m = m + 1 End If Next i p = n - m For k = 1 To p cashflow(1, k) = v(k + m - 1) Do While k < p cashflow(2, k) = ipos * coupon * notional Loop Next k cashflow(2, p) = ipos * (notional + coupon * notional) bondcashflow = cashflow End Function

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Danisto wrote:

      What I want is to have a function that allows me to input a date any time before the bond matures, and give me as an output a series of outstanding cashflows and the corresponding dates.

      OK. So what's the problem?

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      1 Reply Last reply
      0
      • D Danisto

        A quick explanation of what I am trying to achieve: for each bond that is selling in the stock market, there will be an issue date, maturity date, frequency of interest payments and lastly the interest rate. What I want is to have a function that allows me to input a date any time before the bond matures, and give me as an output a series of outstanding cashflows and the corresponding dates. Explanation of the variables in the code Valdate = todays date Ipos = indicator +1 or -1 depending if I have bought or borrowed the bond Notional = amount of bond D1 = date of bond issue D2 = date of maturity Freq = frequency of interest payments Coupon = interest rate V() = vector of all cashflow dates for the bond Cashflow = 2 by p matrix of the bond (dates and corresponding amounts) Code: Function bondcashflow(valdate, ipos, notional, d1, d2, freq, coupon) Dim p, m As Integer Dim v() Dim cashflow() ReDim cashflow(2, p) As Variant Dim n As Long n = Application.Round(DateDiff("d", d1, d2) / 365 * freq, 0) For i = 0 To n - 1 If freq = 1 Then v(i) = DateAdd("yyyy", 1 * i, d1) ElseIf freq = 2 Then v(i) = DateAdd("q", 2 * i, d1) ElseIf freq = 4 Then v(i) = DateAdd("q", 1 * i, d1) ElseIf freq = 12 Then v(i) = DateAdd("m", 1 * i, d1) End If m = 0 If valdate < v(i) Then m = m + 1 End If Next i p = n - m For k = 1 To p cashflow(1, k) = v(k + m - 1) Do While k < p cashflow(2, k) = ipos * coupon * notional Loop Next k cashflow(2, p) = ipos * (notional + coupon * notional) bondcashflow = cashflow End Function

        S Offline
        S Offline
        Steve Erbach
        wrote on last edited by
        #3

        Danisto, Just a brief glance through your code shows that in the For loop at the end you've embedded "Do While k < p". The loop has no exit; that is, it's an infinite loop. Also, the ReDim of the cashflow array uses p as the second dimension, but p hasn't been assigned a value at that point. Is your Code block really supposed to be pseudo-code? Regards, Steve Erbach Neenah, WI

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups