# Overview

This package is meant to make it easy to download daily data from
the Yahoo Finance website (https://finance.yahoo.com )

In order to use the package, a time-series dataset must already be
open when calling the functions contained here. 

The four functions this package offers are:

## yahoo_price

simple importer. It requires

- a string parameter with the ticker
- an optional scalar with the kind of interpolation required (0: none,
  1: repeat, 2: linear interpolation)
- an optional scalar with the aggregation method required for
  non-daily frequencies (0: average (default), 1: min, 2: max).
  
It returns the adjusted price as a series. If the currently open
dataset is monthly, quarterly or weekly, the function retrieves daily
data and then aggregates them using the method chosen by the user.

Note that, at the monthly frequency, this may produce different
results from what you would get by downloading the data from Yahoo
directly at the monthly level, since Yahoo's convention is to use the
first day of the month as representative of the whole month. If this
is what you need, you may use "getYahoo" package by Yi-Nung Yang.

As for weekly data, gretl weekly datasets identify the current
observation by a date, that could be any day of the week. The policy I
followed in this package is to compute the aggregate using the data
for the week **a given observation is in** (with the convention that
weeks start on Sundays). Therefore, if your weekly dataset contains
the date 2026-09-16 (which was a Wednesday), you will get the same
series as if your dataset was Monday-based (so you'd have an
observation for 2026-09-14) or Friday-based (so you'd have an
observation for 2026-09-18).


## yahoo_portfolio

convenience function to call yahoo_price repeatedly. It takes three arguments:
- a string array with the tickers to import
- an optional scalar with the kind of interpolation required (0: none,
  1: repeat, 2: linear interpolation)
- an optional scalar with the aggregation method required for
  non-daily frequencies (0: average (default), 1: min, 2: max).
  
it returns a list with the adjusted prices, suitably renamed. Tickers
for which download failed are NOT included in the returned list.

## yahoo_full

It requires one parameter with the ticker and  fetches the whole set
of available series (volume, open/close, hi/lo, adjusted) as a
list. Requires daily data.

## yahoo_dividends

takes the ticker string as argument and returns the dividend
series. Requires daily data.

# Error codes

Of course, sometimes thing may go wrong. The error messages you can
get are:

* 101: there was some problem in fetching data from the Yahoo website,
  either a network error or the website is down;
* 102: some data were in fact downloaded, but their format isn't
  parseable JSON;
* 400: the ticker you requested isn't listed in the selected sample
  (for example, Apple in the 1960s);
* 404: the ticker you requested wasn't found;
* 1001: no valid dates
* 1002: no valid data for the currently selected sample


# Changelog

3.9 -> 3.10: Bugfix release: fix the yahoo_price() function for weekly
data. Increase version requirement to 2023b.

3.8 -> 3.9: Bugfix release: robustify the yahoo_dividends() function
with respect to possible internet failure.

3.7 -> 3.8: Support monthly and quarterly frequencies for
yahoo_price() and yahoo_portfolio(). Use the --tempfile option to
"outfile" to avoid collisions between escape sequences and Windows
file paths. Fix a bug in the yahoo_dividends() function.

3.6 -> 3.7: (Internal) Switch to readfile() instead of curl() for
the yahoo_dividends() function to avoid the "Too many requests" error.

3.5 -> 3.6: Better error handling and documentation. Switch to markdown for
help text.

3.4 -> 3.5: New "get_portfolio" convenience function. A few bugfixes.
Simplify handling of path separator (use "/" for all OSes).

3.3 -> 3.4: Workarounds for strptime() and strftime() working differently on
Unix and Win, which made data prior to 1/1/1970 impossible to download on
windows machines.

3.2 -> 3.3: Handle cases when an existing ticker was not listed in the current
sample (eg: Apple in the 1960s).

3.1 -> 3.2: Robustify with respect to national decimal separators.

3.0 -> 3.1: A few internal changes to handle better weird tickers. No API
change.

2.0 -> 3.0: Adaptation to the new JSON-based yahoo API (loosely based on the
yfinance python package by Ran Aroussi); use the new native function strptime
instead of badly coded hansl equivalent

1.0 -> 2.0: Introduced dependency on the "extra" package; adaptation to the new
yahoo API
