如何解决用Python重新采样
我最近出现了一项测试,要求我为Data Sheet建立一个筛选器。 问题如下:
Build a Screener on the data sheet attached.
The strategy workflow is as follows:-
• Convert 1 minute time frame data into 15 minutes
• If low of candle is less than prevIoUs low we enter short position,with 2 exit criteria’s
o Exit at end of day
o Exit if the high of prevIoUs candle is broken
我在重新采样数据时遇到麻烦。
我是初学者,请帮助我!
解决方法
要重新采样,首先需要确保数据框的索引类型为DateTimeIndex
。在您自己的情况下,您需要下采样(即较低的频率),然后您需要在新的采样频率(在您的情况下为15分钟)内汇总这些值。这是一个工作代码。
#read data as csv
df = pd.read_csv('data.csv',index_col = 'Time')
#convert df index to DataTimeIndex
df.index = pd.to_datetime(df.index)
#downsample and aggregate
df.resample('15T').sum()
结果:
Open High Low Close Volume
Time
2020-08-22 09:15:00 67651.75 68489.75 66555.80 67449.95 20526750
2020-08-22 09:30:00 66925.60 67568.40 66227.60 66917.05 13935600
2020-08-22 09:45:00 66661.35 67223.20 66065.30 66685.30 11484225
2020-08-22 10:00:00 65943.20 66399.60 65396.70 65902.50 8253600
2020-08-22 10:15:00 66893.50 67397.70 66409.60 66904.75 8384775
2020-08-22 10:30:00 66306.30 66784.25 65789.65 66274.60 7927350
2020-08-22 10:45:00 66410.70 66873.80 65964.20 66424.20 7811550
2020-08-22 11:00:00 65391.45 65818.80 64933.00 65408.95 7302525
2020-08-22 11:15:00 62587.45 63031.15 62059.35 62522.10 6503775
2020-08-22 11:30:00 62369.40 62891.20 61854.70 62387.40 7074825
2020-08-22 11:45:00 63602.35 64068.20 63132.15 63613.05 7082175
2020-08-22 12:00:00 63347.25 63814.55 62903.80 63342.15 6986250
2020-08-22 12:15:00 62588.20 63128.45 62165.75 62655.05 7644375
2020-08-22 12:30:00 64288.35 64769.35 63759.40 64241.20 7598400
2020-08-22 12:45:00 61430.25 61916.45 60898.85 61379.00 8495775
2020-08-22 13:00:00 61137.65 61740.60 60630.45 61213.70 10142250
2020-08-22 13:15:00 61139.60 61723.20 60493.55 61092.30 9513900
2020-08-22 13:30:00 62049.05 62659.50 61437.50 62044.85 10065750
2020-08-22 13:45:00 64004.35 64515.00 63334.60 63936.95 7864125
2020-08-22 14:00:00 63347.80 63923.20 62694.10 63284.55 9224025
2020-08-22 14:15:00 61649.90 62177.70 60951.70 61551.35 8542350
2020-08-22 14:30:00 61993.75 62647.80 61423.70 62058.45 9870600
2020-08-22 14:45:00 62134.75 62697.90 61474.25 62062.55 10302600
2020-08-22 15:00:00 62679.55 63249.90 62063.75 62676.35 12184050
2020-08-22 15:15:00 62727.55 63091.80 62329.15 62717.75 11147250
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。