[英]Adding a Time Condition to an order in Interactive Broker's API
[英]Format Interactive Broker data to ProRealTime's daily bars
當我從盈透證券 (IB) 下載外匯每日開盤高低收盤 (OHLC) 蠟燭時,我得到的值與 ProRealTime (PRT) 的蠟燭不匹配(至少在法國)。
我弄清楚了 PRT 是如何構建蠟燭的(根據 IB 數據):
因此,我想使用熊貓從 IB-hourly-candles 重建 PRT-daily-candles。
下面提供了帶有 IB-hourly-candles 的起始代碼:
import pandas as pd
import dateutils
df = pd.read_csv(
'https://gist.githubusercontent.com/marc-moreaux/d6a910952b8c8243a4fcb8e377cc2de9/raw/d811445bbb782743e71193dbbe31f84adc6f8a5f/EURUSD-daily.csv',
index_col=0,
usecols=[1, 2, 3, 4, 5],
parse_dates=True,
date_parser=dateutil.parser.isoparse))
在這篇文章的同時,我提供了一段為我完成這項工作的代碼。
我花了一些時間來弄清楚這一切,所以我分享了我對這個問題的解決方案,另外我想知道是否有更清晰的方法來實現相同的目標:
import pandas as pd
import dateutils
# Read the csv
df = pd.read_csv(
'https://gist.githubusercontent.com/marc-moreaux/d6a910952b8c8243a4fcb8e377cc2de9/raw/d811445bbb782743e71193dbbe31f84adc6f8a5f/EURUSD-daily.csv',
index_col=0,
usecols=[1, 2, 3, 4, 5],
parse_dates=True,
date_parser=dateutil.parser.isoparse))
# OHLC Agglomeration scheme
ohlc_agg = {
'open': 'first',
'high': 'max',
'low': 'min',
'close': 'last' }
# Set data to Central European Time (+1/+2) and convert it to UTC (+0)
df = (df.tz_localize('CET', ambiguous='infer')
.tz_convert(None)
.resample('1d')
.agg(ohlc_agg)
.dropna())
# Identify Sundays and Mondays by their weekday
df['wd'] = df.index.weekday
# Aggregate 1 week of data where only Sundays and Mondays exists; shift these
# aggregated values to corresponding monday; and update df.
df.update(df[(df.wd == 6) | (df.wd == 0)]
.ressample('1W-MON')
.agg(ohlc_agg))
# Finally delete sundays
df = df[df.wd != 6]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.