數據源

雅虎盤中歷史下載時間戳

  • November 16, 2015

雅虎提供了一個 API 來下載歷史盤中數據,但我無法理解數據的時間戳。網址請求是:

Format : http://chartapi.finance.yahoo.com/instrument/1.0/[TICKER]/chartdata;type=quote;range=[days]d/csv

Example: http://chartapi.finance.yahoo.com/instrument/1.0/GOOG/chartdata;type=quote;range=1d/csv

它返回如下數據:

uri:/instrument/1.0/GOOG/chartdata;type=quote;range=1d/csv
ticker:goog
Company-Name:Alphabet Inc.
Exchange-Name:NMS
unit:MIN
timezone:EST
currency:USD
gmtoffset:-18000
previous_close:731.2300
Timestamp:1447425000,1447448400
labels:1447426800,1447430400,1447434000,1447437600,1447441200,1447444800,1447448400
values:Timestamp,close,high,low,open,volume
close:717.0000,730.7000
high:717.0000,731.1500
low:716.7300,729.7850
open:717.0000,731.0000
volume:0,104700
1447425030,727.2000,728.8550,727.2000,728.7500,48300
1447425096,727.8440,728.2200,727.8440,727.8850,0
1447425120,728.7300,729.0000,727.2900,728.4800,25100
1447425183,729.3100,729.8900,728.1550,729.2465,20000
1447425247,729.4500,731.1500,729.4500,730.4893,8900
1447425301,729.4500,730.4000,729.0600,729.3200,4500
1447425418,730.4250,730.7000,729.0200,730.0500,5100

它在每一行中的數據形式為:時間戳、收盤價、最高價、最低價、開盤價、成交量。

時間戳似乎是 Unix 時間戳(自 1970 年以來的秒數)。此網路文章證實了這一點:https ://www.daniweb.com/programming/software-development/threads/260694/how-to-process-timestamp-in-chartapi-finance-yahoo-com

我的問題是我從 Unix 時間戳轉換時得到的值,它們看起來非常接近我期望的時間戳,每分鐘一次,但是隨機量。

2015-11-13 09:30:58
2015-11-13 09:31:15
2015-11-13 09:32:06
2015-11-13 09:33:00
2015-11-13 09:34:03

我的問題是,是否有其他人成功地弄清楚如何將時間戳正確轉換為正確的值。

———–根據R程式碼建議更新——-

我嘗試了下面的 R 程式碼,並在奇數非偶數分鐘上得到了類似的時間戳結果。這是使用此 getYahoo.intraday() 函式和 GOOG 程式碼的輸出:

> p <- getYahoo.intraday('goog','1')
> head(p)
                      Open    High      Low   Close Volume
2015-11-13 09:31:02 728.410 728.420 727.1601 727.830  18300
2015-11-13 09:32:06 728.960 729.000 727.2900 728.450  11200
2015-11-13 09:33:00 729.240 729.890 728.1550 728.460  15300
2015-11-13 09:34:03 729.450 730.820 729.4500 729.846  15300
2015-11-13 09:35:14 729.450 729.588 729.0600 729.070   3900
2015-11-13 09:36:58 730.425 730.700 729.0200 730.050   5100

你的答案似乎有點不對勁。這是一個回答你問題的前一個文章;

https://stackoverflow.com/questions/3682748/converting-unix-timestamp-string-to-readable-date-in-python

此外,您可以使用此工具進行交叉驗證;http://www.epochconverter.com/

使用 R(程式碼:yahoo ticker,nDays:最大 15):

getYahoo.intraday <- function(tiker,nDays){
url <- paste("http://chartapi.finance.yahoo.com/instrument/1.0/",tiker,"/chartdata;type=quote;range=",nDays,"d/csv",sep="")
nskip <- as.numeric(nDays)+17
data <- read.csv(url, skip=nskip, header=F, stringsAsFactors=F)
data.xts <- xts(data[,-1],as.POSIXct(data$V1,origin="1970-01-01",tz="GMT"))
indexTZ(data.xts) <- "America/New_York"
colnames(data.xts) <- c("Open", "High", "Low", "Close", "Volume")
options(warn=-1)
data.xts
}


library(quantmod)
p <- getYahoo.intraday("SPY","15")
tail(p)

引用自:https://quant.stackexchange.com/questions/21750