python库catalyst运行遇到致命错误,求解决方法

问题遇到的现象和发生背景

python版本3.6.4
catalyst版本0.5.21
运行一段双均线策略后发生致命错误

问题相关代码,请勿粘贴截图

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

from catalyst import run_algorithm
from catalyst.api import 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 = 'dua1_moving_average'
SIGNAL_BUY = 'buy' # 买入信号
SIGNAL_SELL = 'sell' # 卖出信号
SIGNAL_INIT = '' # 观望信号
SHORT_WIN = 5 # 短周期窗口
LONG_WIN = 20 # 长周期窗口

def initialize(context):
"""
初始化
"""
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):
"""
在每个交易周期上运行的策略
"""
context.i += 1 # 记录交易周期
if context.i < LONG_WIN + 2:
# 如果交易周期果断,无法计算均线,则跳过循环
return

# 获得历史价格
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(windows=LONG_WIN).mean()

# 双均线策略
# 短期均线上穿长期均线,做多
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)
    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)
# 输出信息
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):
# 保存交易记录
perf.to_csv('./performance.csv')

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

# 图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'],
        market='买',
        s=100,
        c='green',
        label=''
    )
    ax2.scatter(
        sell_df.index.to_pydatetime(),
        perf.loc[sell_df.index, 'price'],
        market='卖',
        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, share=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,
analyze=analyze,
handle_data=handle_data,
exchange_name='binance',
algo_namespace=NAMESPACE,
quote_currency='usdt',
start=pd.to_datetime('2017-10-01', utc=True),
end=pd.to_datetime('2018-10-01', utc=True)
)

运行结果及报错内容

[2022-04-08 03:50:13.522477] INFO: run_algo: Catalyst version 0.5.21
[2022-04-08 03:50:13.522477] WARNING: run_algo: Catalyst is currently in ALPHA. It is going through rapid development and it is subject to errors. Please use carefully. We encourage you to report any issue on GitHub: https://github.com/enigmampc/catalyst/issues
[2022-04-08 03:50:16.530131] INFO: run_algo: running algo in backtest mode
[2022-04-08 03:50:16.924870] INFO: exchange_algorithm: initialized trading algorithm in backtest mode
Fatal Python error: Acquisition count is -1 (line 22759)
Traceback (most recent call last):
File "catalyst\gens\sim_engine.pyx", line 109, in iter
GeneratorExit

Process finished with exit code -1073740791 (0xC0000409)

我的解答思路和尝试过的方法
我想要达到的结果

希望程序能正常运行