Results 1 to 6 of 6

Need tutoring!!! Writing a cumulative sum function (without calling vba function)

Threaded View

  1. #1
    Registered User
    Join Date
    09-14-2014
    Location
    US
    MS-Off Ver
    2013
    Posts
    3

    Unhappy Need tutoring!!! Writing a cumulative sum function (without calling vba function)

    Hi guys,
    I'm new to vba and recently I met a challenge in my work and I really appreciate if someone can give me some suggestions.

    So I'm trying to write a function to calculate a Bond's Price.
    Given values: coupon, maturity, yield.

    It will be something like this BondPrice=(coupon,maturity,yield)
    And this is the mathematics formula :

    Price (yield)= ∑_(i=1)^(maturity)▒〖CF〗_i/〖( 1+yield)〗^i

    note: 〖CF〗_i= (coupon)*100

    The price is a sum from period i = 1 to maturity, given coupon, maturity and yield.
    Specifically,
    BondPrice=P.1+P.2+P.3+...+P.maturity

    That sigma in the formula get me busted so hard because of the 'rule' we've given.

    Rule:
    Required to write the function without calling vba functions such as P=Sum(Range()). Yeah pure vba language!!!

    -------------------------------------------------------------------------------------
    Below is my 3-hours attempt and it wouldn't work as well as violated the rule.

    Public Function BondPrice(alpha, beta, gama)

    'alpha=coupon
    'beta=maturity
    'gama=yield

    Dim matrix(10 To 10, 1 To 100) As Double

    alpha = Cells(3, 3).Value
    beta = Cells(4, 3).Value
    gama = Cells(5, 3).Value

    'their values are gathered from a subroutine that I wrote before, I put them here for testing purpose.


    For i = 1 To beta

    matrix(10, i) = ((alpha ) * 100) / (1 + (gama ) ^ i)

    Next i

    BondPrice = Application.Sum(Range(matrix(10, 1), matrix(10, beta )))


    End Function

    ---------------------------------
    The work is due next Thursday. That could mean I have a lot of time to enjoy my frustration here.
    But I trust the community to be my salvation. Please help! And please don't forget the rule!
    Last edited by tliu1; 09-15-2014 at 12:01 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Dax function for cumulative numbers/percents
    By Paul-NYS in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 08-26-2013, 08:50 AM
  2. Macro exits prematurely from function after calling other function
    By LouisPhilippe in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-22-2013, 03:22 AM
  3. [SOLVED] help with calling a function (B) and return control of program flow to the calling functio
    By john/nyc in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-26-2012, 11:06 AM
  4. Cumulative Count Function
    By larryg003 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-28-2010, 01:08 PM
  5. How do I calculate the cumulative distribution function
    By macrohunter in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-17-2006, 01:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1