Results 1 to 3 of 3

UDF for Converting Bond Price in Ticks to Decimal Number Format

Threaded View

  1. #1
    Registered User
    Join Date
    09-19-2015
    Location
    US
    MS-Off Ver
    2013
    Posts
    2

    UDF for Converting Bond Price in Ticks to Decimal Number Format

    I have two long formulas that I am trying to turn into a UDF because I use them frequently, and I am new to VBA.

    The first formula converts the tick price (Agency MBS convention) into a decimal number. The convention is shown below.
    Formula: copy to clipboard
    =LEFT(A1,FIND("-",A1)-1)+(LEFT(SUBSTITUTE(RIGHT(A1,LEN(A1)-FIND("-",A1)),"+","4"),2)+IFERROR(MID(SUBSTITUTE(RIGHT(A1,LEN(A1)-FIND("-",A1)),"+","4"),3,1)/8,0))/32

    ticktodec.PNG

    For 104-084, the "08" to the right of "-" represents 8/32's and the third number represents 4/8 of 1/32 or alternatively 4/256. The "+" means half of 1/32 or 4/256 as well.

    I created a UDF for this formula(=Pxd(n)), but it only works for 2 of the 4 different tick formats I need.

    Function Pxd(n)
    Pxd = Left(n, WorksheetFunction.Find("-", n) - 1) + (Left(WorksheetFunction.Substitute( _
        Right(n, Len(n) - WorksheetFunction.Find("-", n)), "+", "4"), 2) _
        + WorksheetFunction.IfError(Mid(WorksheetFunction.Substitute(Right(n, Len(n) - _
        WorksheetFunction.Find("-", n)), "+", "4"), 3, 1) / 8, 0)) / 32
    End Function
    I tried to create a UDF for the second formula, which reverses the formula and converts decimals to ticks but kept running into errors.
    Formula: copy to clipboard
    =INT(A2) & "-"&IF(LEN(ROUNDDOWN((A2-INT(A2))*32,0))=1,"0"&ROUNDDOWN((A2-INT(A2))*32,0),ROUNDDOWN((A2-INT(A2))*32,0))&VLOOKUP((ROUNDDOWN((A2-INT(A2))*256,0)/8)-INT(ROUNDDOWN((A2-INT(A2))*256,0)/8),{0,0;0.125,1;0.25,2;0.375,3;0.5,"+";0.625,5;0.75,6;0.875,7;1,8},2,0)

    dectotick.PNG

    How do I fix the first UDF and how should I set up the UDF for the second formula? Thank you in advance for any help you can provide.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Converting an elapsed time in decimal number format to an actual time :S
    By Spicey_888 in forum Excel General
    Replies: 3
    Last Post: 07-20-2014, 08:53 PM
  2. Formula for bond price
    By Dracan in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 04-15-2014, 11:17 AM
  3. Keep number format when converting to text - with decimal and zeros
    By tampagirl in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-11-2014, 06:34 PM
  4. Bond price conversion
    By freddie mac in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-21-2014, 01:08 AM
  5. Need Help writing bond price conversion
    By elviejo41 in forum Excel General
    Replies: 5
    Last Post: 12-13-2006, 01:00 PM
  6. Replies: 3
    Last Post: 03-18-2006, 02:25 PM
  7. Calculating Bond Price
    By legu in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-16-2006, 12: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