我正在尝试使用highfrequency中的“aggregatePrice”函数。让
2008-01-04 09:30:27 "193.71"
2008-01-04 09:30:28 "193.59"
2008-01-04 09:30:29 "193.445"
2008-01-04 09:30:30 "193.38"
2008-01-04 09:30:31 "193.34"
2008-01-04 09:30:33 "193.52"
2008-01-04 09:30:34 "193.58"
2008-01-04 09:30:35 "193.63"
2008-01-04 09:30:36 "193.47"
2008-01-04 09:30:37 "193.26"
2008-01-04 09:30:38 "193.26"
2008-01-04 09:30:39 "193.23"
2008-01-04 09:30:40 "193.15"
2008-01-04 09:30:41 "193.16"
2008-01-04 09:30:46 "192.86"
2008-01-04 09:30:47 "192.85"
2008-01-04 09:30:49 "192.83"
2008-01-04 09:30:50 "193"
2008-01-04 09:30:51 "192.985"
2008-01-04 09:30:54 "193.045"
2008-01-04 09:30:56 "192.735"
2008-01-04 09:30:57 "192.85"
2008-01-04 09:30:59 "192.68"
2008-01-04 09:31:01 "192.99"
2008-01-04 09:31:02 "192.795"
2008-01-04 09:31:03 "192.69"
2008-01-04 09:31:05 "193.02"
2008-01-04 09:31:07 "193.47"
2008-01-04 09:31:10 "192.99"
2008-01-04 09:31:12 "192.89"
是原始数据和
2008-01-04 09:30:00 193.710
2008-01-04 09:30:36 193.470
2008-01-04 09:30:45 193.160
2008-01-04 09:30:54 193.045
2008-01-04 09:31:03 192.690
2008-01-04 09:31:12 192.890
9秒聚合数据。
根据手册默认情况下,前一个刻度聚合完成。在先前的滴答聚合的情况下,对于on =“seconds”/“minutes”/“hours”,返回的系列的元素具有例如时间戳09:35:00
包含截至该点的最后一次观察,不包括09:35:00
本身的值。 marketclose是一个例外(默认情况下为16:00:00
ET),其中16:00:00
的观察值包含在区间内,因为这是纽约证券交易所交易日的结束。
我的问题是:
为什么汇总数据会提供2008-01-04 09:30:36 193.470
而不是2008-01-04 09:30:36 193.63
09:30:36
。带有时间戳09:30:36
的返回系列的元素包含截至该点的最后一次观察,不包括193.63
本身的值,因此价格不应为#load data
data("sample_tdata");
#aggregate price data to the 30 second frequency
head(sample_tdata$PRICE)
head(aggregatePrice(sample_tdata$PRICE,on="secs",k=9));
?
拜托,也许这对你来说很简单,但我真的不明白。
命令是:
def count_even(obj):
"""
Return the number of even numbers in obj or sublists of obj
if obj is a list. Otherwise, if obj is a number, return 1
if it is an even number and 0 if it is an odd number.
@param int|list obj: object to count even numbers from
@rtype: int
>>> count_even(3)
0
>>> count_even(16)
1
>>> count_even([1, 2, [3, 4], 5])
2
"""
count = 0
if isinstance(obj, int):
if obj % 2 == 0:
return 1
else:
return 0
else:
for i in obj:
count += count_even(i)
return new