Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 尝试将股票行情与调整后的价格匹配_R - Fatal编程技术网

R 尝试将股票行情与调整后的价格匹配

R 尝试将股票行情与调整后的价格匹配,r,R,我有下面的脚本,可以很好地提取历史股票价格,但我似乎无法得到一份按日期列出的股票价格调整后的清单。我得到25只股票,标题如下:$df.tickers,price.open,price.high,price.low,price.close,volume-price.adjusted 有一件事我搞不清楚,当我键入'out'时,我得到数据集,但当我键入dim(out)时,我得到一个空值。那没有任何意义。无论如何,我正在尝试从下面的链接运行代码 这是我正在使用的代码 library(BatchGetS

我有下面的脚本,可以很好地提取历史股票价格,但我似乎无法得到一份按日期列出的股票价格调整后的清单。我得到25只股票,标题如下:$df.tickers,price.open,price.high,price.low,price.close,volume-price.adjusted

有一件事我搞不清楚,当我键入'out'时,我得到数据集,但当我键入dim(out)时,我得到一个空值。那没有任何意义。无论如何,我正在尝试从下面的链接运行代码

这是我正在使用的代码

library(BatchGetSymbols)
library(sqldf)
library(dplyr)

# set dates
first.date <- Sys.Date() - 360
last.date <- Sys.Date()

# set tickers
tickers <- c('MMM','ABT','ABBV','ABMD',
'ACN','ATVI','AYI','ADBE','AMD','AAP',
'AES','AET','AMG','AFL','A','APD','AKAM',
'ALK','ALB','ARE','ALXN','ALGN','ALLE','AGN','ADS')

out <- BatchGetSymbols(tickers = tickers, 
                         first.date = first.date,
                         last.date = last.date, 
                         cache.folder = file.path(tempdir(), 
                                                  'BGS_Cache') ) # cache in tempdir()

# dim(out$df.tickers)
# 6175 10


# After downloading the data, we can check the success of the process for each ticker. 
# Notice that the last ticker does not exist in yahoo finance or google and therefore 
# results in an error. All information regarding the download process is provided in the dataframe df.control:

# print(out$df.control)
price_adjusted <- as.data.frame(out)
price_final <- subset(price_adjusted, select = c(df.control.ticker, df.tickers.price.adjusted, df.tickers.ref.date))
#    df_final <- subset(price_final, df.control.ticker == 'MMM', select = c("df.control.ticker","df.tickers.price.adjusted","df.tickers.ref.date"))
库(BatchGetSymbols)
库(sqldf)
图书馆(dplyr)
#确定日期

first.date本教程使用的是“xts”时间序列格式的数据。要将您的数据转换为这样的数据

library(BatchGetSymbols)
library(tidyr)
library(quantmod)

# set dates
first.date <- Sys.Date() - 360
last.date <- Sys.Date()

# set tickers
tickers <- c('MMM','ABT','ABBV','ABMD',
             'ACN','ATVI','AYI','ADBE','AMD','AAP',
             'AES','AET','AMG','AFL','A','APD','AKAM',
             'ALK','ALB','ARE','ALXN','ALGN','ALLE','AGN','ADS')

out <- BatchGetSymbols(tickers = tickers, 
                       first.date = first.date,
                       last.date = last.date, 
                       cache.folder = file.path(tempdir(), 
                                                'BGS_Cache') ) 
out<-out$df.tickers
out<-out[,c("ref.date","ticker", "price.adjusted")]
q <- spread(out, ticker, price.adjusted)
portfolioPrices <- xts(q[,-1], order.by=q[,1])
库(BatchGetSymbols)
图书馆(tidyr)
图书馆(quantmod)
#确定日期

我们的课程是什么
dim
将给出数据帧或矩阵等的尺寸,但不会给出例如列表。你能说得更具体些吗?是的,我想你知道了一些事情。我想我需要将列表转换为数据帧。我这样做了:您不需要使用sqldf库来运行教程。谷歌金融选项已经失效,你能告诉我们你是如何获得数据的吗?你使用雅虎还是其他来源?您可以使用
dput
输出一些示例数据给我们看。哇!我以为我把密码贴出来了。现在太累了。好的,我刚刚用我正在测试的代码更新了我的原始帖子。基本上,我正在尝试从我发布的URL运行脚本。我正在尝试为每日历史调整价格添加一个不同的来源。这很有效!谢谢!!我只需要在重复数据消除记录中添加一行。我不知道为什么会有被骗者来,但出于某种原因,前一天又在重复。这修复了它:重复数据消除