# 12.2 日内交易 · 大盘日内走势 (for 择时)

``````# 获取09年以来的上证交易日
import datetime
import seaborn
import pandas as pd

array(['20090105', '20090106', '20090107', ..., '20151112', '20151113',
'20151116'], dtype=object)
``````
``````# 获取09年以来的上证指数的分钟线
df = None
try:
temp_df = DataAPI.MktBarHistOneDayGet(securityID='000001.XSHG',date=date, field='barTime,closePrice')[1:]
except:
print 'get data error at %s.' %date
continue
# 日内打分，1表示最高
temp_df['rank'] = temp_df.closePrice.rank(ascending=False)
temp_df['index'] = range(len(temp_df))
if df is None:
df = temp_df
else:
df = df.append(temp_df)
``````

``````bar_length = 30 #30mins bar
def plot(bar_length):
df['bar time'] = df['index'].apply(lambda x:x/bar_length)
highest_count = df[df['rank'] == min(df['rank'])].groupby('bar time')['rank'].count()
lowest_count = df[df['rank'] == max(df['rank'])].groupby('bar time')['rank'].count()

pd.DataFrame({'highest point':highest_count,'lowest point': lowest_count}).plot(figsize=(14,8),kind='bar', title='%s mins bar' %bar_length)
plot(bar_length)
``````

``````plot(bar_length=15)
plot(bar_length=5)
``````

5mins比15mins图更清晰。