Description Usage Arguments Details Value Author(s) References Examples
View source: R/getSymbols.ALFRED.R
R access to the latest observation(s) of the vintages of over seven hundred thousand data series accessible via the St. Louis Federal Reserve Bank's ALFRED (Archival FRED: Federal Reserve Bank of St. Louis's _Archiva_L _Federal _Reserve _Economic _Data) system https://alfred.stlouisfed.org/; collects and displays data from the ALFRED vintages that (as seen by a public user during a zone of time at FRED), 'per observation date', are the 1st appearance of an observation date (and its datum).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | getFRED(
Symbols,
env = parent.frame(),
return.class = "xts",
returnIndex = "ObservationDate",
VintageId = "Latest",
nameVintagedId = F,
EarliestLastUpdDate = NULL,
LookBack = "Beginning",
VintagesPerQuery = 12,
FullOldestVintageData = F,
DataSheet = F,
allowParallel = F,
MaxParallel = NULL,
...
)
getALFRED(
Symbols,
env = parent.frame(),
return.class = "xts",
returnIndex = "ObservationDate",
VintageId = NULL,
nameVintagedId = F,
EarliestLastUpdDate = NULL,
LookBack = 3,
VintagesPerQuery = 12,
FullOldestVintageData = F,
DataSheet = F,
allowParallel = F,
MaxParallel = NULL,
...
)
getSymbols.ALFRED(
Symbols,
env,
return.class = "xts",
returnIndex = "ObservationDate",
VintageId = NULL,
nameVintagedId = F,
version = 1L,
EarliestLastUpdDate = NULL,
LookBack = 3,
VintagesPerQuery = 12,
FullOldestVintageData = F,
DataSheet = F,
allowParallel = F,
MaxParallel = NULL,
...
)
|
Symbols |
a character vector specifying the names of each symbol to be loaded (from R CRAN package quantmod function getSymbols) |
env |
where to create objects. (.GlobalEnv) (from R CRAN package quantmod function getSymbols) |
return.class |
class of returned object (from R CRAN package quantmod function getSymbols) |
returnIndex |
one of "ObservationDate" (row element date) or "LastUpdatedDate" (vintage date). Default is ObservationDate". Note, in FRED and ALFRED an 'observation date'(row element date) is not the 'date of measurement'. The 'observation date' (typically) is (observes) the beginning of the 'date range' (its period: ObservationDate + Frequency). The LastUpdatedDate date, that is, the vintage date of publication, is after the the period has completed, that is after ObservationDate + Frequency. See DATE(observation date a.k.a row element date), Frequency, Date Range, and 'Last Updated' in in https://fred.stlouisfed.org/data/RECPROUSM156N.txt |
VintageId |
download one specific vintage. User input is expected to be a vector of one. The vintage can be the form of a character or Date. Default is NULL meaning try to download all vintages that have not been restricted elsewhere. To otherwise restrict by range, see the parameter EarliestLastUpdDate. To see the available vintage dates, use the function vinDates. The parameter value can also be "Latest". |
nameVintagedId |
add the VintageId (or the most recent "Last Updated" date VintageId) to the name of what is returned |
EarliestLastUpdDate |
character or Date. Earliest date that is before or 'at' the vintage 'Last Updated' date in the past that a user may wish to query upon. Default is NULL (no restriction). This is useful in the situation when the user already owns prior data, and just wants just some recent data. Internally, this just subtracts off some 'Last Updated' dates from the results of calling the function vinDates (xor vintages that have been entered by the user throught the paramter VintageId). Note, if this paramter EarliestLastUpdDate, is used, the tail the returned data (older data) is not expected to be correct. The reason is that, not all vintages can bee seen, so the clause is no longer true: "the first available datam per specific date of all vintages". |
LookBack |
how deep in periods to look back for the latest observation in all of the non-oldest vintages. Meant to use with datasets with a wide range of time between the Measurement interval and the Validity interval. From the 'Last Updated' date try to peek back in time to the 1st vintage with a published tail 'Date Range' date that is within variable 'LookBack' periods. If the periodicy is "day" and, just after a three(3) day holiday weekend, to reach back from a Tuesday to a Friday, parameter LookBack is increased to a minimum value of 4. Default is 3. Increase this value if much time exists between the tail date of 'Date Range' and the 'Last Updated' date: meaning zero(0) observations exist in the LookBack period. The R CRAN package xts function periodicity determines the period of time. This function is meant to minimize server-side CPU and disk I/O. . Value can be "Beginning". "Beginning" means lookback to the start. |
VintagesPerQuery |
number of vintages per HTTPS GET. A.k.a the number of vintages per sheet. Default is 12. Common maximum is 12. Value can be "Max". Practical experience has performed with 192. The maximum may be different during different with not-a-known reason. This parameter exists to enhance performance by limiting the number of trips to the server. This parameter is sometimes (but not often) better than the parameter allowParallel. On many occasions when using this parameter with values greater than 12, the requested data is missing from the returned data set. |
FullOldestVintageData |
if TRUE, then also return the oldest vintage data and keep(prepend) its data. Default is FALSE. Useful when 'as much data as possible' is important. |
DataSheet |
if TRUE, then also return all of the vintages in an xts attribute 'DataSheet'. Default is FALSE. Useful for debugging. Useful as a tool of doing more (future) coding or user-end research. |
allowParallel |
if TRUE, then collect groups of 'sheets of VintagesPerQuery vintages' in parallel. Default is FALSE. (Improved) performance will vary: this is more useful on (more data points) weekly data or daily data. Because this is a server side activity, the number of parallel processes does NOT depend on the local machine CPUs. |
MaxParallel |
if allowParallel is TRUE, then set the maximum number of parallel processes. Default is NULL (no limit). If this parameter is NULL, then the approximate maximum number of parallel processes is 'unique(ceiling(seq_along(vinDates(SYMBOL)/VintagesPerQuery)))' where the vector from vinDates(SYMBOL) may be reduced by limiting data using EarliestLastUpdDate. Good choices of this parameter may depend on, the amount of the client host hardware CPU and memory. |
... |
additional parameters |
version |
Integer. Default is 1L. Version of data ever to be assigned to that point in time: version = 1L means "original (first(1st)) version"; version = 2L means "first(1st) revision"; version = 3L "second(2nd) revision", and so on. |
Downloads Symbols to specified environment (variable env) from 'research.stlouisfed.org'. This method is not to be called directly, instead a call to R CRAN packages quantmod function getSymbols(Symbols,src='ALFRED') will in turn call this method.
The St. Louis Federal Reserve Bank's FRED allows a specific data series to be revised(overwritten) called vintages with different data while and displaying new objservation dates and re-using the same observation dates of the same observations from a 'Date Range'. The series author very often replaces the each data series with a new one. This replacement activity is data obscurity. The past data series of FRED is not easily accessible. The past data series are accessible through ALFRED. The current data series of FRED and the past data series (that are no longer seen in FRED) are called vintages. The original non-rewritten data is called the 1st vintage. The (first) revision is called the 2nd vintage. The (second) next revision is called the 3rd vintage and so-on. The last revision is displayed at FRED. This function collects and displays data from the ALFRED vintages that 'per observation date', are the 1st appearance of an observation date (and its datum).
The functions is a tool in the process of examining a FRED data series of interest and identifying FRED data series that 'per observation' date and its datam, have much change compared to the next vintage's (same) 'per observation' date and its (potentially different) datum. The process is looking for FRED data series that have vintages with highly volatile data, relative to the (same) 'per observation' date and its (potentially different) datum.
as R CRAN package quantmod function getSymbols. See the parameter returnIndex for a user-choice the xts objects returned index
Andre Mikulec (adapted from the original code)
Jeffrey A. Ryan (original code that is inside the R CRAN package quantmod function getSymbols.FRED)
Blame of the code of the R CRAN package quantmod function getSymbols and getSymbols.FRED https://github.com/joshuaulrich/quantmod/blame/master/R/getSymbols.R
ALFRED: Capturing data as it happens, Katrina Stierholz, Director of Library and Information Services, Federal Reserve Bank of St. Louis, https://alfred.stlouisfed.org/docs/alfred_capturing_data.pdf
Richard G. Anderson, "Replicability, Real-Time Data, and the Science of Economic Research: FRED, ALFRED, and VDC," Federal Reserve Bank of St. Louis Review, January/February 2006, pp. 81-94. https://doi.org/10.20955/r.88.81-94 https://files.stlouisfed.org/files/htdocs/publications/review/06/01/Anderson.pdf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | ## Not run:
# Smoothed U.S. Recession Probabilities (RECPROUSM156N)
# Source: Piger, Jeremy Max, Chauvet, Marcelle
# https://fred.stlouisfed.org/series/RECPROUSM156N
# and
# https://fred.stlouisfed.org/data/RECPROUSM156N.txt
library(quantmod)
getSymbols("RECPROUSM156N", src = "FRED")
[1] "RECPROUSM156N"
# src = "ALFRED"
getALFRED("RECPROUSM156N", LookBack = 4)
Processing vintages: 2012-09-04 ... 2013-08-08 of RECPROUSM156N.vin
Processing vintages: 2013-09-03 ... 2014-08-01 of RECPROUSM156N.vin
Processing vintages: 2014-09-01 ... 2015-08-06 of RECPROUSM156N.vin
Processing vintages: 2015-09-01 ... 2016-08-05 of RECPROUSM156N.vin
Processing vintages: 2016-09-01 ... 2017-08-03 of RECPROUSM156N.vin
Processing vintages: 2017-09-01 ... 2018-08-01 of RECPROUSM156N.vin
Processing vintages: 2018-09-03 ... 2019-09-03 of RECPROUSM156N.vin
Processing vintages: 2019-10-01 ... 2020-09-01 of RECPROUSM156N.vin
Processing vintages: 2020-10-01 ... 2020-10-01 of RECPROUSM156N.vin
[1] "RECPROUSM156N.vin"
## End(Not run)
## Not run:
getSymbols("RECPROUSM156N", src = "ALFRED", LookBack = 4)
Processing vintages: 2012-09-04 ... 2013-08-08 of RECPROUSM156N.vin
Processing vintages: 2013-09-03 ... 2014-08-01 of RECPROUSM156N.vin
Processing vintages: 2014-09-01 ... 2015-08-06 of RECPROUSM156N.vin
Processing vintages: 2015-09-01 ... 2016-08-05 of RECPROUSM156N.vin
Processing vintages: 2016-09-01 ... 2017-08-03 of RECPROUSM156N.vin
Processing vintages: 2017-09-01 ... 2018-08-01 of RECPROUSM156N.vin
Processing vintages: 2018-09-03 ... 2019-09-03 of RECPROUSM156N.vin
Processing vintages: 2019-10-01 ... 2020-09-01 of RECPROUSM156N.vin
Processing vintages: 2020-10-01 ... 2020-10-01 of RECPROUSM156N.vin
[1] "RECPROUSM156N.vin"
# Note, the distance between the graphic date and the 'Last Updated' date
# is about two(2) months, so one may shift the graphic to the right
# by two(2) months to get the real story.
#
# See: 'Date Range' and
'Last Updated' in https://fred.stlouisfed.org/data/RECPROUSM156N.txt
# See: vinDates("RECPROUSM156N")
#
# rough way to get the real story based on 'Date Range' and "Last Updated"
# after the last observation date the "Last Updated" published date is two(2) months later
# the returnIndex parameter (default) is "ObservationDate (row/element date)
index(RECPROUSM156N) <- index(RECPROUSM156N) + 61
index(RECPROUSM156N.vin) <- index(RECPROUSM156N.vin) + 61
dygraphs::dygraph(merge(RECPROUSM156N, RECPROUSM156N.vin))
# better way to get the real story
# instead make observation dates to be the "Last Updated" published date.
# the returnIndex parameter is "LastUpdatedDate" (vintage published date)
getSymbols("RECPROUSM156N", src = "ALFRED", returnIndex = "LastUpdatedDate", LookBack = 4)
dygraphs::dygraph(merge(RECPROUSM156N, RECPROUSM156N.vin))
# get the most recent vintage (most recent VintageId)
getALFRED("RECPROUSM156N", VintageId = "Latest", LookBack = "Beginning", verbose = T)
# same
getFRED("RECPROUSM156N", verbose = T)
downloading RECPROUSM156N .....
Processing vintages: 2020-10-01 ... 2020-10-01 of RECPROUSM156N.vin
# get just this exact vintage data and all of its data
# To get all of the data the user chooses look back 100 years)
# (This series has known periods of one month long in duration)
getSymbols("RECPROUSM156N", src = "ALFRED", VintageId = "2020-01-02", LookBack = 1200)
# get this exact vintage and all of its data
getSymbols("RECPROUSM156N", src = "ALFRED", VintageId = "2020-01-02",
LookBack = "Beginning")
# get just this exact vintage and its most recent data (some of its data)
# that is restricted by the default short time Lookback
getSymbols("RECPROUSM156N", src = "ALFRED", VintageId = "2020-01-02")
# same as above, and include the VintageId in the column name
getSymbols("RECPROUSM156N", src = "ALFRED", VintageId = "2020-01-02", nameVintagedId = T)
# Processing vintages: 2020-01-02 ... 2020-01-02 of RECPROUSM156N.vin.2020.01.02
# [1] "RECPROUSM156N.vin.2020.01.02"
RECPROUSM156N.vin.2020.01.02
# RECPROUSM156N.vin.2020.01.02
# 2019-10-01 1.82
# 2019-11-01 0.60
# if too much time in periods exists between the
# tail date of the 'Date Range' and 'Last Updated' date,
# then increase LookBack from three(3) (default) to four(4) or greater.
getSymbols("RECPROUSM156N", src = "ALFRED", LookBack = 4)
# for debugging, or further work one may include the vintages
getSymbols("RECPROUSM156N", src = "ALFRED", LookBack = 4, DataSheet = T)
# note: the user-chosen 'viewer' may have a limit on the number of columns displayed
View(data.frame(xtsAttributes(RECPROUSM156N.vin)$DataSheet))
# see the names of all columns
# The column names format are the same names and formate as returned
# by ALFRED (and unmodified) '(old)FRED series identifier'_YYYYMMDD.
# YYYYMMDD is the 'Last Updated' date;
# YYYY is the year and
# MM is the month in number values of 01 through 12
# representing January through December.
# DD is the daty of the month from 01 through the last day of that month.
colnames(data.frame(xtsAttributes(RECPROUSM156N.vin)$DataSheet))
# From (above) https://fred.stlouisfed.org/data/RECPROUSM156N.txt
# one knows that Frequency is 'Monthly'.
# To get all of the data (in all of the vintages), set the
# LookBack to be a 'high value' e.g. perhaps, 100 years
# (1200: 12 months x 100 years)
# (In this specific FRED series case, observation dates start in 1967)
getSymbols("RECPROUSM156N", src = "ALFRED", LookBack = 1200, DataSheet = T)
View(data.frame(xtsAttributes(RECPROUSM156N.vin)$DataSheet))
# prepend (include) the data of the very first vintage in the head of the data
getSymbols("RECPROUSM156N", src = "ALFRED", LookBack = 4, FullOldestVintageData = T)
# use R CRAN package doParallel to query simultaneously
getSymbols("RECPROUSM156N", src = "ALFRED", LookBack = 4, allowParallel = T)
# quarterly
# ALFRED was still in development in 2006;
# moreover, not all FRED data series were being placed into ALFRED.
# Some FRED data series were/is popular enough and important enough
# to be worth the effort to back-load its data into ALFRED.
# Gross Domestic Product (GDP)
# is in ALFRED with 'Last Updated' dates that start in the year of 1991.
getSymbols("GDP", src = "ALFRED")
# noticably faster
getSymbols("GDP", src = "ALFRED", allowParallel = T)
# weekly
# Weekly, Ending Friday (reported during the following Wednesday)
# Chicago Fed National Financial Conditions Index (NFCI)
getSymbols("NFCI", src = "ALFRED")
# daily
# Effective Federal Funds Rate (EFFR)
getSymbols("EFFR", src = "ALFRED")
# sometimes better
# In the case of using a large 'VintagesPerQuery',
# very often much requested data is missing from the returned data.
getSymbols("EFFR", src = "ALFRED", VintagesPerQuery = 192)
# often better
getSymbols("EFFR", src = "ALFRED", allowParallel = T, MaxParallel = 8)
# the user does not want to query upon vintages before vintage at the
# 'Last Updated' date of "2020-01-01"
# Note, if this parameter is used, the tail the returned data (older data)
# is not expected to be correct. The reason is that, not all vintages can bee seen,
# so the clause is no longer true:
# "the first available datam per specific date of all vintages".
getSymbols("EFFR", src = "ALFRED", EarliestLastUpdDate = "2020-01-01")
# better (just recent data)
getSymbols("EFFR", src = "ALFRED", EarliestLastUpdDate = Sys.Date() - 35)
# first(1st) revision (and its last updated date (publication date))
getSymbols("GDP", src = "ALFRED", LookBack = 5, DataSheet = T, version = 2, returnIndex = "LastUpdatedDate")
head(GDP.vin,7)
This is correct. Four(4) first revisions (version = 2)
(but for four different observation dates (not shown))
were published on 1991-12-20.
GDP.vin
1991-12-20 5570.5 # correct
1991-12-20 5557.5 # correct
1991-12-20 5589.0 # correct
1991-12-20 5652.6 # correct
1991-12-20 5709.2
1992-02-28 5746.7
1992-05-29 5817.5
# get multiple Symbols in one user execution
# using R CRAN package quantmod function getSymbols
getSymbols("RECPROUSM156N;GDP", src = "ALFRED", EarliestLastUpdDate = "2020-01-01",
nameVintagedId = T)
# only the last Symbol is printed back to the console
# Moreover, both series are actually there.
# get multiple Symbols in one user execution
mapply(
function(Symbol, VintageId, LookBack) {
getSymbols(Symbol, src = "ALFRED", VintageId = VintageId,
nameVintagedId = T,
LookBack = LookBack, env = .GlobalEnv)
},
c("RECPROUSM156N", "RECPROUSM156N", "GDP"), # Symbol
c("2020-01-02", "2019-01-02", "2019-12-20"), # VintageId
c(18, 12, 6) # LookBack # months and quarters
)
Processing vintages: 2020-01-02 ... 2020-01-02 of RECPROUSM156N.vin.2020.01.02
Processing vintages: 2019-01-02 ... 2019-01-02 of RECPROUSM156N.vin.2019.01.02
Processing vintages: 2019-12-20 ... 2019-12-20 of GDP.vin.2019.12.20
RECPROUSM156N RECPROUSM156N GDP
"RECPROUSM156N.vin.2020.01.02" "RECPROUSM156N.vin.2019.01.02" "GDP.vin.2019.12.20"
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.