Downloading from remote data source
Three eponymous methods are provided for downloading free data, from Yahoo Finance (yahoo) the Federal Reserve St. Louis (fred) and the United Kingdom's Office for National Statistics (ons)
These methods take a string argument that represents the name of the desired data set to be downloaded.
These methods have default arguments. These defaults only apply when no argument is passed, otherwise the user is left with determining the correct name for the data of interest.
Yahoo
For the yahoo()
method, the default data is the S&P 500 end-of-day daily prices. That symbol is named ^GSPC
.
MarketData.yahoo
— Functionyahoo(symbol::AbstractString, opt::YahooOpt = YahooOpt())::TimeArray
yahoo(symbol::Symbol, opt::YahooOpt = YahooOpt())::TimeArray
This is a wrapper for downloading historical stock prices from Yahoo Finance.
The yahoo method takes a stock name in the form of a string and returns a TimeSeries.TimeArray
corresponding to the Yahoo Finance ticker. With no argument, the default historical time series is the S&P 500.
Examples
AAPL = yahoo(:AAPL)
SPX = yahoo("^GSPC")
NQ = yahoo("^IXIC")
julia> start = DateTime(2018, 1, 1)
2018-01-01T00:00:00
julia> yahoo(:AAPL, YahooOpt(period1 = start))
655×6 TimeArray{Float64,2,Date,Array{Float64,2}} 2018-01-02 to 2020-08-07
...
References
https://finance.yahoo.com
See Also
- fred() which accesses the St. Louis Federal Reserve financial and economic data sets.
- ons() which is a wrapper to download financial and economic time series data from the Office for National Statistics (ONS).
MarketData.YahooOpt
— Typestruct YahooOpt <: AbstractQueryOpt
period1 # the start time
period2 # the end time
interval # "1d", "1wk" or "1mo"
events # currently only `:history` supported
end
The Yahoo Finance HTTP API query object.
Examples
julia> t = Dates.now()
2020-08-09T01:38:04.735
julia> YahooOpt(period1 = t - Year(2), period2 = t)
YahooOpt{DateTime} with 4 entries:
:period1 => 1533778685
:period2 => 1596937085
:interval => "1d"
:events => :history
FRED
The default data for the fred()
method is CPIAUCNS
, which represents the Consumer Price Index for All Urban Consumers data.
ONS
For the ons()
method, the default data is the L522
timeseries from the MM23
dataset, which represents the Consumer Price Index including housing costs, in the UK. This is the ONS' headline monthly price inflation statistic.
MarketData.ons
— Functionons(timeseries::String="L522", dataset::String="MM23")::TimeArray
The ons() method is a wrapper to download financial and economic time series data from the Office for National Statistics (ONS).
The ons() method takes two string arguments corresponding to a dataset and timeseries code from the ONS database, to explore the database, you can use https://www.ons.gov.uk/timeseriestool. It returns the data in the TimeSeries.TimeArray data structure with additional information in the meta field. The data might include monthly values, quarterly averages and yearly averages, with column names monthly, quarterly and yearly. The timestamps are the first day of the period. When no argument is provided, the default dataset is the Consumer Price Index including housing costs (CPIH) which is the ONS’s headline measure of inflation.
Examples
UK_RPI = ("CHAW","MM23")
UK_CPI = ("D7BT","MM23")
UK_CPIH = ("L522","MM23")
References
https://www.ons.gov.uk/timeseriestool
See Also
- fred() which accesses the St. Louis Federal Reserve financial and economic data sets.
- yahoo() which is a wrapper from downloading financial time series for stocks from Yahoo Finance.