[R-SIG-Finance] Ques regarding price conversion to 32nds
Joshua Ulrich
josh.m.ulrich at gmail.com
Thu Sep 2 00:15:48 CEST 2010
Here's the answer to the second part, using the results from Pierre's email:
> eval(parse(text=paste(my.split[[1]],collapse="+")))
[1] 2.03125
Best,
--
Joshua Ulrich
FOSS Trading: www.fosstrading.com
On Wed, Sep 1, 2010 at 5:09 PM, Pierre Lapointe <pierrelap at gmail.com> wrote:
> Here's the answer to the first part of your question:
>
> #Decimals to fractions
> frac.fun <- function(x, den){
> dec <- seq(0, den) / den
> nams <- paste(seq(0, den), den, sep = "/")
> sapply(x, function(y) nams[which.min(abs(y - dec))])
> }
>
> frac.fun(c(0, 1, 0.8266667, .066666, 0.2666666,0.03125), 32)
>
> To convert from fraction to decimal, I would strsplit numbers in two parts,
> one integer and one fraction.
>
> #Fractions to decimals
> x <- c("2 1/32","3 7/32","4 27/32")
> my.split<-strsplit(x," ")
>
> However, I do not know how to convert a "1/32" caracter string to numeric.
>
> Pierre
>
>
> On Wed, Sep 1, 2010 at 5:22 PM, Gandhi, Puneet - RSCH AMRS <
> p.gandhi at baml.com> wrote:
>
>>
>>
>>
>> Hi,
>>
>> Can any one point me to a function which converts prices in decimals to
>> 32nds and vice versa.
>>
>> 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.
>
More information about the R-SIG-Finance
mailing list