我正在探索在' http://www.moneycontrol.com/stocks/histstock.php?ex=N&sc_id=MU01&mycomp=Maruti%20Suzuki'可以直接用R填充,然后直接将结果导入R工作区
感谢任何人是否有任何指针。谢谢你的时间。
答案 0 :(得分:0)
我不确定为什么你在近一个月内没有得到任何答复。也许你需要考虑你发布的特定链接以外的选项。
library(BatchGetSymbols)
first.date <- Sys.Date()-365
last.date <- Sys.Date()
df.SP500 <- GetSP500Stocks()
tickers <- df.SP500$tickers
l.out <- BatchGetSymbols(tickers = tickers,
first.date = first.date,
last.date = last.date)
print(l.out$df.control)
print(l.out$df.tickers)
另外,您知道,您可以使用quantmod获取各种历史股票数据。
以下是一些例子。
###############################################################################
# Load Systematic Investor Toolbox (SIT)
###############################################################################
con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb'))
source(con)
close(con)
#*****************************************************************
# Load historical data
#******************************************************************
load.packages('quantmod')
stock.folder = 'c:\\Stocks\\Data\\'
tickers = spl('UUP,EMB,HYG')
data <- new.env()
# load historical data, select data load method
data.load.method = 'basic'
if(data.load.method == 'basic') {
# quantmod - getSymbols
getSymbols(tickers, src = 'yahoo', from = '1970-01-01', env = data, auto.assign = T)
}else if(data.load.method == 'basic.local') {
# if you saved yahoo historical price files localy
getSymbols.sit(tickers, src = 'yahoo', from = '1980-01-01', env = data, auto.assign = T, stock.folder = stock.folder)
}else if(data.load.method == 'custom.local') {
# custom format historical price files
for(n in tickers) {
data[[n]] = read.xts(paste(stock.folder, n, '.csv', sep=''), format='%m/%d/%Y')
}
}else if(data.load.method == 'custom.one.file') {
# read from one csv file, column headers are tickers
filename = 'hex.csv'
all.data = read.xts(paste(stock.folder, filename, sep=''), format='%m/%d/%Y')
for(n in names(all.data)) {
data[[n]] = all.data[,n]
colnames(data[[n]]) = 'Close'
data[[n]]$Adjusted = data[[n]]$Open = data[[n]]$High = data[[n]]$Low = data[[n]]$Close
}
}
# prepare data for back test
for(i in ls(data)) data[[i]] = adjustOHLC(data[[i]], use.Adjusted=T)
bt.prep(data, align='remove.na')
#*****************************************************************
# Code Strategies
#******************************************************************
prices = data$prices
n = ncol(prices)
models = list()
# find period ends
period.ends = endpoints(prices, 'months')
period.ends = period.ends[period.ends > 0]
obj = portfolio.allocation.helper(data$prices, period.ends=period.ends, lookback.len = 250,
min.risk.fns = list(EW=equal.weight.portfolio,
RP=risk.parity.portfolio,
MV=min.var.portfolio,
MC=min.corr.portfolio)
)
models = create.strategies(obj, data)$models
#*****************************************************************
# Create Report
#******************************************************************
strategy.performance.snapshoot(models, T)
https://systematicinvestor.wordpress.com/2013/06/01/loading-historical-stock-data/
https://chrisconlan.com/download-daily-data-every-sp-500-stock-r/