数字货币量化之 Catalyst 基于交易信号的策略开发-双均线交易信号

本章我们将使用Catalyst框架来进行双均线交易信号策略的开发。

一、策略原理

  • 应用两条不同周期的移动平均线,即短周期移动平均线和长周期移动平均线的相对大小,研判买入与卖出时机的策略。(择时策略)
  • 当短周期的均线从长期的均线的下方,向上穿越至长周期的均线,所形成的交点,称为金叉,市场属于多头市场。
  • 当短周期的均线从长周期的均线的上方,向下穿越至长周期的均线,所形成的交点,称为死叉,市场属于空头市场。

二、策略逻辑

  • 空仓状态下,短周期均线上穿(大于)长周期均线形成金叉,且该数字货币可以交易,满仓买入。
  • 持仓状态下,短周期均线下穿(小于)长周期均线形成死叉,且该数字货币可以交易,满仓卖出。

三、策略实现

设置手续费,maker, taker

maker:挂单。以指定的价格(挂买单时低于市价或高于市场价格)下单时不会立即与深度列表里的其他订单成交,而是进入深度列表等待对方主动来跟你的订单成交。

taker:吃单。以指定的价格(与市场深度列表中的订单有交叉)下单时立即与深度列表的其他订单成交,主动与深度列表中的其他订单成交。

滑点:一笔交易或挂单交易中所要求的价格和实际订单执行或成交价格之间的差异。在普通交易时间内,一般价格波动不大,所以滑点通常设为比较小的值,如 0.001。

注意:买入点的选择。
file

四、实战

dual_moving_avg_alg.py

# -*- coding:utf-8 -*-

"""
@author: Corwien
@file: dual_moving_avg_test.py
@time: 19/12/18 20:57
"""

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

from catalyst import run_algorithm
from catalyst.api import order, record, symbol, order_target_percent
from catalyst.exchange.utils.stats_utils import  extract_transactions

# 需要先加载数据
# catalyst ingest-exchange -x binance -i btc_usdt -f daily

# 定义常量
NAMESPACE = 'dual_moving_average'  # 变量空间
SIGNAL_BUY = 'buy'      # 买入信号
SIGNAL_SELL = 'sell'    # 卖出信号
SIGNAL_INIT = ''        # 观望信号
SHORT_WIN = 5           # 短周期窗口
LONG_WIN = 25           # 长周期窗口 , 10, 20, 25, 30

def initialize(context):
    """
    初始化
    :param context:
    :return:
    """
    context.i = 0                         # 经历过得交易周期
    context.asset = symbol('btc_usdt')    # 交易对
    context.base_price = None             # 初识价格
    context.signal = SIGNAL_INIT          # 交易信号
    context.set_commission(maker=0.001, taker=0.001)    # 设置手续费
    context.set_slippage(slippage=0.001)                # 设置滑点

def handle_data(context, data):
    """
    在每个交易周期上运行的策略
    :param context:
    :param data:
    :return:
    """

    # 在判断每个交易点,要拿到金叉的三天的数据,要判断当天是不是买入点,就要看前两天的数据。
    # 前两天的短期均线在长期均线下边,同时满足前一天是在长期均线上边,这样就形成金叉,完成上穿,而不是一直在上边,

    context.i += 1   # 记录交易周期

    # 累计交易周期,得先累计够长周期窗口,则才能计算均线。
    # 如果交易周期过短,无法计算均线,则跳过循环
    if context.i < LONG_WIN + 2:
        return

    # 获取历史价格,catalyst/lib/python3.6/site-packages/catalyst/_protocol.pyx
    history_data = data.history(context.asset,
                                'close',
                                bar_count=LONG_WIN + 2,
                                frequency='1D',
                                )

    # 获取当前持仓数量
    pos_amount = context.portfolio.positions[context.asset].amount

    # 计算双均线
    short_avgs = history_data.rolling(window=SHORT_WIN).mean()
    long_avgs = history_data.rolling(window=LONG_WIN).mean()

    # 双均线策略
    # 短周期均线上穿长周期均线,做多(当天是-1,前两天则是-3,前一天是-2,回测时假设是不知道后边的行情走势)
    if(short_avgs[-3] < long_avgs[-3]) and (short_avgs[-2] >= long_avgs[-2]) and pos_amount == 0:
        # 开多仓
        order_target_percent(asset=context.asset, target=1)  # 买入,target=1表示全仓买入
        context.signal = SIGNAL_BUY

    # 短周期均线下穿长期均线,做空
    if(short_avgs[-3] > long_avgs[-3]) and (short_avgs[-2] <= long_avgs[-2]) and pos_amount > 0:
        # 平多仓
        order_target_percent(asset=context.asset, target=0)  # 卖出
        context.signal = SIGNAL_SELL

    # 获取当前的价格
    price = data.current(context.asset, 'price')
    if context.base_price is None:
        # 如果没有设置初始价格,则将第一个周期的价格作为初始价格
        context.base_price = price

    # 计算价格变化百分比,作为基准
    price_change = (price - context.base_price) / context.base_price

    # 记录每个交易周期的信息
    # 1、价格,2、现金,3、价格变化率,4、快线均值,5、慢线均值

    record(
        price=price,
        cash=context.portfolio.cash,
        price_change=price_change,
        short_mavg=short_avgs[-1],
        long_mavg=long_avgs[-1],
        signal=context.signal
    )

    # 输出信息,portfolio_value 总的资产,包括现金和货币
    print('日期:{},价格:{:.4f},资产:{:.2f},持仓量:{:.8f}, {}'.format(
        data.current_dt, price, context.portfolio.portfolio_value, pos_amount, context.signal))

    # 进行下一次交易前重置交易信号
    context.signal = SIGNAL_INIT

def analyze(context, perf):
    """
    策略分析
    :param context:
    :param perf:
    :return:
    """

    # 保存交易记录
    perf.to_csv('./performance.csv')

    # 获取交易所的计价货币
    exchange = list(context.exchanges.values())[0]
    quote_currency = exchange.quote_currency.upper()

    # 图1 可视化资产(手里是否有现金),subplot(numRows,numCols,plotNum),(411)等价(4,1,1)
    ax1 = plt.subplot(411)
    perf['portfolio_value'].plot(ax=ax1)
    ax1.set_ylabel('Portfolio Value\n({})'.format(quote_currency))
    start, end = ax1.get_ylim()
    ax1.yaxis.set_ticks(np.arange(start, end, (end - start) / 5))

    # 图2:可视化货币价格,均线和买入卖出点
    ax2 = plt.subplot(412, sharex=ax1)
    perf[['price', 'short_mavg', 'long_mavg']].plot(ax=ax2)
    ax2.set_ylabel('{asset}\n({quote})'.format(
        asset=context.asset.symbol,
        quote=quote_currency
    ))
    start, end = ax2.get_ylim()
    ax2.yaxis.set_ticks(np.arange(start, end, (end - start) / 5))

    # 提取交易时间点
    transaction_df = extract_transactions(perf)
    if not transaction_df.empty:
        buy_df = transaction_df[transaction_df['amount'] > 0]   # 买入点
        sell_df = transaction_df[transaction_df['amount'] < 0]  # 卖出点
        ax2.scatter(
            buy_df.index.to_pydatetime(),
            perf.loc[buy_df.index, 'price'],
            marker='^',
            s=100,
            c='green',
            label=''
        )
        ax2.scatter(
            sell_df.index.to_pydatetime(),
            perf.loc[sell_df.index, 'price'],
            marker='v',
            s=100,
            c='red',
            label=''
        )

    # 图3:比较价格变化率和资产变化率
    ax3 = plt.subplot(413, sharex=ax1)
    perf[['algorithm_period_return', 'price_change']].plot(ax=ax3)
    ax3.set_ylabel('Percent Change')
    start, end = ax3.get_ylim()
    ax3.yaxis.set_ticks(np.arange(start, end, (end - start) / 5))

    # 图4:可视化现金数量
    ax4 = plt.subplot(414, sharex=ax1)
    perf['cash'].plot(ax=ax4)
    ax4.set_ylabel('Cash\n({})'.format(quote_currency))
    start, end = ax4.get_ylim()
    ax4.yaxis.set_ticks(np.arange(0, end, end / 5))

    plt.tight_layout()
    plt.show()

if __name__ == '__main__':
    run_algorithm(
        capital_base=1000,
        data_frequency='daily',
        initialize=initialize,
        handle_data=handle_data,
        analyze=analyze,
        exchange_name='binance',
        algo_namespace=NAMESPACE,
        quote_currency='usdt',
        start=pd.to_datetime('2019-01-01', utc=True),
        end=pd.to_datetime('2019-12-15', utc=True)
    )

结果打印:

[2019-12-18 15:38:58.075341] INFO: exchange_algorithm: initialized trading algorithm in backtest mode
日期:2019-01-27 23:59:00+00:00,价格:3550.8400,资产:1000.00,持仓量:0.00000000, 
日期:2019-01-28 23:59:00+00:00,价格:3434.1500,资产:1000.00,持仓量:0.00000000, 
日期:2019-01-29 23:59:00+00:00,价格:3411.0400,资产:1000.00,持仓量:0.00000000, 
日期:2019-01-30 23:59:00+00:00,价格:3458.1800,资产:1000.00,持仓量:0.00000000, 
日期:2019-01-31 23:59:00+00:00,价格:3434.1000,资产:1000.00,持仓量:0.00000000, 
日期:2019-02-01 23:59:00+00:00,价格:3462.0700,资产:1000.00,持仓量:0.00000000, 
日期:2019-02-02 23:59:00+00:00,价格:3504.7700,资产:1000.00,持仓量:0.00000000, 
日期:2019-02-03 23:59:00+00:00,价格:3458.1100,资产:1000.00,持仓量:0.00000000, 
日期:2019-02-04 23:59:00+00:00,价格:3463.2200,资产:1000.00,持仓量:0.00000000, 
日期:2019-02-05 23:59:00+00:00,价格:3471.5900,资产:1000.00,持仓量:0.00000000, 
日期:2019-02-06 23:59:00+00:00,价格:3405.3700,资产:1000.00,持仓量:0.00000000, 
日期:2019-02-07 23:59:00+00:00,价格:3398.4000,资产:1000.00,持仓量:0.00000000, 
日期:2019-02-08 23:59:00+00:00,价格:3659.0400,资产:1000.00,持仓量:0.00000000, 
日期:2019-02-09 23:59:00+00:00,价格:3665.1800,资产:1000.00,持仓量:0.00000000, 
日期:2019-02-10 23:59:00+00:00,价格:3680.0600,资产:1000.00,持仓量:0.00000000, 
日期:2019-02-11 23:59:00+00:00,价格:3631.0500,资产:1000.00,持仓量:0.00000000, buy
日期:2019-02-12 23:59:00+00:00,价格:3631.4600,资产:998.00,持仓量:0.27540243, 
日期:2019-02-13 23:59:00+00:00,价格:3609.4000,资产:991.92,持仓量:0.27540243, 
日期:2019-02-14 23:59:00+00:00,价格:3590.5600,资产:986.73,持仓量:0.27540243, 
日期:2019-02-15 23:59:00+00:00,价格:3602.4700,资产:990.01,持仓量:0.27540243, 
日期:2019-02-16 23:59:00+00:00,价格:3618.4100,资产:994.40,持仓量:0.27540243, 
日期:2019-02-17 23:59:00+00:00,价格:3667.5800,资产:1007.95,持仓量:0.27540243, 
日期:2019-02-18 23:59:00+00:00,价格:3898.6000,资产:1071.57,持仓量:0.27540243, 
日期:2019-02-19 23:59:00+00:00,价格:3907.7900,资产:1074.10,持仓量:0.27540243, 
日期:2019-02-20 23:59:00+00:00,价格:3969.7400,资产:1091.16,持仓量:0.27540243, 
日期:2019-02-21 23:59:00+00:00,价格:3937.3100,资产:1082.23,持仓量:0.27540243, 
日期:2019-02-22 23:59:00+00:00,价格:3962.0000,资产:1089.03,持仓量:0.27540243, 
日期:2019-02-23 23:59:00+00:00,价格:4117.7600,资产:1131.93,持仓量:0.27540243, 
日期:2019-02-24 23:59:00+00:00,价格:3743.5600,资产:1028.87,持仓量:0.27540243, 
日期:2019-02-25 23:59:00+00:00,价格:3827.9200,资产:1052.10,持仓量:0.27540243, 
日期:2019-02-26 23:59:00+00:00,价格:3809.2300,资产:1046.96,持仓量:0.27540243, 
日期:2019-02-27 23:59:00+00:00,价格:3818.0700,资产:1049.39,持仓量:0.27540243, 
日期:2019-02-28 23:59:00+00:00,价格:3813.6900,资产:1048.19,持仓量:0.27540243, 
日期:2019-03-01 23:59:00+00:00,价格:3823.0000,资产:1050.75,持仓量:0.27540243, 
日期:2019-03-02 23:59:00+00:00,价格:3819.9300,资产:1049.90,持仓量:0.27540243, 
日期:2019-03-03 23:59:00+00:00,价格:3807.7500,资产:1046.55,持仓量:0.27540243, 
日期:2019-03-04 23:59:00+00:00,价格:3715.3000,资产:1021.09,持仓量:0.27540243, 
日期:2019-03-05 23:59:00+00:00,价格:3857.7300,资产:1060.31,持仓量:0.27540243, 
日期:2019-03-06 23:59:00+00:00,价格:3861.8400,资产:1061.45,持仓量:0.27540243, 
日期:2019-03-07 23:59:00+00:00,价格:3873.6400,资产:1064.70,持仓量:0.27540243, 
日期:2019-03-08 23:59:00+00:00,价格:3864.8900,资产:1062.29,持仓量:0.27540243, 
日期:2019-03-09 23:59:00+00:00,价格:3943.0400,资产:1083.81,持仓量:0.27540243, 
日期:2019-03-10 23:59:00+00:00,价格:3916.8200,资产:1076.59,持仓量:0.27540243, 
日期:2019-03-11 23:59:00+00:00,价格:3871.6100,资产:1064.14,持仓量:0.27540243, 
日期:2019-03-12 23:59:00+00:00,价格:3882.7300,资产:1067.20,持仓量:0.27540243, 
日期:2019-03-13 23:59:00+00:00,价格:3866.0000,资产:1062.59,持仓量:0.27540243, 
日期:2019-03-14 23:59:00+00:00,价格:3877.1200,资产:1065.65,持仓量:0.27540243, 
日期:2019-03-15 23:59:00+00:00,价格:3923.7600,资产:1078.50,持仓量:0.27540243, 
日期:2019-03-16 23:59:00+00:00,价格:4005.9800,资产:1101.14,持仓量:0.27540243, 
日期:2019-03-17 23:59:00+00:00,价格:3981.1400,资产:1094.30,持仓量:0.27540243, 
日期:2019-03-18 23:59:00+00:00,价格:3987.8100,资产:1096.14,持仓量:0.27540243, 
日期:2019-03-19 23:59:00+00:00,价格:4015.5300,资产:1103.77,持仓量:0.27540243, 
日期:2019-03-20 23:59:00+00:00,价格:4043.0400,资产:1111.35,持仓量:0.27540243, 
日期:2019-03-21 23:59:00+00:00,价格:3980.6400,资产:1094.16,持仓量:0.27540243, 
日期:2019-03-22 23:59:00+00:00,价格:3986.9300,资产:1095.90,持仓量:0.27540243, 
日期:2019-03-23 23:59:00+00:00,价格:4006.0100,资产:1101.15,持仓量:0.27540243, 
日期:2019-03-24 23:59:00+00:00,价格:3992.1800,资产:1097.34,持仓量:0.27540243, 
日期:2019-03-25 23:59:00+00:00,价格:3936.1200,资产:1081.90,持仓量:0.27540243, 
日期:2019-03-26 23:59:00+00:00,价格:3948.5500,资产:1085.33,持仓量:0.27540243, 
日期:2019-03-27 23:59:00+00:00,价格:4038.0500,资产:1109.97,持仓量:0.27540243, 
日期:2019-03-28 23:59:00+00:00,价格:4027.8100,资产:1107.15,持仓量:0.27540243, 
日期:2019-03-29 23:59:00+00:00,价格:4103.2500,资产:1127.93,持仓量:0.27540243, 
日期:2019-03-30 23:59:00+00:00,价格:4106.9700,资产:1128.96,持仓量:0.27540243, 
日期:2019-03-31 23:59:00+00:00,价格:4103.9500,资产:1128.12,持仓量:0.27540243, 
日期:2019-04-01 23:59:00+00:00,价格:4144.5600,资产:1139.31,持仓量:0.27540243, 
日期:2019-04-02 23:59:00+00:00,价格:4857.2900,资产:1335.60,持仓量:0.27540243, 
日期:2019-04-03 23:59:00+00:00,价格:4932.6000,资产:1356.34,持仓量:0.27540243, 
日期:2019-04-04 23:59:00+00:00,价格:4898.6600,资产:1346.99,持仓量:0.27540243, 
日期:2019-04-05 23:59:00+00:00,价格:5004.9500,资产:1376.26,持仓量:0.27540243, 
日期:2019-04-06 23:59:00+00:00,价格:5043.8900,资产:1386.99,持仓量:0.27540243, 
日期:2019-04-07 23:59:00+00:00,价格:5170.2700,资产:1421.79,持仓量:0.27540243, 
日期:2019-04-08 23:59:00+00:00,价格:5236.9000,资产:1440.14,持仓量:0.27540243, 
日期:2019-04-09 23:59:00+00:00,价格:5150.0000,资产:1416.21,持仓量:0.27540243, 
日期:2019-04-10 23:59:00+00:00,价格:5308.2500,资产:1459.79,持仓量:0.27540243, 
日期:2019-04-11 23:59:00+00:00,价格:5017.3700,资产:1379.68,持仓量:0.27540243, 
日期:2019-04-12 23:59:00+00:00,价格:5048.0100,资产:1388.12,持仓量:0.27540243, 
日期:2019-04-13 23:59:00+00:00,价格:5045.2200,资产:1387.35,持仓量:0.27540243, 
日期:2019-04-14 23:59:00+00:00,价格:5131.3000,资产:1411.06,持仓量:0.27540243, 
日期:2019-04-15 23:59:00+00:00,价格:5024.9500,资产:1381.77,持仓量:0.27540243, 
日期:2019-04-16 23:59:00+00:00,价格:5173.7200,资产:1422.74,持仓量:0.27540243, 
日期:2019-04-17 23:59:00+00:00,价格:5202.8200,资产:1430.76,持仓量:0.27540243, 
日期:2019-04-18 23:59:00+00:00,价格:5258.4400,资产:1446.07,持仓量:0.27540243, 
日期:2019-04-19 23:59:00+00:00,价格:5258.6800,资产:1446.14,持仓量:0.27540243, 
日期:2019-04-20 23:59:00+00:00,价格:5291.7300,资产:1455.24,持仓量:0.27540243, 
日期:2019-04-21 23:59:00+00:00,价格:5256.1400,资产:1445.44,持仓量:0.27540243, 
日期:2019-04-22 23:59:00+00:00,价格:5357.1400,资产:1473.26,持仓量:0.27540243, 
日期:2019-04-23 23:59:00+00:00,价格:5493.3100,资产:1510.76,持仓量:0.27540243, 
日期:2019-04-24 23:59:00+00:00,价格:5415.0000,资产:1489.19,持仓量:0.27540243, 
日期:2019-04-25 23:59:00+00:00,价格:5219.9000,资产:1435.46,持仓量:0.27540243, 
日期:2019-04-26 23:59:00+00:00,价格:5314.1000,资产:1461.40,持仓量:0.27540243, 
日期:2019-04-27 23:59:00+00:00,价格:5295.6900,资产:1456.33,持仓量:0.27540243, 
日期:2019-04-28 23:59:00+00:00,价格:5307.5200,资产:1459.59,持仓量:0.27540243, 
日期:2019-04-29 23:59:00+00:00,价格:5238.1400,资产:1440.48,持仓量:0.27540243, 
日期:2019-04-30 23:59:00+00:00,价格:5320.8100,资产:1463.25,持仓量:0.27540243, 
日期:2019-05-01 23:59:00+00:00,价格:5383.2000,资产:1480.43,持仓量:0.27540243, 
日期:2019-05-02 23:59:00+00:00,价格:5492.8700,资产:1510.64,持仓量:0.27540243, 
日期:2019-05-03 23:59:00+00:00,价格:5772.6900,资产:1587.70,持仓量:0.27540243, 
日期:2019-05-04 23:59:00+00:00,价格:5829.4500,资产:1603.33,持仓量:0.27540243, 
日期:2019-05-05 23:59:00+00:00,价格:5775.6200,资产:1588.51,持仓量:0.27540243, 
日期:2019-05-06 23:59:00+00:00,价格:5747.7900,资产:1580.84,持仓量:0.27540243, 
日期:2019-05-07 23:59:00+00:00,价格:5846.3400,资产:1607.98,持仓量:0.27540243, 
日期:2019-05-08 23:59:00+00:00,价格:5987.2900,资产:1646.80,持仓量:0.27540243, 
日期:2019-05-09 23:59:00+00:00,价格:6209.1800,资产:1707.91,持仓量:0.27540243, 
日期:2019-05-10 23:59:00+00:00,价格:6373.3300,资产:1753.12,持仓量:0.27540243, 
日期:2019-05-11 23:59:00+00:00,价格:7076.2200,资产:1946.69,持仓量:0.27540243, 
日期:2019-05-12 23:59:00+00:00,价格:6967.3100,资产:1916.70,持仓量:0.27540243, 
日期:2019-05-13 23:59:00+00:00,价格:7790.7100,资产:2143.47,持仓量:0.27540243, 
日期:2019-05-14 23:59:00+00:00,价格:7947.5600,资产:2186.66,持仓量:0.27540243, 
日期:2019-05-15 23:59:00+00:00,价格:8169.8700,资产:2247.89,持仓量:0.27540243, 
日期:2019-05-16 23:59:00+00:00,价格:7866.5900,资产:2164.36,持仓量:0.27540243, 
日期:2019-05-17 23:59:00+00:00,价格:7355.2600,资产:2023.54,持仓量:0.27540243, 
日期:2019-05-18 23:59:00+00:00,价格:7257.4500,资产:1996.61,持仓量:0.27540243, 
日期:2019-05-19 23:59:00+00:00,价格:8148.4800,资产:2242.00,持仓量:0.27540243, 
日期:2019-05-20 23:59:00+00:00,价格:7938.1500,资产:2184.07,持仓量:0.27540243, 
日期:2019-05-21 23:59:00+00:00,价格:7904.8700,资产:2174.91,持仓量:0.27540243, 
日期:2019-05-22 23:59:00+00:00,价格:7628.4300,资产:2098.77,持仓量:0.27540243, 
日期:2019-05-23 23:59:00+00:00,价格:7851.5100,资产:2160.21,持仓量:0.27540243, 
日期:2019-05-24 23:59:00+00:00,价格:7964.8700,资产:2191.43,持仓量:0.27540243, 
日期:2019-05-25 23:59:00+00:00,价格:8025.4100,资产:2208.10,持仓量:0.27540243, 
日期:2019-05-26 23:59:00+00:00,价格:8614.4300,资产:2370.32,持仓量:0.27540243, 
日期:2019-05-27 23:59:00+00:00,价格:8756.3200,资产:2409.40,持仓量:0.27540243, 
日期:2019-05-28 23:59:00+00:00,价格:8715.6400,资产:2398.19,持仓量:0.27540243, 
日期:2019-05-29 23:59:00+00:00,价格:8645.6800,资产:2378.93,持仓量:0.27540243, 
日期:2019-05-30 23:59:00+00:00,价格:8269.5400,资产:2275.34,持仓量:0.27540243, 
日期:2019-05-31 23:59:00+00:00,价格:8555.0000,资产:2353.95,持仓量:0.27540243, 
日期:2019-06-01 23:59:00+00:00,价格:8544.0700,资产:2350.94,持仓量:0.27540243, 
日期:2019-06-02 23:59:00+00:00,价格:8725.9800,资产:2401.04,持仓量:0.27540243, 
日期:2019-06-03 23:59:00+00:00,价格:8115.8200,资产:2233.00,持仓量:0.27540243, 
日期:2019-06-04 23:59:00+00:00,价格:7687.0300,资产:2114.91,持仓量:0.27540243, 
日期:2019-06-05 23:59:00+00:00,价格:7776.5000,资产:2139.55,持仓量:0.27540243, 
日期:2019-06-06 23:59:00+00:00,价格:7786.7000,资产:2142.36,持仓量:0.27540243, 
日期:2019-06-07 23:59:00+00:00,价格:7980.5300,资产:2195.74,持仓量:0.27540243, sell
日期:2019-06-08 23:59:00+00:00,价格:7893.6200,资产:2167.46,持仓量:0.00000000, 
日期:2019-06-09 23:59:00+00:00,价格:7628.1300,资产:2167.46,持仓量:0.00000000, 
日期:2019-06-10 23:59:00+00:00,价格:7982.7500,资产:2167.46,持仓量:0.00000000, 
日期:2019-06-11 23:59:00+00:00,价格:7884.9000,资产:2167.46,持仓量:0.00000000, 
日期:2019-06-12 23:59:00+00:00,价格:8127.6400,资产:2167.46,持仓量:0.00000000, 
日期:2019-06-13 23:59:00+00:00,价格:8218.5400,资产:2167.46,持仓量:0.00000000, 
日期:2019-06-14 23:59:00+00:00,价格:8650.0000,资产:2167.46,持仓量:0.00000000, 
日期:2019-06-15 23:59:00+00:00,价格:8808.7000,资产:2167.46,持仓量:0.00000000, buy
日期:2019-06-16 23:59:00+00:00,价格:8953.3300,资产:2163.05,持仓量:0.24605927, 
...
日期:2019-11-12 23:59:00+00:00,价格:8821.9400,资产:1805.39,持仓量:0.20991364, 
日期:2019-11-13 23:59:00+00:00,价格:8777.1200,资产:1795.98,持仓量:0.20991364, 
日期:2019-11-14 23:59:00+00:00,价格:8646.6800,资产:1768.60,持仓量:0.20991364, sell
日期:2019-11-15 23:59:00+00:00,价格:8471.7300,资产:1728.32,持仓量:0.00000000, 
日期:2019-11-16 23:59:00+00:00,价格:8491.0200,资产:1728.32,持仓量:0.00000000, 
日期:2019-11-17 23:59:00+00:00,价格:8502.4000,资产:1728.32,持仓量:0.00000000, 
日期:2019-11-18 23:59:00+00:00,价格:8187.1700,资产:1728.32,持仓量:0.00000000, 
日期:2019-11-19 23:59:00+00:00,价格:8133.6400,资产:1728.32,持仓量:0.00000000, 
日期:2019-11-20 23:59:00+00:00,价格:8098.0100,资产:1728.32,持仓量:0.00000000, 
日期:2019-11-21 23:59:00+00:00,价格:7627.7400,资产:1728.32,持仓量:0.00000000, 
日期:2019-11-22 23:59:00+00:00,价格:7268.2300,资产:1728.32,持仓量:0.00000000, 
日期:2019-11-23 23:59:00+00:00,价格:7311.5700,资产:1728.32,持仓量:0.00000000, 
日期:2019-11-24 23:59:00+00:00,价格:6903.2800,资产:1728.32,持仓量:0.00000000, 
日期:2019-11-25 23:59:00+00:00,价格:7109.5700,资产:1728.32,持仓量:0.00000000, 
日期:2019-11-26 23:59:00+00:00,价格:7156.1400,资产:1728.32,持仓量:0.00000000, 
日期:2019-11-27 23:59:00+00:00,价格:7508.5200,资产:1728.32,持仓量:0.00000000, 
日期:2019-11-28 23:59:00+00:00,价格:7419.4900,资产:1728.32,持仓量:0.00000000, 
日期:2019-11-29 23:59:00+00:00,价格:7739.6800,资产:1728.32,持仓量:0.00000000, 
日期:2019-11-30 23:59:00+00:00,价格:7541.8900,资产:1728.32,持仓量:0.00000000, 
日期:2019-12-01 23:59:00+00:00,价格:7390.8900,资产:1728.32,持仓量:0.00000000, 
日期:2019-12-02 23:59:00+00:00,价格:7294.2800,资产:1728.32,持仓量:0.00000000, 
日期:2019-12-03 23:59:00+00:00,价格:7292.7100,资产:1728.32,持仓量:0.00000000, 
日期:2019-12-04 23:59:00+00:00,价格:7194.3200,资产:1728.32,持仓量:0.00000000, 
日期:2019-12-05 23:59:00+00:00,价格:7389.0000,资产:1728.32,持仓量:0.00000000, 
日期:2019-12-06 23:59:00+00:00,价格:7527.4700,资产:1728.32,持仓量:0.00000000, 
日期:2019-12-07 23:59:00+00:00,价格:7488.2100,资产:1728.32,持仓量:0.00000000, 
日期:2019-12-08 23:59:00+00:00,价格:7510.1100,资产:1728.32,持仓量:0.00000000, 
日期:2019-12-09 23:59:00+00:00,价格:7338.6400,资产:1728.32,持仓量:0.00000000, 
日期:2019-12-10 23:59:00+00:00,价格:7224.1300,资产:1728.32,持仓量:0.00000000, 
日期:2019-12-11 23:59:00+00:00,价格:7210.0000,资产:1728.32,持仓量:0.00000000, 
日期:2019-12-12 23:59:00+00:00,价格:7198.0800,资产:1728.32,持仓量:0.00000000, 
日期:2019-12-13 23:59:00+00:00,价格:7258.4800,资产:1728.32,持仓量:0.00000000, 
日期:2019-12-14 23:59:00+00:00,价格:7064.0500,资产:1728.32,持仓量:0.00000000, 
日期:2019-12-15 23:59:00+00:00,价格:7118.5900,资产:1728.32,持仓量:0.00000000, 
[2019-12-18 15:39:01.336101] INFO: Performance: Simulated 349 trading days out of 349.
[2019-12-18 15:39:01.336217] INFO: Performance: first open: 2019-01-01 00:00:00+00:00
[2019-12-18 15:39:01.336291] INFO: Performance: last close: 2019-12-15 23:59:00+00:00

file

我们可以看到这个收益还是挺不错的,从 1000刀持有到现在收益为 1728.32 刀,收益率为 72.83%, 如果以当前btc=7118.5900 usdt 价格计算,1000刀可以买入 0.140477 btc, 而如果用收益 1728.32 刀可兑换 0.24278 btc。

为者常成,行者常至