Last active
September 9, 2019 01:17
-
-
Save zhangz/9af1a7ea91dfc8f37e93a9f0b622297d to your computer and use it in GitHub Desktop.
Revisions
-
zhangz revised this gist
Apr 10, 2017 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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'} newdf = pd.DataFrame() for col in newdf.columns: newdf[col] = newdf[col].resample('5min', how=d_dict[col]) newdf.tail(20) if __name__ == "__main__": -
zhangz revised this gist
Apr 10, 2017 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 -
zhangz created this gist
Apr 10, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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()