update_prices: update_prices

View source: R/update_prices.R

update_pricesR Documentation

update_prices

Description

Fetches and manages a collection of Yahoo OHLCV data.

Usage

update_prices(
  asset_symbols,
  append_asset_symbols = TRUE,
  include_index_symbols = ""
)

Arguments

asset_symbols

a character vector of asset symbols

append_asset_symbols

boolean, if TRUE, OHLCV series specified in asset_symbols will be added to those already downloaded (see Note), Default: TRUE

include_index_symbols

a character vector indicating specific indexes whose components will be added to asset_symbols, Default: ”

Details

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.

Note

IMPORTANT: Without append = TRUE, the OHLCV series in the prices directory will be completely replaced by the symbols indicated in asset_symbols

Examples

## 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)

causality-loop/updateprices documentation built on Aug. 31, 2022, 5:36 a.m.