D*****l 发帖数: 554 | 1 Merging Current Stock Quotes with Historical Prices
By systematicinvestor
#*****************************************************************
# Load historical data
#******************************************************************
load.packages('quantmod')
tickers = spl('VTI,EFA,SHY')
data <- new.env()
getSymbols(tickers, src = 'yahoo', from = '1980-01-01', env = data, auto.
assign = T)
for(i in ls(data)) data[[i]] = adjustOHLC(data[[i]], use.Adjusted=T)
bt.prep(data)
# look at the data
last(data$prices, 2)
#*****************************************************************
# Load historical data
#******************************************************************
load.packages('quantmod')
tickers = spl('VTI,EFA,SHY')
data <- new.env()
getSymbols(tickers, src = 'yahoo', from = '1980-01-01', env = data, auto.
assign = T)
for(i in ls(data)) data[[i]] = adjustOHLC(data[[i]], use.Adjusted=T)
# current quotes logic
quotes = getQuote(tickers)
for(i in ls(data))
if( last(index(data[[i]])) < as.Date(quotes[i, 'Trade Time']) ) {
data[[i]] = rbind( data[[i]], make.xts(quotes[i, spl('Open,High,
Low,Last,Volume,Last')],
as.Date(quotes[i, 'Trade Time'])))
}
bt.prep(data)
# look at the data
last(data$prices, 2)
http://www.r-bloggers.com/merging-current-stock-quotes-with-his | M*P 发帖数: 6456 | 2 赞!
【在 D*****l 的大作中提到】 : Merging Current Stock Quotes with Historical Prices : By systematicinvestor : #***************************************************************** : # Load historical data : #****************************************************************** : load.packages('quantmod') : tickers = spl('VTI,EFA,SHY') : data <- new.env() : getSymbols(tickers, src = 'yahoo', from = '1980-01-01', env = data, auto. : assign = T)
|
|