# HG changeset patch
# User Thomas Weber <tweber@debian.org>
# Date 1378464293 -7200
#      Fri Sep 06 12:44:53 2013 +0200
# Node ID b8c947118a8566c1a95b14234ac47db6137d295a
# Parent  7e6433be0b10db1566e620b0602a90f406104e70
Update Google test case for daily values

It seems the values returned by Google for the daily traded volumes changed. I
do not understand why that is the case, nor why the traded volumes given by
Google, Yahoo and the Nasdaq Historical data differ:

01 July 2005, traded volume of symobl YHOO:
Yahoo:	9.861.600
Google:	9,875,220
Nasdaq:	9,872,570

diff -r 7e6433be0b10 -r b8c947118a85 inst/private/fetch_google.m
--- a/inst/private/fetch_google.m	Tue Sep 03 07:50:42 2013 -0400
+++ b/inst/private/fetch_google.m	Fri Sep 06 12:44:53 2013 +0200
@@ -79,11 +79,11 @@
 
 %!shared fgood, dgood, wgood
 %! fgood = {"Date", "Open", "High", "Low", "Close", "Volume"};
-%! dgood = [732501,34.77,34.87,34.25,34.62,15296900;
-%!          732500,33.87,34.77,33.72,34.63,16265900;
-%!          732499,34.64,34.97,34.03,34.12,13451500;
-%!          732498,34.25,35.08,34.20,34.60,15845100;
-%!          732494,34.76,34.85,34.22,34.44,9740300];
+%! dgood = [732501,34.77,34.87,34.25,34.62,15520553;
+%!          732500,33.87,34.77,33.72,34.63,16360297;
+%!          732499,34.64,34.97,34.03,34.12,13694806;
+%!          732498,34.25,35.08,34.20,34.60,16103029;
+%!          732494,34.76,34.85,34.22,34.44,9875220];
 %! wgood = [732501,34.25,35.08,33.72,34.62,60859400;
 %!          732494,35.88,36.24,34.22,34.44,67132100];
 %!test
# HG changeset patch
# User Thomas Weber <tweber@debian.org>
# Date 1378466394 -7200
#      Fri Sep 06 13:19:54 2013 +0200
# Node ID 5dcc545b4a628231bc6dde90f02adcbd60962220
# Parent  b8c947118a8566c1a95b14234ac47db6137d295a
Remove option for weekly stock prices from Google Finance

Google Finance no longer supports weekly historical prices

diff -r b8c947118a85 -r 5dcc545b4a62 inst/fetch.m
--- a/inst/fetch.m	Fri Sep 06 12:44:53 2013 +0200
+++ b/inst/fetch.m	Fri Sep 06 13:19:54 2013 +0200
@@ -51,7 +51,7 @@
 ## the associated backend.
 ## @itemize @bullet
 ## @item 'd': daily
-## @item 'w': weekly
+## @item 'w': weekly (Yahoo only)
 ## @item 'm': monthly (Yahoo only)
 ## @item 'v': dividends (Yahoo only)
 ## @end itemize
diff -r b8c947118a85 -r 5dcc545b4a62 inst/private/fetch_google.m
--- a/inst/private/fetch_google.m	Fri Sep 06 12:44:53 2013 +0200
+++ b/inst/private/fetch_google.m	Fri Sep 06 13:19:54 2013 +0200
@@ -29,7 +29,6 @@
 ## data which can be any of
 ## @itemize @bullet
 ## @item 'd': daily
-## @item 'w': weekly
 ## @end itemize
 ##
 ## @seealso{google, fetch}
@@ -40,8 +39,10 @@
 
 function [data fields] = fetch_google (conn=[], symbol="",
                                           fromdate, todate, period="d")
-
-  periods = struct("d", "daily", "w", "weekly");
+  if strcmpi(period, "w")
+    error("Google Financial no longer supports weekly stock data");
+  endif
+  periods = struct("d", "daily");
   if strcmpi (conn.url, "http://finance.google.com")
     fromdatestr = datestr (fromdate);
     todatestr   = datestr (todate);
@@ -95,8 +96,6 @@
 %! [d f] = fetch_google (google(), "yhoo", 732494, 732501);
 %! assert(d, dgood, eps);
 %! assert(f, fgood, eps);
-## Test that weekly works
+## Test that weekly fails
 %!test
-%! [d f] = fetch_google (google(), "yhoo", 732494, 732501, "w");
-%! assert(d, wgood, eps);
-%! assert(f, fgood, eps);
+%! fail ('fetch_google (google(), "yhoo", 732494, 732501, "w")', ".*weekly.*")
# HG changeset patch
# User Thomas Weber <tweber@debian.org>
# Date 1378466533 -7200
#      Fri Sep 06 13:22:13 2013 +0200
# Node ID 4d3d4a5b8ab0cda62f75713f5bbe4a0d2c884dac
# Parent  5dcc545b4a628231bc6dde90f02adcbd60962220
Remove DOS line ending from all .m files - no code changes

diff -r 5dcc545b4a62 -r 4d3d4a5b8ab0 inst/fetch.m
--- a/inst/fetch.m	Fri Sep 06 13:19:54 2013 +0200
+++ b/inst/fetch.m	Fri Sep 06 13:22:13 2013 +0200
@@ -1,149 +1,149 @@
-## Copyright (C) 2008 Bill Denney <bill@denney.ws>
-##
-## This program is free software; you can redistribute it and/or modify it under
-## the terms of the GNU General Public License as published by the Free Software
-## Foundation; either version 3 of the License, or (at your option) any later
-## version.
-##
-## This program is distributed in the hope that it will be useful, but WITHOUT
-## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-## details.
-##
-## You should have received a copy of the GNU General Public License along with
-## this program; if not, see <http://www.gnu.org/licenses/>.
-
-## -*- texinfo -*-
-## @deftypefn {@var{data} =} fetch (@var{conn}, @var{symbol})
-## @deftypefnx {@var{data} =} fetch (@dots{}, @var{fields})
-## @deftypefnx {@var{data} =} fetch (@dots{}, @var{date})
-## @deftypefnx {@var{data} =} fetch (@dots{}, @var{fromdate}, @var{todate})
-## @deftypefnx {@var{data} =} fetch (@dots{}, @var{period})
-## @deftypefnx {[@var{data}, @var{fields}] =} fetch (@dots{})
-##
-## Download stock data from a connection.
-##
-## @var{fields} are the data fields to download and must come from the
-## set
-## @itemize @bullet
-## @item "Symbol"
-## @item "Last"
-## @item "Date"
-## @item "Time"
-## @item "Change"
-## @item "Open"
-## @item "High",
-## @item "Low"
-## @item "Volume"
-## @end itemize
-##
-## As an output, @var{fields} may be different than your request.  This
-## is because there is mapping of field names from the data source to
-## the output, and what is returned is the source mapping to allow
-## validation.
-##
-## @var{date} is the date string or datenum for the requested data.  If
-## you enter today's date, you will get yesterday's data. @var{fromdate}
-## and @var{todate} allow you to specify a date range for the data.
-##
-## @var{period} (default: "d") allows you to select the period for the
-## data which can be any of the below as long as they are supported by
-## the associated backend.
-## @itemize @bullet
-## @item 'd': daily
-## @item 'w': weekly (Yahoo only)
-## @item 'm': monthly (Yahoo only)
-## @item 'v': dividends (Yahoo only)
-## @end itemize
-##
-## @seealso{yahoo, google}
-## @end deftypefn
-
-## FIXME: Actually use the proxy info if given in the connection.
-## FIXME: Do not ignore the fields input.
-
-function [data fields] = fetch (conn=[], symbol="", varargin)
-
-  fields   = {"Symbol", "Last", "Date", "Time", "Change", "Open", ...
-              "High", "Low", "Volume"};
-  fromdate = [];
-  todate   = [];
-  period   = "d";
-
-  firstdate = datenum (1900, 1, 1);
-  lastdate  = today ();
-
-  if isempty (conn)
-    ## By default, use yahoo now since it's the only connection
-    ## currently available.
-    conn = yahoo ();
-  endif
-  if isempty (symbol)
-    error ("The ticker symbol must be given")
-  elseif ! ischar (symbol)
-    error ("The symbol must be either a string")
-  endif
-  for i = 1:numel (varargin)
-    if ischar (varargin{i}) && (length (varargin{i}) == 1)
-      period = varargin{i};
-    elseif iscellstr (varargin{i}) || ischar (varargin{i})
-      ## if it's a character and it's a valid date, make it into our
-      ## dates
-      if ischar (varargin{i})
-        thisdate = [];
-        try
-          thisdate = datenum (varargin{i});
-          if isempty (fromdate)
-            fromdate = thisdate;
-          endif
-          todate = thisdate;
-        end_try_catch
-      endif
-      if isempty (thisdate)
-        fields = varargin{i};
-        warning ("Fields are currently ignored and all data is returned")
-      endif
-      thisdate = [];
-    elseif isnumeric (varargin{i})
-      ## it must be our dates
-      if isempty (fromdate)
-        fromdate = varargin{i};
-      endif
-      todate = varargin{i};
-    else
-      error ("Invalid input for argument %d", i + 2)
-    endif
-  endfor
-
-  if isempty (fromdate)
-    fromdate = firstdate;
-    todate   = lastdate;
-  endif
-
-  if strcmpi (conn.url, "http://quote.yahoo.com")
-    [data fields] = fetch_yahoo (conn, symbol, fromdate, todate, period);
-  elseif strcmpi (conn.url, "http://finance.google.com")
-    [data fields] = fetch_google (conn, symbol, fromdate, todate, period);
-  else
-    error ("Unrecgonized connection type")
-  endif
-
-endfunction
-
-%!shared fgood, dgood
-%! fgood = {"Date", "Open", "High", "Low", "Close", "Volume", "Adj Close"};
-%! dgood = [732501,34.77,34.87,34.25,34.62,15515400,34.62;
-%!          732500,33.87,34.77,33.72,34.63,16354300,34.63;
-%!          732499,34.64,34.97,34.03,34.12,13585700,34.12;
-%!          732498,34.25,35.08,34.20,34.60,16086700,34.60;
-%!          732494,34.76,34.85,34.22,34.44,9861600,34.44];
-%!test
-%! [d f] = fetch(yahoo(), "yhoo", "01-Jul-2005", "10-Jul-2005");
-%! assert(d, dgood, eps);
-%! assert(f, fgood, eps);
-
-## The test below fails because yahoo gives a different volume on 732498
-##%!xtest
-##%! [d f] = fetch(yahoo(), "yhoo", "01-Jul-2005", "10-Jul-2005", "w");
-##%! assert(d, dgood(4:5,:), eps);
-##%! assert(f, fgood, eps);
+## Copyright (C) 2008 Bill Denney <bill@denney.ws>
+##
+## This program is free software; you can redistribute it and/or modify it under
+## the terms of the GNU General Public License as published by the Free Software
+## Foundation; either version 3 of the License, or (at your option) any later
+## version.
+##
+## This program is distributed in the hope that it will be useful, but WITHOUT
+## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+## details.
+##
+## You should have received a copy of the GNU General Public License along with
+## this program; if not, see <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {@var{data} =} fetch (@var{conn}, @var{symbol})
+## @deftypefnx {@var{data} =} fetch (@dots{}, @var{fields})
+## @deftypefnx {@var{data} =} fetch (@dots{}, @var{date})
+## @deftypefnx {@var{data} =} fetch (@dots{}, @var{fromdate}, @var{todate})
+## @deftypefnx {@var{data} =} fetch (@dots{}, @var{period})
+## @deftypefnx {[@var{data}, @var{fields}] =} fetch (@dots{})
+##
+## Download stock data from a connection.
+##
+## @var{fields} are the data fields to download and must come from the
+## set
+## @itemize @bullet
+## @item "Symbol"
+## @item "Last"
+## @item "Date"
+## @item "Time"
+## @item "Change"
+## @item "Open"
+## @item "High",
+## @item "Low"
+## @item "Volume"
+## @end itemize
+##
+## As an output, @var{fields} may be different than your request.  This
+## is because there is mapping of field names from the data source to
+## the output, and what is returned is the source mapping to allow
+## validation.
+##
+## @var{date} is the date string or datenum for the requested data.  If
+## you enter today's date, you will get yesterday's data. @var{fromdate}
+## and @var{todate} allow you to specify a date range for the data.
+##
+## @var{period} (default: "d") allows you to select the period for the
+## data which can be any of the below as long as they are supported by
+## the associated backend.
+## @itemize @bullet
+## @item 'd': daily
+## @item 'w': weekly (Yahoo only)
+## @item 'm': monthly (Yahoo only)
+## @item 'v': dividends (Yahoo only)
+## @end itemize
+##
+## @seealso{yahoo, google}
+## @end deftypefn
+
+## FIXME: Actually use the proxy info if given in the connection.
+## FIXME: Do not ignore the fields input.
+
+function [data fields] = fetch (conn=[], symbol="", varargin)
+
+  fields   = {"Symbol", "Last", "Date", "Time", "Change", "Open", ...
+              "High", "Low", "Volume"};
+  fromdate = [];
+  todate   = [];
+  period   = "d";
+
+  firstdate = datenum (1900, 1, 1);
+  lastdate  = today ();
+
+  if isempty (conn)
+    ## By default, use yahoo now since it's the only connection
+    ## currently available.
+    conn = yahoo ();
+  endif
+  if isempty (symbol)
+    error ("The ticker symbol must be given")
+  elseif ! ischar (symbol)
+    error ("The symbol must be either a string")
+  endif
+  for i = 1:numel (varargin)
+    if ischar (varargin{i}) && (length (varargin{i}) == 1)
+      period = varargin{i};
+    elseif iscellstr (varargin{i}) || ischar (varargin{i})
+      ## if it's a character and it's a valid date, make it into our
+      ## dates
+      if ischar (varargin{i})
+        thisdate = [];
+        try
+          thisdate = datenum (varargin{i});
+          if isempty (fromdate)
+            fromdate = thisdate;
+          endif
+          todate = thisdate;
+        end_try_catch
+      endif
+      if isempty (thisdate)
+        fields = varargin{i};
+        warning ("Fields are currently ignored and all data is returned")
+      endif
+      thisdate = [];
+    elseif isnumeric (varargin{i})
+      ## it must be our dates
+      if isempty (fromdate)
+        fromdate = varargin{i};
+      endif
+      todate = varargin{i};
+    else
+      error ("Invalid input for argument %d", i + 2)
+    endif
+  endfor
+
+  if isempty (fromdate)
+    fromdate = firstdate;
+    todate   = lastdate;
+  endif
+
+  if strcmpi (conn.url, "http://quote.yahoo.com")
+    [data fields] = fetch_yahoo (conn, symbol, fromdate, todate, period);
+  elseif strcmpi (conn.url, "http://finance.google.com")
+    [data fields] = fetch_google (conn, symbol, fromdate, todate, period);
+  else
+    error ("Unrecgonized connection type")
+  endif
+
+endfunction
+
+%!shared fgood, dgood
+%! fgood = {"Date", "Open", "High", "Low", "Close", "Volume", "Adj Close"};
+%! dgood = [732501,34.77,34.87,34.25,34.62,15515400,34.62;
+%!          732500,33.87,34.77,33.72,34.63,16354300,34.63;
+%!          732499,34.64,34.97,34.03,34.12,13585700,34.12;
+%!          732498,34.25,35.08,34.20,34.60,16086700,34.60;
+%!          732494,34.76,34.85,34.22,34.44,9861600,34.44];
+%!test
+%! [d f] = fetch(yahoo(), "yhoo", "01-Jul-2005", "10-Jul-2005");
+%! assert(d, dgood, eps);
+%! assert(f, fgood, eps);
+
+## The test below fails because yahoo gives a different volume on 732498
+##%!xtest
+##%! [d f] = fetch(yahoo(), "yhoo", "01-Jul-2005", "10-Jul-2005", "w");
+##%! assert(d, dgood(4:5,:), eps);
+##%! assert(f, fgood, eps);
diff -r 5dcc545b4a62 -r 4d3d4a5b8ab0 inst/google.m
--- a/inst/google.m	Fri Sep 06 13:19:54 2013 +0200
+++ b/inst/google.m	Fri Sep 06 13:22:13 2013 +0200
@@ -1,44 +1,44 @@
-## Copyright (C) 2008 Bill Denney <bill@denney.ws>
-##
-## This program is free software; you can redistribute it and/or modify it under
-## the terms of the GNU General Public License as published by the Free Software
-## Foundation; either version 3 of the License, or (at your option) any later
-## version.
-##
-## This program is distributed in the hope that it will be useful, but WITHOUT
-## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-## details.
-##
-## You should have received a copy of the GNU General Public License along with
-## this program; if not, see <http://www.gnu.org/licenses/>.
-
-## -*- texinfo -*-
-## @deftypefn {Function File} {@var{conn} =} google ()
-## @deftypefnx {Function File} {@var{conn} =} google (@var{URL}, @var{ipaddress}, @var{port})
-##
-## Prepare a Google connection for the fetch command to get Google
-## historical quote data.
-##
-## If given, the @var{URL} must be "http://finance.google.com".  The
-## @var{ipaddress} and @var{port} is the proxy ipaddress and port. These
-## parameters are currently ignored (with a warning if given).
-##
-## @seealso{fetch, yahoo}
-## @end deftypefn
-
-## FIXME: Actually use the proxy info if given.
-
-function conn = google (url="http://finance.google.com", ipaddr="", port=[])
-
-  if ! strcmpi (url, "http://finance.google.com")
-    error ("url must be 'http://finance.google.com'")
-  elseif ! (isempty (ipaddr) && isempty (port))
-    warning ("Proxy information is currently ignored")
-  endif
-
-  conn.url  = url;
-  conn.ip   = ipaddr;
-  conn.port = port;
-
-endfunction
+## Copyright (C) 2008 Bill Denney <bill@denney.ws>
+##
+## This program is free software; you can redistribute it and/or modify it under
+## the terms of the GNU General Public License as published by the Free Software
+## Foundation; either version 3 of the License, or (at your option) any later
+## version.
+##
+## This program is distributed in the hope that it will be useful, but WITHOUT
+## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+## details.
+##
+## You should have received a copy of the GNU General Public License along with
+## this program; if not, see <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {@var{conn} =} google ()
+## @deftypefnx {Function File} {@var{conn} =} google (@var{URL}, @var{ipaddress}, @var{port})
+##
+## Prepare a Google connection for the fetch command to get Google
+## historical quote data.
+##
+## If given, the @var{URL} must be "http://finance.google.com".  The
+## @var{ipaddress} and @var{port} is the proxy ipaddress and port. These
+## parameters are currently ignored (with a warning if given).
+##
+## @seealso{fetch, yahoo}
+## @end deftypefn
+
+## FIXME: Actually use the proxy info if given.
+
+function conn = google (url="http://finance.google.com", ipaddr="", port=[])
+
+  if ! strcmpi (url, "http://finance.google.com")
+    error ("url must be 'http://finance.google.com'")
+  elseif ! (isempty (ipaddr) && isempty (port))
+    warning ("Proxy information is currently ignored")
+  endif
+
+  conn.url  = url;
+  conn.ip   = ipaddr;
+  conn.port = port;
+
+endfunction
diff -r 5dcc545b4a62 -r 4d3d4a5b8ab0 inst/private/fetch_google.m
--- a/inst/private/fetch_google.m	Fri Sep 06 13:19:54 2013 +0200
+++ b/inst/private/fetch_google.m	Fri Sep 06 13:22:13 2013 +0200
@@ -1,101 +1,101 @@
-## Copyright (C) 2008 Bill Denney <bill@denney.ws>
-##
-## This program is free software; you can redistribute it and/or modify it under
-## the terms of the GNU General Public License as published by the Free Software
-## Foundation; either version 3 of the License, or (at your option) any later
-## version.
-##
-## This program is distributed in the hope that it will be useful, but WITHOUT
-## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-## details.
-##
-## You should have received a copy of the GNU General Public License along with
-## this program; if not, see <http://www.gnu.org/licenses/>.
-
-## -*- texinfo -*-
-## @deftypefn {[@var{data} @var{fields}] =}
-##  fetch_google (@var{conn}, @var{symbol}, @var{fromdate}, @var{todate}, @var{period})
-##
-## Download stock data from google. (Helper for fetch.)
-##
-## @var{fields} are the data fields returned by Google.
-##
-## @var{fromdate} and @var{todate} is the date datenum for the requested
-## date range.  If you enter today's date, you will get yesterday's
-## data.
-##
-## @var{period} (default: "d") allows you to select the period for the
-## data which can be any of
-## @itemize @bullet
-## @item 'd': daily
-## @end itemize
-##
-## @seealso{google, fetch}
-## @end deftypefn
-
-## FIXME: Actually use the proxy info if given in the connection.
-## FIXME: Do not ignore the fields input.
-
-function [data fields] = fetch_google (conn=[], symbol="",
-                                          fromdate, todate, period="d")
-  if strcmpi(period, "w")
-    error("Google Financial no longer supports weekly stock data");
-  endif
-  periods = struct("d", "daily");
-  if strcmpi (conn.url, "http://finance.google.com")
-    fromdatestr = datestr (fromdate);
-    todatestr   = datestr (todate);
-    ## http://finance.google.com/finance/historical?q=T&startdate=Sep+1%2C+2007&enddate=Aug+31%2C+2008&histperiod=weekly&output=csv
-    geturl = sprintf (["http://finance.google.com/finance/" ...
-                       "historical?" ...
-                       "q=%s&startdate=%s&enddate=%s&" ...
-                       "histperiod=%s&output=csv"],
-                      symbol, fromdatestr, todatestr, periods.(period));
-    ## FIXME: This would be more efficient if csv2cell could work on
-    ## strings instead of files.
-    [f, success, msg] = urlwrite (geturl, tmpnam ());
-    if ! success
-      error (["Could not write Google data to tmp file:" ...
-              "\n%s\nURL was:\n%s"], msg, geturl)
-    endif
-    d = csv2cell (f);
-    d{1,1} = d{1,1}(4:end); # Remove byte order mark (BOM)
-    unlink(f);
-    ## Pull off the header
-    fields = d(1,:);
-    d(1,:) = [];
-    ## Put the dates into datenum format
-    data = [datenum(datevec(d(:,1), "dd-mmm-yy")), ...
-            cell2mat(d(:,2:end))];
-    ## Note that google appears to have an off-by-one error in
-    ## returning historical data, so make sure that we only return the
-    ## requested data and not what Google sent.
-    data((data(:,1) < fromdate) | (data(:,1) > todate), :) = [];
-  else
-    error ("Non-google connection passed to google fetch")
-  endif
-
-endfunction
-
-%!shared fgood, dgood, wgood
-%! fgood = {"Date", "Open", "High", "Low", "Close", "Volume"};
-%! dgood = [732501,34.77,34.87,34.25,34.62,15520553;
-%!          732500,33.87,34.77,33.72,34.63,16360297;
-%!          732499,34.64,34.97,34.03,34.12,13694806;
-%!          732498,34.25,35.08,34.20,34.60,16103029;
-%!          732494,34.76,34.85,34.22,34.44,9875220];
-%! wgood = [732501,34.25,35.08,33.72,34.62,60859400;
-%!          732494,35.88,36.24,34.22,34.44,67132100];
-%!test
-%! [d f] = fetch_google (google(), "yhoo", 732494, 732501, "d");
-%! assert(d, dgood, eps);
-%! assert(f, fgood, eps);
-## test that the automatic period works
-%!test
-%! [d f] = fetch_google (google(), "yhoo", 732494, 732501);
-%! assert(d, dgood, eps);
-%! assert(f, fgood, eps);
-## Test that weekly fails
-%!test
-%! fail ('fetch_google (google(), "yhoo", 732494, 732501, "w")', ".*weekly.*")
+## Copyright (C) 2008 Bill Denney <bill@denney.ws>
+##
+## This program is free software; you can redistribute it and/or modify it under
+## the terms of the GNU General Public License as published by the Free Software
+## Foundation; either version 3 of the License, or (at your option) any later
+## version.
+##
+## This program is distributed in the hope that it will be useful, but WITHOUT
+## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+## details.
+##
+## You should have received a copy of the GNU General Public License along with
+## this program; if not, see <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {[@var{data} @var{fields}] =}
+##  fetch_google (@var{conn}, @var{symbol}, @var{fromdate}, @var{todate}, @var{period})
+##
+## Download stock data from google. (Helper for fetch.)
+##
+## @var{fields} are the data fields returned by Google.
+##
+## @var{fromdate} and @var{todate} is the date datenum for the requested
+## date range.  If you enter today's date, you will get yesterday's
+## data.
+##
+## @var{period} (default: "d") allows you to select the period for the
+## data which can be any of
+## @itemize @bullet
+## @item 'd': daily
+## @end itemize
+##
+## @seealso{google, fetch}
+## @end deftypefn
+
+## FIXME: Actually use the proxy info if given in the connection.
+## FIXME: Do not ignore the fields input.
+
+function [data fields] = fetch_google (conn=[], symbol="",
+                                          fromdate, todate, period="d")
+  if strcmpi(period, "w")
+    error("Google Financial no longer supports weekly stock data");
+  endif
+  periods = struct("d", "daily");
+  if strcmpi (conn.url, "http://finance.google.com")
+    fromdatestr = datestr (fromdate);
+    todatestr   = datestr (todate);
+    ## http://finance.google.com/finance/historical?q=T&startdate=Sep+1%2C+2007&enddate=Aug+31%2C+2008&histperiod=weekly&output=csv
+    geturl = sprintf (["http://finance.google.com/finance/" ...
+                       "historical?" ...
+                       "q=%s&startdate=%s&enddate=%s&" ...
+                       "histperiod=%s&output=csv"],
+                      symbol, fromdatestr, todatestr, periods.(period));
+    ## FIXME: This would be more efficient if csv2cell could work on
+    ## strings instead of files.
+    [f, success, msg] = urlwrite (geturl, tmpnam ());
+    if ! success
+      error (["Could not write Google data to tmp file:" ...
+              "\n%s\nURL was:\n%s"], msg, geturl)
+    endif
+    d = csv2cell (f);
+    d{1,1} = d{1,1}(4:end); # Remove byte order mark (BOM)
+    unlink(f);
+    ## Pull off the header
+    fields = d(1,:);
+    d(1,:) = [];
+    ## Put the dates into datenum format
+    data = [datenum(datevec(d(:,1), "dd-mmm-yy")), ...
+            cell2mat(d(:,2:end))];
+    ## Note that google appears to have an off-by-one error in
+    ## returning historical data, so make sure that we only return the
+    ## requested data and not what Google sent.
+    data((data(:,1) < fromdate) | (data(:,1) > todate), :) = [];
+  else
+    error ("Non-google connection passed to google fetch")
+  endif
+
+endfunction
+
+%!shared fgood, dgood, wgood
+%! fgood = {"Date", "Open", "High", "Low", "Close", "Volume"};
+%! dgood = [732501,34.77,34.87,34.25,34.62,15520553;
+%!          732500,33.87,34.77,33.72,34.63,16360297;
+%!          732499,34.64,34.97,34.03,34.12,13694806;
+%!          732498,34.25,35.08,34.20,34.60,16103029;
+%!          732494,34.76,34.85,34.22,34.44,9875220];
+%! wgood = [732501,34.25,35.08,33.72,34.62,60859400;
+%!          732494,35.88,36.24,34.22,34.44,67132100];
+%!test
+%! [d f] = fetch_google (google(), "yhoo", 732494, 732501, "d");
+%! assert(d, dgood, eps);
+%! assert(f, fgood, eps);
+## test that the automatic period works
+%!test
+%! [d f] = fetch_google (google(), "yhoo", 732494, 732501);
+%! assert(d, dgood, eps);
+%! assert(f, fgood, eps);
+## Test that weekly fails
+%!test
+%! fail ('fetch_google (google(), "yhoo", 732494, 732501, "w")', ".*weekly.*")
diff -r 5dcc545b4a62 -r 4d3d4a5b8ab0 inst/private/fetch_yahoo.m
--- a/inst/private/fetch_yahoo.m	Fri Sep 06 13:19:54 2013 +0200
+++ b/inst/private/fetch_yahoo.m	Fri Sep 06 13:22:13 2013 +0200
@@ -1,98 +1,98 @@
-## Copyright (C) 2008 Bill Denney <bill@denney.ws>
-##
-## This program is free software; you can redistribute it and/or modify it under
-## the terms of the GNU General Public License as published by the Free Software
-## Foundation; either version 3 of the License, or (at your option) any later
-## version.
-##
-## This program is distributed in the hope that it will be useful, but WITHOUT
-## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-## details.
-##
-## You should have received a copy of the GNU General Public License along with
-## this program; if not, see <http://www.gnu.org/licenses/>.
-
-## -*- texinfo -*-
-## @deftypefn {[@var{data} @var{fields}] =}
-##  fetch_yahoo (@var{conn}, @var{symbol}, @var{fromdate}, @var{todate}, @var{period})
-##
-## Download stock data from yahoo. (Helper for fetch.)
-##
-## @var{fields} are the data fields returned by Yahoo.
-##
-## @var{fromdate} and @var{todate} is the date datenum for the requested
-## date range.  If you enter today's date, you will get yesterday's
-## data.
-##
-## @var{period} (default: "d") allows you to select the period for the
-## data which can be any of
-## @itemize @bullet
-## @item 'd': daily
-## @item 'w': weekly
-## @item 'm': monthly
-## @item 'v': dividends
-## @end itemize
-##
-## @seealso{yahoo, fetch}
-## @end deftypefn
-
-## FIXME: Actually use the proxy info if given in the connection.
-## FIXME: Do not ignore the fields input.
-
-function [data fields] = fetch_yahoo (conn=[], symbol="",
-                                          fromdate, todate, period="d")
-
-  if strcmpi (conn.url, "http://quote.yahoo.com")
-    fromdate = datevec (fromdate);
-    todate   = datevec (todate);
-    geturl   = sprintf (["http://ichart.finance.yahoo.com/table.csv" ...
-                         "?s=%s&d=%d&e=%d&f=%d&g=%s&a=%d&b=%d&c=%d&" ...
-                         "ignore=.csv"],
-                         symbol, todate(2)-1, todate(3), todate(1),
-                         period,
-                         fromdate(2)-1, fromdate(3), fromdate(1));
-    ## FIXME: This would be more efficient if csv2cell could work on
-    ## strings instead of files.
-    [f, success, msg] = urlwrite (geturl, tmpnam ());
-    if ! success
-      error ("Could not write Yahoo data to tmp file:\n%s", msg)
-    endif
-    d = csv2cell (f);
-    unlink(f);
-    ## Pull off the header
-    fields = d(1,:);
-    d(1,:) = [];
-    dates  = strvcat (d(:,1));
-    dates  = datenum(str2num(dates(:,1:4)),
-                     str2num(dates(:,6:7)),
-                     str2num(dates(:,9:10)));
-    data   = [dates, cell2mat(d(:,2:end))];
-  else
-    error ("Non-yahoo connection passed to yahoo fetch")
-  endif
-
-endfunction
-
-%!shared fgood, dgood
-%! fgood = {"Date", "Open", "High", "Low", "Close", "Volume", "Adj Close"};
-%! dgood = [732501,34.77,34.87,34.25,34.62,15515400,34.62;
-%!          732500,33.87,34.77,33.72,34.63,16354300,34.63;
-%!          732499,34.64,34.97,34.03,34.12,13585700,34.12;
-%!          732498,34.25,35.08,34.20,34.60,16086700,34.60;
-%!          732494,34.76,34.85,34.22,34.44,9861600,34.44];
-%!test
-%! [d f] = fetch_yahoo (yahoo(), "yhoo", 732494, 732501, "d");
-%! assert(d, dgood, eps);
-%! assert(f, fgood, eps);
-## test that the automatic period works
-%!test
-%! [d f] = fetch_yahoo (yahoo(), "yhoo", 732494, 732501);
-%! assert(d, dgood, eps);
-%! assert(f, fgood, eps);
-
-## The test below fails because yahoo gives a different volume on 732498
-##%!xtest
-##%! [d f] = fetch(yahoo(), "yhoo", "01-Jul-2005", "10-Jul-2005", "w");
-##%! assert(d, dgood(4:5,:), eps);
-##%! assert(f, fgood, eps);
+## Copyright (C) 2008 Bill Denney <bill@denney.ws>
+##
+## This program is free software; you can redistribute it and/or modify it under
+## the terms of the GNU General Public License as published by the Free Software
+## Foundation; either version 3 of the License, or (at your option) any later
+## version.
+##
+## This program is distributed in the hope that it will be useful, but WITHOUT
+## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+## details.
+##
+## You should have received a copy of the GNU General Public License along with
+## this program; if not, see <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {[@var{data} @var{fields}] =}
+##  fetch_yahoo (@var{conn}, @var{symbol}, @var{fromdate}, @var{todate}, @var{period})
+##
+## Download stock data from yahoo. (Helper for fetch.)
+##
+## @var{fields} are the data fields returned by Yahoo.
+##
+## @var{fromdate} and @var{todate} is the date datenum for the requested
+## date range.  If you enter today's date, you will get yesterday's
+## data.
+##
+## @var{period} (default: "d") allows you to select the period for the
+## data which can be any of
+## @itemize @bullet
+## @item 'd': daily
+## @item 'w': weekly
+## @item 'm': monthly
+## @item 'v': dividends
+## @end itemize
+##
+## @seealso{yahoo, fetch}
+## @end deftypefn
+
+## FIXME: Actually use the proxy info if given in the connection.
+## FIXME: Do not ignore the fields input.
+
+function [data fields] = fetch_yahoo (conn=[], symbol="",
+                                          fromdate, todate, period="d")
+
+  if strcmpi (conn.url, "http://quote.yahoo.com")
+    fromdate = datevec (fromdate);
+    todate   = datevec (todate);
+    geturl   = sprintf (["http://ichart.finance.yahoo.com/table.csv" ...
+                         "?s=%s&d=%d&e=%d&f=%d&g=%s&a=%d&b=%d&c=%d&" ...
+                         "ignore=.csv"],
+                         symbol, todate(2)-1, todate(3), todate(1),
+                         period,
+                         fromdate(2)-1, fromdate(3), fromdate(1));
+    ## FIXME: This would be more efficient if csv2cell could work on
+    ## strings instead of files.
+    [f, success, msg] = urlwrite (geturl, tmpnam ());
+    if ! success
+      error ("Could not write Yahoo data to tmp file:\n%s", msg)
+    endif
+    d = csv2cell (f);
+    unlink(f);
+    ## Pull off the header
+    fields = d(1,:);
+    d(1,:) = [];
+    dates  = strvcat (d(:,1));
+    dates  = datenum(str2num(dates(:,1:4)),
+                     str2num(dates(:,6:7)),
+                     str2num(dates(:,9:10)));
+    data   = [dates, cell2mat(d(:,2:end))];
+  else
+    error ("Non-yahoo connection passed to yahoo fetch")
+  endif
+
+endfunction
+
+%!shared fgood, dgood
+%! fgood = {"Date", "Open", "High", "Low", "Close", "Volume", "Adj Close"};
+%! dgood = [732501,34.77,34.87,34.25,34.62,15515400,34.62;
+%!          732500,33.87,34.77,33.72,34.63,16354300,34.63;
+%!          732499,34.64,34.97,34.03,34.12,13585700,34.12;
+%!          732498,34.25,35.08,34.20,34.60,16086700,34.60;
+%!          732494,34.76,34.85,34.22,34.44,9861600,34.44];
+%!test
+%! [d f] = fetch_yahoo (yahoo(), "yhoo", 732494, 732501, "d");
+%! assert(d, dgood, eps);
+%! assert(f, fgood, eps);
+## test that the automatic period works
+%!test
+%! [d f] = fetch_yahoo (yahoo(), "yhoo", 732494, 732501);
+%! assert(d, dgood, eps);
+%! assert(f, fgood, eps);
+
+## The test below fails because yahoo gives a different volume on 732498
+##%!xtest
+##%! [d f] = fetch(yahoo(), "yhoo", "01-Jul-2005", "10-Jul-2005", "w");
+##%! assert(d, dgood(4:5,:), eps);
+##%! assert(f, fgood, eps);
diff -r 5dcc545b4a62 -r 4d3d4a5b8ab0 inst/yahoo.m
--- a/inst/yahoo.m	Fri Sep 06 13:19:54 2013 +0200
+++ b/inst/yahoo.m	Fri Sep 06 13:22:13 2013 +0200
@@ -1,44 +1,44 @@
-## Copyright (C) 2008 Bill Denney <bill@denney.ws>
-##
-## This program is free software; you can redistribute it and/or modify it under
-## the terms of the GNU General Public License as published by the Free Software
-## Foundation; either version 3 of the License, or (at your option) any later
-## version.
-##
-## This program is distributed in the hope that it will be useful, but WITHOUT
-## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-## details.
-##
-## You should have received a copy of the GNU General Public License along with
-## this program; if not, see <http://www.gnu.org/licenses/>.
-
-## -*- texinfo -*-
-## @deftypefn {Function File} {@var{conn} =} yahoo ()
-## @deftypefnx {Function File} {@var{conn} =} yahoo (@var{URL}, @var{ipaddress}, @var{port})
-##
-## Prepare a Yahoo connection for the fetch command to get Yahoo
-## historical quote data.
-##
-## If given, the @var{URL} must be "http://quote.yahoo.com".  The
-## @var{ipaddress} and @var{port} is the proxy ipaddress and port. These
-## parameters are currently ignored (with a warning if given).
-##
-## @seealso{fetch, google}
-## @end deftypefn
-
-## FIXME: Actually use the proxy info if given.
-
-function conn = yahoo (url="http://quote.yahoo.com", ipaddr="", port=[])
-
-  if ! strcmpi (url, "http://quote.yahoo.com")
-    error ("url must be 'http://quote.yahoo.com'")
-  elseif ! (isempty (ipaddr) && isempty (port))
-    warning ("Proxy information is currently ignored")
-  endif
-
-  conn.url  = url;
-  conn.ip   = ipaddr;
-  conn.port = port;
-
-endfunction
+## Copyright (C) 2008 Bill Denney <bill@denney.ws>
+##
+## This program is free software; you can redistribute it and/or modify it under
+## the terms of the GNU General Public License as published by the Free Software
+## Foundation; either version 3 of the License, or (at your option) any later
+## version.
+##
+## This program is distributed in the hope that it will be useful, but WITHOUT
+## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+## details.
+##
+## You should have received a copy of the GNU General Public License along with
+## this program; if not, see <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {@var{conn} =} yahoo ()
+## @deftypefnx {Function File} {@var{conn} =} yahoo (@var{URL}, @var{ipaddress}, @var{port})
+##
+## Prepare a Yahoo connection for the fetch command to get Yahoo
+## historical quote data.
+##
+## If given, the @var{URL} must be "http://quote.yahoo.com".  The
+## @var{ipaddress} and @var{port} is the proxy ipaddress and port. These
+## parameters are currently ignored (with a warning if given).
+##
+## @seealso{fetch, google}
+## @end deftypefn
+
+## FIXME: Actually use the proxy info if given.
+
+function conn = yahoo (url="http://quote.yahoo.com", ipaddr="", port=[])
+
+  if ! strcmpi (url, "http://quote.yahoo.com")
+    error ("url must be 'http://quote.yahoo.com'")
+  elseif ! (isempty (ipaddr) && isempty (port))
+    warning ("Proxy information is currently ignored")
+  endif
+
+  conn.url  = url;
+  conn.ip   = ipaddr;
+  conn.port = port;
+
+endfunction
