Skip Menu |
 

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

Report information
The Basics
Id: 42983
Status: patched
Worked: 10 min
Priority: 0/
Queue: Finance-Quote

People
Owner: eco [...] ecocode.net
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

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

Attachments


Subject: TSP previous day's price (patch)
Date: Tue, 03 Feb 2009 09:44:48 +1100
To: bug-Finance-Quote [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
Download (untitled) / with headers
text/plain 321b
I wonder if the tsp source could include the previous day's price as the "close" field, if I understand that one correctly. The couple of lines below do the trick for me. (The advantage would be that with at least one of "close", "net" or "p_change" a program can show a change amount together with the latest price.)
diff --git a/lib/Finance/Quote/TSP.pm b/lib/Finance/Quote/TSP.pm index 1759ff5..2e339da 100644 --- a/lib/Finance/Quote/TSP.pm +++ b/lib/Finance/Quote/TSP.pm @@ -90,7 +90,7 @@ sub tsp { # Local Variables my(%info, %fundrows); - my($ua, $reply, $row, $te); + my($ua, $reply, $row, $second_row, $te); $ua = $quoter->user_agent; $reply = $ua->request(GET $TSP_URL); @@ -103,6 +103,7 @@ sub tsp { # First row is newest data, older data follows, maybe there # should be some way to get it? $row = ($te->rows())[0]; + $second_row = ($te->rows())[1]; # Make a hash that maps the order the columns are in for(my $i=1; my $key = each %TSP_FUND_COLUMNS ; $i++) { @@ -132,6 +133,7 @@ sub tsp { $info{$_, 'name'} = $TSP_FUND_NAMES{$tmp}; ($info{$_, 'nav'} = $$row[$fundrows{$tmp}]) =~ s/[^0-9]*([0-9.,]+).*/$1/s; $info{$_, 'last'} = $info{$_, 'nav'}; + ($info{$_, 'close'} = $$second_row[$fundrows{$tmp}]) =~ s/[^0-9]*([0-9.,]+).*/$1/s; $quoter->store_date(\%info, $_, {usdate => $$row[0]}); } else { $info{$_, 'success'} = 0;
Download (untitled) / with headers
text/plain 868b
On Mon Feb 02 17:46:27 2009, user42@zip.com.au wrote: Show quoted text
> I wonder if the tsp source could include the previous day's price as the > "close" field, if I understand that one correctly. The couple of lines > below do the trick for me. > > (The advantage would be that with at least one of "close", "net" or > "p_change" a program can show a change amount together with the latest > price.) >
Hi, 'Close' is meant to be the "latest close". So until todays market session is closed, close should return yesterday's close. After market closes, close should return todays close. In practice, Finance Quotes modules take the latest price as being the close price with the exception if the site explicitly mentions a "close" quote. Your patch doesn't follow this idea. I'm certainly open to discussion if you think I'm wrong somewhere ;) Thanks for the help! -- Erik
Subject: Re: [rt.cpan.org #42983] TSP previous day's price (patch)
Date: Thu, 08 Oct 2009 11:53:21 +1100
To: bug-Finance-Quote [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
Download (untitled) / with headers
text/plain 886b
"Erik Colson via RT" <bug-Finance-Quote@rt.cpan.org> writes: Show quoted text
> > 'Close' is meant to be the "latest close". So until todays market > session is closed, close should return yesterday's close. After market > closes, close should return todays close.
I'm not sure the reads that way when it says "previous close". It makes me think it's whatever came before the "last" -- subject to rolling over some time overnight or early the next morning ready for the next trading session when the "change" resets to 0. Unless that's not what you mean already ... In any case for funds like TSP it'd be good to have some way to see the latest and previous, or the latest and a change amount, since that information is available in the download at no extra charge. The "close" field would seem reasonable since it matches plain shares during trading hours, and preserves "last - close == change".
Download (untitled) / with headers
text/plain 228b
Hi Kevin, Would you mind updating your patch for this 'close' field to the current TSP.pm file CPAN ? Also, please provide a test update for the returned data. Thanks for your work, and sorry for the huuuuge delay ! -- Erik
Subject: Re: [rt.cpan.org #42983] TSP previous day's price (patch)
Date: Sat, 12 Feb 2011 10:51:43 +1100
To: bug-Finance-Quote [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
Download (untitled) / with headers
text/plain 412b
"Erik Colson via RT" <bug-Finance-Quote@rt.cpan.org> writes: Show quoted text
> > Would you mind updating your patch for this 'close' field to the current TSP.pm file CPAN ?
I'll try to get to that soon. How does my other patch for yahoo billions rate? I may have to re-diff or gitize it too. I seem to have posted two diffs instead of one for the .t part, somehow. https://rt.cpan.org/Public/Bug/Display.html?id=50424
Download (untitled) / with headers
text/plain 597b
On Fri Feb 11 18:51:46 2011, user42@zip.com.au wrote: Show quoted text
> "Erik Colson via RT" <bug-Finance-Quote@rt.cpan.org> writes:
> > > > Would you mind updating your patch for this 'close' field to the
> current TSP.pm file CPAN ? > > I'll try to get to that soon.
Great, thank you ! Show quoted text
> > > How does my other patch for yahoo billions rate? I may have to re- > diff > or gitize it too. I seem to have posted two diffs instead of one for > the .t part, somehow. > > https://rt.cpan.org/Public/Bug/Display.html?id=50424
OK, I replied to that bug report for keeping references.. Best -- erik -- Erik
Subject: Re: [rt.cpan.org #42983] TSP previous day's price (patch)
Date: Tue, 15 Feb 2011 10:42:52 +1100
To: bug-Finance-Quote [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
Download (untitled) / with headers
text/plain 242b
Re-diffed as a format-patch for the current head, and slipping in the new L2050 fund at the same time. It couldn't be hard to recognise those year funds from the column text rather than listing them explicitly, but adding it for now works.
From 768104f98f6976229f9839ae514ec633095f4e2e Mon Sep 17 00:00:00 2001 From: Kevin Ryde <user42@zip.com.au> Date: Tue, 15 Feb 2011 10:40:08 +1100 Subject: [PATCH] TSP "close" field set from previous day's price. Add "close" and "last" to labels() and to the POD. Add L2050 fund. Expand the POD a bit, in particular list the fund symbols. --- lib/Finance/Quote/TSP.pm | 43 ++++++++++++++++++++++++++++++++++++++----- 1 files changed, 38 insertions(+), 5 deletions(-) diff --git a/lib/Finance/Quote/TSP.pm b/lib/Finance/Quote/TSP.pm index 7c574d1..36076c0 100644 --- a/lib/Finance/Quote/TSP.pm +++ b/lib/Finance/Quote/TSP.pm @@ -50,6 +50,7 @@ $TSP_MAIN_URL=("http://www.tsp.gov"); # Better not to hard code them. # %TSP_FUND_COLUMNS = ( + TSPL2050FUND => "L 2050", TSPL2040FUND => "L 2040", TSPL2030FUND => "L 2030", TSPL2020FUND => "L 2020", @@ -61,6 +62,7 @@ $TSP_MAIN_URL=("http://www.tsp.gov"); TSPIFUND => "I FUND" ); %TSP_FUND_NAMES = ( + TSPL2050 => 'Lifecycle 2050 Fund', TSPL2040 => 'Lifecycle 2040 Fund', TSPL2030 => 'Lifecycle 2030 Fund', TSPL2020 => 'Lifecycle 2020 Fund', @@ -74,7 +76,7 @@ $TSP_MAIN_URL=("http://www.tsp.gov"); sub methods { return (tsp => \&tsp) } { - my @labels = qw/name nav date isodate currency method/; + my @labels = qw/name nav date isodate currency method last close/; sub labels { return (tsp => \@labels); } } @@ -91,7 +93,7 @@ sub tsp { # Local Variables my(%info, %fundrows); - my($ua, $reply, $row, $te, $ts); + my($ua, $reply, $row, $te, $ts, $second_row); $ua = $quoter->user_agent; $reply = $ua->request(GET $TSP_URL); @@ -102,10 +104,11 @@ sub tsp { $te->parse($reply->content); # First row is newest data, older data follows, maybe there - # should be some way to get it? + # should be some way to get it (in addition to the second_row "close") $ts = $te->first_table_found || die 'TSP data table not recognised'; $row = $ts->row(0); + $second_row = $ts->row(1); # Make a hash that maps the order the columns are in for(my $i=1; my $key = each %TSP_FUND_COLUMNS ; $i++) { @@ -135,6 +138,7 @@ sub tsp { $info{$_, 'name'} = $TSP_FUND_NAMES{$tmp}; ($info{$_, 'nav'} = $$row[$fundrows{$tmp}]) =~ s/[^0-9]*([0-9.,]+).*/$1/s; $info{$_, 'last'} = $info{$_, 'nav'}; + ($info{$_, 'close'} = $second_row->[$fundrows{$tmp}]) =~ s/[^0-9]*([0-9.,]+).*/$1/s; $quoter->store_date(\%info, $_, {usdate => $$row[0]}); } else { $info{$_, 'success'} = 0; @@ -161,12 +165,41 @@ Finance::Quote::TSP Obtain fund prices for US Federal Government Thrift Savings =head1 DESCRIPTION This module fetches fund information from the "Thrift Savings Plan" -homepage http://www.tsp.gov. + + http://www.tsp.gov + +using its fund prices page + + https://www.tsp.gov/investmentfunds/shareprice/sharePriceHistory.shtml + +The quote symbols are + + C common stock fund + F fixed income fund + G government securities fund + I international stock fund + S small cap stock fund + L2020 lifecycle fund year 2020 + L2030 lifecycle fund year 2030 + L2040 lifecycle fund year 2040 + L2050 lifecycle fund year 2050 + LINCOME lifecycle income fund =head1 LABELS RETURNED The following labels may be returned by Finance::Quote::TSP : -name nav date currency method + + name eg. "Common Stock Index Investment Fund" + date latest date, eg. "21/02/10" + isodate latest date, eg. "2010-02-21" + last latest price, eg. "16.1053" + close previous day's price + nav same as "last" + currency "USD" + method "tsp" + +C<nav> is the same as C<last> since the funds are quoted at their net asset +value. =head1 SEE ALSO -- 1.7.2.3
Download (untitled) / with headers
text/plain 351b
On Mon Feb 14 18:43:10 2011, user42@zip.com.au wrote: Show quoted text
> Re-diffed as a format-patch for the current head, and slipping in the > new L2050 fund at the same time. > > It couldn't be hard to recognise those year funds from the column text > rather than listing them explicitly, but adding it for now works. >
Thanks you Kevin! Patch applied -- Erik


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.