View source: R/update_prices.R
update_prices | R Documentation |
Fetches and manages a collection of Yahoo OHLCV data.
update_prices( asset_symbols, append_asset_symbols = TRUE, include_index_symbols = "" )
asset_symbols |
a character vector of asset symbols |
append_asset_symbols |
boolean, if TRUE, OHLCV series specified in |
include_index_symbols |
a character vector indicating specific indexes whose components will be added to |
The idea behind this function is to continually update a store of cached price data on a VPS.
On the server, run update_prices
once to populate the prices
directory, then set the function to run via a cronjob.
It would be optimal to run daily updates pre- or post-market, and at a time which would not conflict with server maintenance reboots (if scheduled).
The OHLCV data is downloaded and stored in ./prices
.
If existing symbols are again fed to asset_symbols
and the function is rerun, only the most recent data will be added to the cached OHLCV data in ./prices
.
If a symbol is not included in asset_symbols
and update_prices
is run, its OHLCV data will be removed from ./prices
, unless append_asset_symbols = TRUE
.
If asset_symbols
is left blank, OHLCV already downloaded will be updated.
Optionally, components for an index can also be included (see Examples).
Each time a fetch attempt is made, a record is stored in ./log/fetch_attempts.rds
. Likewise, when a symbol fails to download, a record is stored in ./log/fetch_errors.rds
.
IMPORTANT: Without append = TRUE
, the OHLCV series in the prices
directory will be completely replaced by the symbols indicated in asset_symbols
## Not run: if(interactive()){ ## run through each of the below examples in order ## download OHLCV series for each major index ETF update_prices(asset_symbols = c('SPY', 'QQQ', 'DIA', 'IWM')) ## remove IWM OHLCV data from ./prices update_prices(asset_symbols = c('SPY', 'QQQ', 'DIA')) ## add IWM again and update prices for SPY, QQQ, DIA ## note that, unlike above, this doesn't remove OHLCV previously downloaded update_prices(asset_symbols = 'IWM', append_asset_symbols = TRUE) ## update prices for all symbols update_prices() ## update prices for all symbols and add all Dow stocks update_prices(include_index_symbols = 'DOW') ## remove the Dow stocks update_prices(asset_symbols = c('SPY', 'QQQ', 'DIA', 'IWM')) } ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.