[R] Quantmod - modify decimal places

David Menezes david.n.menezes at gmail.com
Tue May 24 03:57:49 CEST 2016


Hi

Apologies if this has already been asked and answered or if I've labelled
the subject incorrectly but I can't find a solution using the search
function for this group; the vignette documentation for quantmod or general
google searches.

I'm attempting to use quantmod to download foreign currency exchange
rates.  I'm using the call "getFX" however the output results are always
restricted to 4 decimal places.  Generally this is fine but when comparing
developing and mature economies this can lead to no answer being returned
due to how weak a specific currency is (in relative terms).

For example, compare the following two results for converting USD to
Vietnamese Dong (VND):

a)      *1/getFX("USD/VND",from="2016-05-22",to ="2016-05-22", source =
"oanda", auto.assign=FALSE)*

 This yields…

                USD.VND

2016-05-22 4.473272e-05

 However my preferred call would be:

 b)*      getFX("VND/USD",from="2016-05-22",to ="2016-05-22", source =
"oanda", auto.assign=FALSE)*

 However this yields a zero result:

VND.USD

2016-05-22       0


which is clearly wrong.


I've tried various things including trying to invoke options (digits = 10)
at the start of the script, and even within the getFX wrapper as an extra
argument, but it doesn't work.  I can of course run select cross currency
rates and invert the results, but that is pretty awkward and it feels like
there ought to be a smarter and simpler solution.

Any help greatly appreciated.

Thanks
Dave

	[[alternative HTML version deleted]]



More information about the R-help mailing list