我试图对市场数据进行一些统计分析,并设法将交易平台的tick数据转换为python数据框,格式如下所示。
我需要进行一项测试,看看当天会话(09:30-16:15)多长时间等于或超过会议剩余时间(16:15 - 09:30)打印的高点或低点。有人可以帮我这个吗?
export default React.createClass({
change: function(){
console.log(this.props.classes);
},
render: function(){
return(
<div>
<select onChange = {this.change}>
{
Object.keys(this.props.classes).map((value, key) =>{
return <option key = {key}>{value}</option>
}
)}
</select>
</div>
)
}
});
期望的输出:
print (df.iloc[85:95])
Price bidVol askVol
2015-12-28 08:39:12.000000 2041.00 2 0
2015-12-28 08:39:12.001000 2041.00 1 0
2015-12-28 08:47:19.000000 2041.25 0 2
2015-12-28 09:18:00.999999 2040.25 0 5
2015-12-28 09:33:30.000000 2039.75 0 1
2015-12-28 09:35:58.000000 2039.75 0 5
2015-12-28 09:44:35.000000 2039.75 1 0
2015-12-28 09:58:39.999999 2039.00 0 1
2015-12-28 09:58:55.000000 2039.25 1 0
2015-12-28 10:02:59.000000 2038.50 1 0
我试试:
high 2015-12-28 True or False
low 2015-12-28 True or False
答案 0 :(得分:1)
您可以尝试:
import pandas as pd
#for all data remove iloc[85:95]
df = pd.read_hdf('tubus.h5').iloc[85:95]
print (df)
Price bidVol askVol
2015-12-28 08:39:12.000000 2041.00 2 0
2015-12-28 08:39:12.001000 2041.00 1 0
2015-12-28 08:47:19.000000 2041.25 0 2
2015-12-28 09:18:00.999999 2040.25 0 5
2015-12-28 09:33:30.000000 2039.75 0 1
2015-12-28 09:35:58.000000 2039.75 0 5
2015-12-28 09:44:35.000000 2039.75 1 0
2015-12-28 09:58:39.999999 2039.00 0 1
2015-12-28 09:58:55.000000 2039.25 1 0
2015-12-28 10:02:59.000000 2038.50 1 0
daystart = '9:30'
dayend = '16:14:59'
#filter day data, include start and end
day_session = df.between_time(daystart,dayend, include_start=True, include_end=True)
print (day_session.head())
Price bidVol askVol
2015-12-28 09:33:30.000000 2039.75 0 1
2015-12-28 09:35:58.000000 2039.75 0 5
2015-12-28 09:44:35.000000 2039.75 1 0
2015-12-28 09:58:39.999999 2039.00 0 1
2015-12-28 09:58:55.000000 2039.25 1 0
#filter night data, exclude start and end
night_session = df.between_time(dayend,daystart, include_start=False, include_end=False)
print (night_session.head())
Price bidVol askVol
2015-12-28 08:39:12.000000 2041.00 2 0
2015-12-28 08:39:12.001000 2041.00 1 0
2015-12-28 08:47:19.000000 2041.25 0 2
2015-12-28 09:18:00.999999 2040.25 0 5
#resample only column Price
#version above 0.18.0
df_day = day_session.Price.resample('D').ohlc()
df_night = night_session.Price.resample('D').ohlc()
#version bellow 0.18.0
#df_day = day_session.Price.resample('D', how='ohlc')
#df_night = night_session.Price.resample('D', how='ohlc')
#day data are longer as nightly, so you need reindex them
df_day = df_day.reindex(df_night.index)
print (df_day)
open high low close
2015-12-28 2039.75 2039.75 2038.5 2038.5
print (df_night)
open high low close
2015-12-28 2041.0 2041.25 2040.25 2040.25
#compare columns high and low
print (df_day.high >= df_night.high)
2015-12-28 False
Freq: D, Name: high, dtype: bool
print (df_day.low <= df_night.low)
2015-12-28 True
Freq: D, Name: low, dtype: bool