Skip Menu |
 

This queue is for tickets about the Finance-Quote CPAN distribution.

Report information
The Basics
Id: 74694
Status: open
Worked: 20 min
Priority: 0/
Queue: Finance-Quote

People
Owner: eco [...] ecocode.net
Requestors: mta [...] umich.edu
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.17
Fixed in: (no value)



Subject: Better value for very small currency exchange rates
Download (untitled) / with headers
text/plain 374b
Some currency exchange rates have almost no precision because the rate is so small and Yahoo only reports 4 or 5 digits after the decimal point no matter how small the rate is. For example 1 krw = 0.0009 usd The attached patch changes Quote.pm so that rates like this are computed using the reciprocal of the inverse rate so instead you get 1 krw = 0.00089656 usd
Subject: currency2.diff
Download currency2.diff
text/x-diff 971b
--- lib/Finance/Quote.pm 2012-02-05 00:51:04.000000000 -0500 +++ lib/Finance/Quote.pm 2012-02-05 00:51:39.000000000 -0500 @@ -300,6 +300,22 @@ my $primary_rate = primary_url($this, $from, $to); my $secondary_rate = secondary_url($this, $from, $to); + + # If the rate is very small we get no accuracy so take the reciprocal + # of the inverse rate. + if ( $primary_rate && $primary_rate < .001 ) { + $primary_rate = 1 / primary_url($this, $to, $from); + if ( $primary_rate ) { + $primary_rate = int($primary_rate * 100000000 + .5) / 100000000; + } + } + if ( $secondary_rate && $secondary_rate < .001 ) { + $secondary_rate = 1 / secondary_url($this, $to, $from); + if ( $secondary_rate ) { + $secondary_rate = int($secondary_rate * 100000000 + .5) / 100000000; + } + } + my $exchange_rate = $primary_rate; if ( $primary_rate && $secondary_rate ) {
Download (untitled) / with headers
text/plain 558b
On Sun Feb 05 01:31:24 2012, malexander wrote: Show quoted text
> Some currency exchange rates have almost no precision because the rate > is so small and Yahoo only reports 4 or 5 digits after the decimal point > no matter how small the rate is. For example > > 1 krw = 0.0009 usd > > The attached patch changes Quote.pm so that rates like this are computed > using the reciprocal of the inverse rate so instead you get > > 1 krw = 0.00089656 usd >
Hi, I got the idea and implemented it in a slightly different way. see the master branch. thanks again -- Erik
Subject: Re: [rt.cpan.org #74694] Better value for very small currency exchange rates
Date: Tue, 03 Apr 2012 19:45:08 -0400
To: bug-Finance-Quote [...] rt.cpan.org
From: Mike Alexander <mta [...] umich.edu>
Download (untitled) / with headers
text/plain 1021b
--On April 1, 2012 4:17:27 PM -0400 Erik Colson via RT <bug-Finance-Quote@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=74694 > > > On Sun Feb 05 01:31:24 2012, malexander wrote:
>> Some currency exchange rates have almost no precision because the >> rate is so small and Yahoo only reports 4 or 5 digits after the >> decimal point no matter how small the rate is. For example >> >> 1 krw = 0.0009 usd >> >> The attached patch changes Quote.pm so that rates like this are >> computed using the reciprocal of the inverse rate so instead you get >> >> 1 krw = 0.00089656 usd >>
> > Hi, > > I got the idea and implemented it in a slightly different way. > see the master branch. > > thanks again
Thanks, your version seems to work fine. I presume you saw my patches for the TIAACREF module attached to <https://rt.cpan.org/Public/Bug/Display.html?id=62104>. In case it helps I've attached a patch file that applies these changes to the current master branch on github. Mike
Download tiaacref.patch.gz
application/octet-stream 4.6k

Message body not shown because it is not plain text.



This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.