比特币自动交易策略入门

上周五开始入坑比特币交易。
由于各个交易所提供了丰富的API,基本上利用API来协助交易变得非常简单。
比如结合itchat这个工具我们可以实现使用微信来进行交易。

三天下来有一点感受就是,总是盯着价格容易精神恍惚,所以得早日转战自动交易。
gekko就是一个非常适合用来做自动交易的框架。

要自动交易自然了解交易策略是非常重要的。下面就gekko默认自带的几个交易策略做一下备忘。

DEMA

这个方法使用(EMA)Exponential Moving Average crossovers来预测当前市场的走向。所谓的EMA可以参考wikipedia,总的来说,可以把它理解成一个K线图的加权平均,所以自带一个参数α,数值介乎0至1。α也可用天数N来代表,这个时候(α=1/(N+1))。在gekko这个框架里面,涉及用到EMA的策略,我们通常可以看到short和long这两个参数。分别代表短期N和长期的N。
DEMA中,使用短期平均和长期平均曲线的交错点来判断市场走向。下面的down和up阈值就分别代表了其上下的幅度。

1
2
3
4
5
6
7
8
# EMA weight
# the higher the weight, the more smooth (and delayed) the line
short = 10
long = 21

[thresholds]
down = -0.025
up = 0.025

MACD

基本和DEMA相同,不同点是引入了一个叫signal的参数,这个时候会有第三条EMA曲线,是用short和long EMA的查生成的。signal是其期间长度。

1
2
3
4
5
6
7
8
9
10
11
12
13
# EMA weight (α)
# the higher the weight, the more smooth (and delayed) the line
short = 10
long = 21
signal = 9

# the difference between the EMAs (to act as triggers)
[thresholds]
down = -0.025
up = 0.025
# How many candle intervals should a trend persist
# before we consider it real?
persistence = 1

PRO

基本和MACD相同,具体区别参考这里

RSI

Relative Strength Index。主要考察过卖,过买点来分析市场走向。

1
2
3
4
5
6
7
8
interval = 14

[thresholds]
low = 30
high = 70
# How many candle intervals should a trend persist
# before we consider it real?
persistence = 2

low 和 high两个参数代表RSI数值的上值和下值,超过上值就有可能发生超买,低于下值就有可能发生超卖。

StochRSI

从名字上可以看出和RSI类似,参数也相同,就不多说了。

CCI

Commodity Channel Index。计算当前价和均价的相关性。也是判断超买和超卖的指标,前提是假设这些走向具有周期性。

1
2
3
4
5
6
7
8
9
10
# constant multiplier. 0.015 gets to around 70% fit
constant = 0.015

# history size, make same or smaller than history
history = 90

[thresholds]
up = 100
down = -100
persistence = 0

talib-macd

talib的MACD实现。基本原理和参数和上面的MACD一致。