背景:,我编写了一个密码交易机器人,以获取乐趣和利润。到目前为止,它连接到一个交易所并获取流价格数据。我使用这个价格来创建一个技术指标(MACD)。通常,对于MACD,建议使用26,12和9天的收盘价。然而,对于我的交易策略,我计划使用26,12和9 my 的数据。
问题:,我马上就能得到多重(比如说10)的价格。我是否只是简单地将它们平均起来,并把时间循环到下一分钟(所以它们都落在同一分钟的桶里)?或者有更好的方法来处理这件事。
非常感谢!
发布于 2021-03-15 13:41:50
我就是这样处理的。流数据出现在< 1s期间。代码检查新的低和高在流期间,并建立蜡烛。可能很难看,因为我不是一个训练有素的开发人员,但它有效。
调整“...round(‘20年代’)”和“如果不同意> 15:”为你想要的蜡烛期。
def on_message(self, msg):
df = pd.json_normalize(msg, record_prefix=msg['type'])
df['date'] = df['time']
df['price'] = df['price'].astype(float)
df['low'] = df['low'].astype(float)
for i in range(0, len(self.df)):
if i == (len(self.df) - 1):
self.rounded_time = self.df['date'][i]
self.rounded_time = pd.to_datetime(self.rounded_time).round('20s')
self.lhigh = self.df['price'][i]
self.lhighcandle = self.candle['high'][i]
self.llow = self.df['price'][i]
self.lowcandle = self.candle['low'][i]
self.close = self.df['price'][i]
if self.lhigh > self.lhighcandle:
nhigh = self.lhigh
else:
nhigh = self.lhighcandle
if self.llow < self.lowcandle:
nlow = self.llow
else:
nlow = self.lowcandle
newdata = pd.DataFrame.from_dict({
'date': self.df['date'],
'tkr': tkr,
'open': self.df.price.iloc[0],
'high': nhigh,
'low': nlow,
'close': self.close,
'vol': self.df['last_size']})
self.candle = self.candle.append(newdata, ignore_index=True).fillna(0)
if ctime > self.rounded_time:
closeit = True
self.en = time.time()
if closeit:
dur = (self.en - self.st)
if dur > 15:
self.st = time.time()
out = self.candle[-1:]
out.to_sql(tkr, cnx, if_exists='append')
dat = ['tkr', 0, 0, 100000, 0, 0]
self.candle = pd.DataFrame([dat], columns=['tkr', 'open', 'high', 'low', 'close', 'vol'])发布于 2021-05-30 21:50:35
据我所知,大多数或所有技术指标公式都依赖于相同大小的条形图来产生准确和有意义的结果。您将不得不进行一些数据转换。下面是一个聚集技术的例子,它使用量化来使所有的条形图都达到统一的尺寸。它将把小的条形尺寸转换为较大的条形尺寸;例如,第二条到每分钟一条。
// C#, see link above for more info
quoteHistory
.OrderBy(x => x.Date)
.GroupBy(x => x.Date.RoundDown(newPeriod))
.Select(x => new Quote
{
Date = x.Key,
Open = x.First().Open,
High = x.Max(t => t.High),
Low = x.Min(t => t.Low),
Close = x.Last().Close,
Volume = x.Sum(t => t.Volume)
});有关指标和相关工具,请参见Stock.Indicators for .NET。
https://stackoverflow.com/questions/66111501
复制相似问题