您提到您将进行回溯测试,因此您将拥有所有历史定价。
让下面是代理设置:
import pandas as pd
from StringIO import StringIO
text = """Date,200001,200230,200247,200291,200597
2016-03-31,593.6399,41.830002,11.800001,25.100007,151.45
2016-04-01,598.5,42.190003,11.57,25.350007,152.52001
2016-04-04,593.18995,42.320008,11.36,26.0,152.07001
2016-04-05,586.1399,42.039994,11.07,25.380005,150.0
2016-04-06,602.08008,43.050004,11.08,25.940003,150.02001
2016-04-07,591.42994,42.610001,10.86,25.820008,148.25
2016-04-08,594.6001,42.369996,10.960001,26.339997,149.35001
2016-04-11,595.92994,42.479996,11.020001,26.080002,149.25
2016-04-12,603.16993,42.820008,11.16,26.130005,149.63001
2016-04-13,614.82007,43.350007,11.23,27.470002,151.23"""
price_df = pd.read_csv(StringIO(text), index_col=0, parse_dates=[0])
然后你就可以生产的历史高位价格与历史价格低,像这样:
hi_df = price_df.cummax()
lo_df = price_df.cummin()
price_df
看起来像
200001 200230 200247 200291 200597
Date
2016-03-31 593.63990 41.830002 11.800001 25.100007 151.45000
2016-04-01 598.50000 42.190003 11.570000 25.350007 152.52001
2016-04-04 593.18995 42.320008 11.360000 26.000000 152.07001
2016-04-05 586.13990 42.039994 11.070000 25.380005 150.00000
2016-04-06 602.08008 43.050004 11.080000 25.940003 150.02001
2016-04-07 591.42994 42.610001 10.860000 25.820008 148.25000
2016-04-08 594.60010 42.369996 10.960001 26.339997 149.35001
2016-04-11 595.92994 42.479996 11.020001 26.080002 149.25000
2016-04-12 603.16993 42.820008 11.160000 26.130005 149.63001
2016-04-13 614.82007 43.350007 11.230000 27.470002 151.23000
hi_df
and lo_df
lo好吧,像这些分别
print hi_df
200001 200230 200247 200291 200597
Date
2016-03-31 593.63990 41.830002 11.800001 25.100007 151.45000
2016-04-01 598.50000 42.190003 11.800001 25.350007 152.52001
2016-04-04 598.50000 42.320008 11.800001 26.000000 152.52001
2016-04-05 598.50000 42.320008 11.800001 26.000000 152.52001
2016-04-06 602.08008 43.050004 11.800001 26.000000 152.52001
2016-04-07 602.08008 43.050004 11.800001 26.000000 152.52001
2016-04-08 602.08008 43.050004 11.800001 26.339997 152.52001
2016-04-11 602.08008 43.050004 11.800001 26.339997 152.52001
2016-04-12 603.16993 43.050004 11.800001 26.339997 152.52001
2016-04-13 614.82007 43.350007 11.800001 27.470002 152.52001
print lo_df
200001 200230 200247 200291 200597
Date
2016-03-31 593.63990 41.830002 11.800001 25.100007 151.45
2016-04-01 593.63990 41.830002 11.570000 25.100007 151.45
2016-04-04 593.18995 41.830002 11.360000 25.100007 151.45
2016-04-05 586.13990 41.830002 11.070000 25.100007 150.00
2016-04-06 586.13990 41.830002 11.070000 25.100007 150.00
2016-04-07 586.13990 41.830002 10.860000 25.100007 148.25
2016-04-08 586.13990 41.830002 10.860000 25.100007 148.25
2016-04-11 586.13990 41.830002 10.860000 25.100007 148.25
2016-04-12 586.13990 41.830002 10.860000 25.100007 148.25
2016-04-13 586.13990 41.830002 10.860000 25.100007 148.25
你能给我们一些样本数据和预期的输出,使我们的生活更轻松。你总是可以使用'min,max'内置的插件 – Bahrom
除了使用'[option1,option2] [x> 0]'技巧来消除对条件分支的需求之外,还有很少的优化,但是没有额外的有关需要完成什么的信息。 –
编辑orignal帖子添加运行该平台将允许建立一个熊猫数据库中的所有价格。所以我可以说 currentPrices = data.history(证券,'价格',1,'1m') currentPrices然后将是一个数据表,证券作为列和一行价格。 –