今、10秒後の株価の騰落率を返すプログラムを書いています。
とりあえず、for文を使って上手く動くコードは書けたのですが、実行に時間がかかりすぎるため、pandasの処理でうまく返せないか検討しています。
いいアイデアがある方、ご教示いただけないでしょうか?
python
1 START_TIME = datetime.time(9, 00, 0, 0) 2 END_TIME = datetime.time(15, 00, 0, 0) 3 RESTSTART_TIME = datetime.time(11, 30, 0, 0) 4 RESTEND_TIME = datetime.time(12, 30, 0, 0) 5 6 df = args 7 df = df.reset_index(drop=True) 8 9 for i, row in df.iterrows(): 10 t = pushlist.objects.get(pushlist_id=df.loc[i, 'pushlist_id']) 11 time = df.loc[i, 'currentpricetime'] + datetime.timedelta(hours=9) 12 if time.time() > END_TIME: # 教師信号となる時間が15時を超えていたらelseにとんで0をいれる 13 print("時間外") 14 else: 15 # ここから10秒後の教師信号 16 time2 = time + datetime.timedelta(seconds=10) 17 if RESTSTART_TIME < time2.time() < RESTEND_TIME: 18 t.later10s = 99 # 99は時間外 19 else: 20 time3 = time2 - datetime.timedelta(hours=9) 21 df2 = df[(df.symbolname == df.loc[i, 'symbolname']) & (df.currentpricetime < time3)] # 同じ銘柄かつ教師信号自転 22 df2 = df2.sort_values(['currentpricetime']) 23 df2 = df2.reset_index(drop=True) 24 value = (float(df2['currentprice'][df2.index.max()]) / float(df['currentprice'][i])) - 1 25 t.later10s = value 26 t.save() 27
pandas
1 symbol currentprice currentpricetime later10s 24490 5170 2020-10-21 00:06:04.736356+00:00 0 ← 00:06:14の株価との騰落率5160/5170-1 を返したい 34490 5170 2020-10-21 00:06:06.095071+00:00 0 44490 5170 2020-10-21 00:06:06.271264+00:00 0 54490 5160 2020-10-21 00:06:06.417457+00:00 0 64490 5160 2020-10-21 00:06:06.469697+00:00 0 74490 5160 2020-10-21 00:06:06.500777+00:00 0 84490 5160 2020-10-21 00:06:06.946862+00:00 0 94490 5160 2020-10-21 00:06:07.081324+00:00 0 104490 5160 2020-10-21 00:06:07.912222+00:00 0 114490 5160 2020-10-21 00:06:09.399203+00:00 0 124490 5140 2020-10-21 00:06:10.346132+00:00 0 134490 5140 2020-10-21 00:06:10.440464+00:00 0 144490 5140 2020-10-21 00:06:10.505377+00:00 0 154490 5140 2020-10-21 00:06:10.785968+00:00 0 164490 5140 2020-10-21 00:06:10.982870+00:00 0 174490 5140 2020-10-21 00:06:11.294839+00:00 0 184490 5110 2020-10-21 00:06:11.837236+00:00 0 194490 5110 2020-10-21 00:06:11.852856+00:00 0 204490 5110 2020-10-21 00:06:12.022399+00:00 0 214490 5110 2020-10-21 00:06:12.556094+00:00 0 224490 5110 2020-10-21 00:06:12.805651+00:00 0 234490 5130 2020-10-21 00:06:13.857057+00:00 0 244490 5160 2020-10-21 00:06:13.888533+00:00 0 254490 5160 2020-10-21 00:06:14.065261+00:00 0 264490 5160 2020-10-21 00:06:14.220194+00:00 0 274490 5160 2020-10-21 00:06:14.582616+00:00 0 284490 5160 2020-10-21 00:06:15.189344+00:00 0 294490 5160 2020-10-21 00:06:15.383874+00:00 0 304490 5160 2020-10-21 00:06:17.014968+00:00 0 314490 5140 2020-10-21 00:06:17.678799+00:00 0 324490 5140 2020-10-21 00:06:17.730237+00:00 0 334490 5140 2020-10-21 00:06:17.866179+00:00 0 344490 5120 2020-10-21 00:06:20.887709+00:00 0 354490 5120 2020-10-21 00:06:20.960669+00:00 0 364490 5120 2020-10-21 00:06:21.106985+00:00 0 374490 5120 2020-10-21 00:06:22.163820+00:00 0 384490 5120 2020-10-21 00:06:23.252743+00:00 0 394490 5120 2020-10-21 00:06:23.431432+00:00 0 404490 5120 2020-10-21 00:06:23.600981+00:00 0 414490 5120 2020-10-21 00:06:23.827950+00:00 0 42
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/10/24 16:03
2020/10/24 16:06
2020/10/24 23:12