[R-SIG-Finance] [SPAM] - Re: Question regarding floor and round - Email found in subject

David Reiner David.Reiner at xrtrading.com
Thu Aug 26 18:18:52 CEST 2010


and of course Excel doesn't handle negative x in a nice way,
(you have to negate base, and switch floor and ceiling in Excel),
but the R functions given do it correctly without having to negate base.
(You could emulate Excel's functions exactly for negative x,
but why would you want to?)
-- David

-----Original Message-----
From: r-sig-finance-bounces at stat.math.ethz.ch [mailto:r-sig-finance-bounces at stat.math.ethz.ch] On Behalf Of Gandhi, Puneet - RSCH AMRS
Sent: Thursday, August 26, 2010 6:44 AM
To: Martin Becker; Pierre Lapointe
Cc: r-sig-finance at stat.math.ethz.ch
Subject: [SPAM] - Re: [R-SIG-Finance] Question regarding floor and round - Email found in subject


 Great,
That works perfectly.

Thanks a lot Martin
Puneet

-----Original Message-----
From: Martin Becker [mailto:martin.becker at mx.uni-saarland.de]
Sent: Thursday, August 26, 2010 3:38 AM
To: Pierre Lapointe
Cc: Gandhi, Puneet - RSCH AMRS; r-sig-finance at stat.math.ethz.ch
Subject: Re: [R-SIG-Finance] Question regarding floor and round


  AFAIR, Excel does not comply with IEEE rounding (but R does), which
may lead to undesirable results if Base is not exactly representable; at

least on my system I get

 > my.floor(2.8,0.2)
[1] 2.6

for example.
So (if my memory about Excel's behaviour is correct) one has to modify
the functions my.floor and my.ceiling slightly to mimic Excel's
behaviour more precisely. Something like

Floor <- function(x,Base) {
   Base*floor(x*(1+.Machine$double.eps)/Base)
}

Ceiling <- function(x,Base) {
   Base*ceiling(x*(1-.Machine$double.eps)/Base)
}

may be closer to Excel. At least, in the previous example I get

 > Floor(2.8,0.2)
[1] 2.8

on my system.

HTH

   Martin




On 26.08.2010 00:00, Pierre Lapointe wrote:
> Here are modified floor and ceiling functions that solve your problem:
>
> my.floor<-function(x,my.base){
> floor(x/my.base)*my.base
> }
>
> my.ceiling<-function(x,my.base){
> ceiling(x/my.base)*my.base
> }
>
> Base = 0.5
> my.floor(126.6,Base)   #[1] 126.5
> my.ceiling(126.6,Base) #[1] 127
>
> Base = 1
> my.floor(126.6,Base) #[1] 126
> my.ceiling(126.6,Base) #[1] 127
>
> HTH
>
> Pierre
>
>
> On Wed, Aug 25, 2010 at 4:38 PM, Gandhi, Puneet - RSCH AMRS<
> p.gandhi at baml.com>  wrote:
>
>> Hi All,
>>
>> Is there any function in R which does what Floor or Ceiling in Excel.
>>
>> Excel can take 2 arguments to FLOOR function while R doesn't.
>>
>> I need the following which is done in excel
>>
>> Base = 0.5
>> Floor(126.6,Base) = 126.5
>> Ceiling(126.6, Base) = 127
>>
>>
>> Base = 1
>> Floor(126.6, Base) = 126
>> Ceiling(126.6, Base) = 127
>>
>> I tried round, floor, ceiling, trunc in R but none does this job.
>>
>> Pls Help/Thanks
>> Puneet
>>
>>
----------------------------------------------------------------------
>> This message w/attachments (message) is intended solely
...{{dropped:7}}
>>
>> _______________________________________________
>> R-SIG-Finance at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R
questions
>> should go.
>>
>       [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R
questions should go.


--
Dr. Martin Becker
Statistics and Econometrics
Saarland University
Campus C3 1, Room 217
66123 Saarbruecken
Germany

----------------------------------------------------------------------
This message w/attachments (message) is intended solely ...{{dropped:7}}

_______________________________________________
R-SIG-Finance at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.


This e-mail and any materials attached hereto, including, without limitation, all content hereof and thereof (collectively, "XR Content") are confidential and proprietary to XR Trading, LLC ("XR") and/or its affiliates, and are protected by intellectual property laws.  Without the prior written consent of XR, the XR Content may not (i) be disclosed to any third party or (ii) be reproduced or otherwise used by anyone other than current employees of XR or its affiliates, on behalf of XR or its affiliates.

THE XR CONTENT IS PROVIDED AS IS, WITHOUT REPRESENTATIONS OR WARRANTIES OF ANY KIND.  TO THE MAXIMUM EXTENT PERMISSIBLE UNDER APPLICABLE LAW, XR HEREBY DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS AND IMPLIED, RELATING TO THE XR CONTENT, AND NEITHER XR NOR ANY OF ITS AFFILIATES SHALL IN ANY EVENT BE LIABLE FOR ANY DAMAGES OF ANY NATURE WHATSOEVER, INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL AND PUNITIVE DAMAGES, LOSS OF PROFITS AND TRADING LOSSES, RESULTING FROM ANY PERSON'S USE OR RELIANCE UPON, OR INABILITY TO USE, ANY XR CONTENT, EVEN IF XR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES OR IF SUCH DAMAGES WERE FORESEEABLE.



More information about the R-SIG-Finance mailing list