+ Reply to Thread
Results 1 to 14 of 14

DURATION function

  1. #1
    Registered User
    Join Date
    06-29-2017
    Location
    CASA
    MS-Off Ver
    2007
    Posts
    13

    Exclamation DURATION function

    Hi all

    DURATION function : Returns the Macauley duration for an assumed par value of $100. Duration is defined as the weighted average of the present value of the cash flows and is used as a measure of a bond price's response to changes in yield.

    DURATION(settlement, maturity, coupon, yld, frequency, [basis])

    it is usually calculated by excel ; for example

    B7=DURATION(B1,B2,B3,B4,B5,B6)

    IePum.png


    but what i am trying to do , is to customize Duration function with vba editor

    2017-07-04_202126.png

    i think Excel uses this formula as explained in Wikipedia for calculation Macauley duration.

    ol1oM.png

    the problem is i find difficulty to write this function in vba to calculate Duration like Excel

  2. #2
    Forum Contributor
    Join Date
    07-28-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    104

    Re: DURATION function

    How about:

    WorksheetFunction.Duration

  3. #3
    Registered User
    Join Date
    06-29-2017
    Location
    CASA
    MS-Off Ver
    2007
    Posts
    13

    Re: DURATION function

    Hi thanks for reply

    yes i know , but i must write the function without using "WorksheetFunction.Duration"

  4. #4
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: DURATION function

    exc05,
    I presume this is also school work.
    If we do all your excel homework for you without you even showing your best attempt at creating the code - we rob you of the opportunity to learn...
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

  5. #5
    Registered User
    Join Date
    06-29-2017
    Location
    CASA
    MS-Off Ver
    2007
    Posts
    13

    Re: DURATION function

    I studied VBA for only two months, and my specialist not in vba, I only need these functions to integrate them into my project. i made a great effort to write the functions but I could not, so for this i'm asking for help now , Thanks

  6. #6
    Forum Contributor
    Join Date
    07-28-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    104

    Re: DURATION function

    If you want to integrate them into your project, then I stand by my recommendation. If you really want to create a wrapper function, how about this:

    Please Login or Register  to view this content.
    Now, you can use your CalcDuration function instead. It will still call the WorksheetFunction, so it will probably be more efficient than code you write yourself.

  7. #7
    Registered User
    Join Date
    06-29-2017
    Location
    CASA
    MS-Off Ver
    2007
    Posts
    13

    Re: DURATION function

    thank you Mr SlipEternal ,but i'm really wanted it without using WorksheetFunction

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: DURATION function

    i made a great effort to write the functions but I could not
    I think we could provide better help if you share some of these attempts you have tried. Explain the errors you are getting and what you expect from some of these attempts. I suspect that, if we could see some of your attempts, we would be able to see some of what you are misunderstanding and be able to help you understand why your code does not work and what changes you could make so it would work better.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: DURATION function

    Try example file.
    Attached Files Attached Files
    Last edited by bakerman2; 07-07-2017 at 04:30 AM. Reason: Fixed error in code
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  10. #10
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: DURATION function

    Nothing is more frustrating than to be working on homework and to get stuck. Without guidance, you might have no hope of finishing the assignment before the deadline. The Internet can be a big help in that respect, but without learning how to get the right answer, asking others to solve your homework questions for you simply becomes a downward spiral (and it's cheating).

    We do not want to contribute to you cheating yourself out of your education, but we also acknowledge that seeking assistance to learn a concept is a legitimate request.

    If you are genuinely interested in receiving help in the form of tutoring or coaching, then please rephrase the title of your original post to clearly indicate you are seeking coaching or tutoring help. Any forum members (who are willing to assist as a tutor) will modify their responses accordingly to facilitate your learning. Tutors don't tell you the answers, they help you figure it out for yourself; so don't expect answers, expect suggestions, or just plain hints. Also, be specific in describing the function/formula or technique you trying to learn, and tell us what you have attempted so far. Otherwise, expect your plea for homework answers to be ignored.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  11. #11
    Registered User
    Join Date
    06-29-2017
    Location
    CASA
    MS-Off Ver
    2007
    Posts
    13

    Re: DURATION function

    Thank you very much for the clarification , ه asked for help only because I could not reach a solution

  12. #12
    Registered User
    Join Date
    06-29-2017
    Location
    CASA
    MS-Off Ver
    2007
    Posts
    13

    Re: DURATION function

    Thank you for help , but in this example the Macaulay Duration have a 6 arguments , and in excel duration function we have just 5 arguments

  13. #13
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: DURATION function

    Maybe you can put a little effort in yourself, if it's not too much to ask.

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    06-29-2017
    Location
    CASA
    MS-Off Ver
    2007
    Posts
    13

    Red face Re: DURATION function

    Thank you bro , the code final

    Formula: copy to clipboard
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Sum of Max of a value in a duration
    By vkknava in forum Excel General
    Replies: 10
    Last Post: 01-05-2017, 06:10 PM
  2. Have start-stop times & duration, need sub-duration based on range criteria
    By CathTyner in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-23-2016, 01:53 AM
  3. [SOLVED] Formula: To calculate duration between two times, if duration is over 6hours subtract 30mi
    By MattBarnes7 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-11-2013, 03:22 PM
  4. Yield and duration function
    By rsl22 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-04-2009, 12:47 PM
  5. Duration
    By jonmsimon in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-09-2009, 03:40 PM
  6. Calling the "Duration" function in excel to be used in VBA?
    By korokke in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-27-2006, 12:13 PM
  7. [SOLVED] Duration
    By Tess in forum Excel General
    Replies: 3
    Last Post: 02-01-2005, 12:06 PM

Tags for this Thread

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