[R] Big Finance and digits

Duncan Murdoch murdoch.duncan at gmail.com
Wed Feb 3 00:57:31 CET 2016


On 02/02/2016 4:28 PM, Glenn Schultz wrote:
> All,
>
> I am modeling a FNMA credit risk transfer deal.  The size of the collateral 250 billion.  Naturally, the cashflow is quite large the cash flow is calculated and stored in a S4 object which is then converted to an array and the result is character values - converting back to numeric I lose the decimal unless I set options(digits = 22).  Are there any other options available.  I have searched the internet and well as some R sites and it seems this maybe my only option.

Most R values are stored in double precision, which gives 15-16 digit 
accuracy.  That should give you values accurate to 1 cent in 10^13 
dollars, which covers your range.

Automatic conversion to characters shouldn't happen.  If it does, 
something is going wrong in your computations.  (It happens when you mix 
characters and numbers in the same vector.  Don't do that.)

At the end when you want to print, you need to convert to character. 
You can use options(digits=) to set the default number of digits, or you 
can do the conversion explicitly, using format(), sprintf(), or a 
related function.  It's up to you how many decimals you print.

Duncan Murdoch



More information about the R-help mailing list