Skip to content

Instantly share code, notes, and snippets.

@zhangz
Last active September 9, 2019 01:17
Show Gist options
  • Save zhangz/9af1a7ea91dfc8f37e93a9f0b622297d to your computer and use it in GitHub Desktop.
Save zhangz/9af1a7ea91dfc8f37e93a9f0b622297d to your computer and use it in GitHub Desktop.

Revisions

  1. zhangz revised this gist Apr 10, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions calcMinuteBar.py
    Original file line number Diff line number Diff line change
    @@ -29,10 +29,10 @@ def calcOneMinuteBar():
    # 一分钟转N分钟
    d_dict = {'open': 'first', 'high': 'max',
    'close': 'last', 'low': 'min', 'amount': 'sum'}
    new = pd.DataFrame()
    newdf = pd.DataFrame()
    for col in newdf.columns:
    new[col] = newdf[col].resample('5min', how=d_dict[col])
    new.tail(20)
    newdf[col] = newdf[col].resample('5min', how=d_dict[col])
    newdf.tail(20)


    if __name__ == "__main__":
  2. zhangz revised this gist Apr 10, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions calcMinuteBar.py
    Original file line number Diff line number Diff line change
    @@ -37,3 +37,5 @@ def calcOneMinuteBar():

    if __name__ == "__main__":
    calcOneMinuteBar()

    # http://mp.weixin.qq.com/s?__biz=MzAwOTgzMDk5Ng==&mid=2650833965&idx=1&sn=e3e74639c068e7a1e41a35bb1decd313
  3. zhangz created this gist Apr 10, 2017.
    39 changes: 39 additions & 0 deletions calcMinuteBar.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    # coding: utf8
    import tushare as ts
    import pandas as pd


    def calcOneMinuteBar():
    # data_frame = pd.read_csv('AUDJPY-2016-01.csv', names=['Symbol', 'Date_Time', 'Bid', 'Ask'],
    # index_col=1, parse_dates=True)
    df = ts.get_tick_data('002743', date='2016-10-28')
    # df.tail(10)
    df['time'] = '2016-10-28 ' + df['time']
    df['time'] = pd.to_datetime(df['time'])
    df = df.set_index(['time'])
    # TICK数据转成开、高、低、收
    price_df = df['price'].resample('1min').ohlc()
    price_df = price_df.dropna()
    # 成交量
    vols = df['volume'].resample('1min').sum()
    vols = vols.dropna()
    vol_df = pd.DataFrame(vols, columns=['volume'])
    # 成交额
    amounts = df['amount'].resample('1min').sum()
    amount = amounts.dropna()
    amount_df = pd.DataFrame(amounts, columns=['amount'])
    # 合并
    result_df = price_df.merge(vol_df, left_index=True, right_index=True).merge(
    amount_df, left_index=True, right_index=True)
    result_df.head()
    # 一分钟转N分钟
    d_dict = {'open': 'first', 'high': 'max',
    'close': 'last', 'low': 'min', 'amount': 'sum'}
    new = pd.DataFrame()
    for col in newdf.columns:
    new[col] = newdf[col].resample('5min', how=d_dict[col])
    new.tail(20)


    if __name__ == "__main__":
    calcOneMinuteBar()