Using new ROUND() function giving erratic results?

Optuma Forums Optuma Scripting Using new ROUND() function giving erratic results?

This topic contains 1 reply, has 1 voice, and was last updated by Avatar Dean 4 months, 1 week ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #52667
    Avatar
    Dean
    • Topics: 13
    • Replies: 23
    • Posts: 36

    Hi, I was wondering if anyone has been working with the new ROUND() function released with version 1.4?

    I have had success rounding simple formulas like CLOSE()/OPEN() but have not had much luck with more complex formulas, for example:

    BARDATE()/7 + MOD(VALUE=30, 19 * MOD(VALUE=19, YEARNUM()) – 7) * 0.14;

    I’ve tested this formula using two custom labels on the cursor, the first label using the ROUND function as follows:

    testdate = BARDATE()/7 + MOD(VALUE=30,19*MOD(VALUE=19,YEARNUM())-7) * 0.14;

    v1 = ROUND(testdate, DECIMALTYPE=0.00) ;

    v1

    and the second label not using the ROUND function at all as follows:

    testdate = BARDATE()/7 + MOD(VALUE=30,19*MOD(VALUE=19,YEARNUM())-7) * 0.14;

    testdate

    With the cursor hovering over 12 April 2019 (BARDATE()=43567), both custom labels return 6227.777143. I would have expected that the label using the ROUND function should have returned a value of 6227.780000.

    However, if I substitute the testdate variable with a simple formula like CLOSE()/OPEN(), the two custom labels return values as expected. For example, on the daily SPY (WI) on 12 April 2019, the custom label using ROUND returns 1.000000 while the custom label not using ROUND returns 1.002258.

    Has anyone had a similar experience or can give me a clue on what I have missed?

    Many thanks

     

    #52671
    Avatar
    Dean
    • Topics: 13
    • Replies: 23
    • Posts: 36

    Alternate solution using FLOOR and MOD

    For what it is worth, I was able to get expected rounding results by using the following script (using FLOOR and MOD functions) as a substitute for the ROUND function

    testdate = BARDATE()/7 + MOD(VALUE=30,19*MOD(VALUE=19,YEARNUM())-7) * 0.14;

    ROUNDtestdate = FLOOR(testdate) + IF(MOD(VALUE=100, testdate*100)/100);

    ROUNDtestdate

    With the cursor hovering on 12 April 2019 (BARDATE()=43567), a custom label with this script returned the expected value of 6227.780000 (the un-rounded value is 6227.777143). Changing the MOD divisor increases or decreases at what decimal place the rounding occurs (e.g. changing to MOD(VALUE=10, testdate*10)/10 will return a result of 6227.800000). To round to an integer, the 2nd line of the script must be slightly different, as follows:

    ROUNDtestdate = FLOOR(testdate) +IF(MOD(VALUE=10, testdate*10)/10 > 0.5, 1, 0)

    the script then rounds to 6228.000000 as expected. 

    Luckily, this post in the forum mentions the FLOOR function. FLOOR is not documented in the Formula Functions & General Interface.

    Even though this is a viable alternative to the ROUND function, I’d still be interested if anyone can offer advice on getting the ROUND() function to operate as expected.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

Pin It on Pinterest

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close