RQAlpha安装、配置指南。

RQAlpha开发部署手册

Docker 配置

镜像制作

参考 github.com:yirami/quantitative-investment-docker/Dockerfile

Docker Hub 已发布多个镜像版本:

  1. docker pull yirami/rqalpha-slim-buster:v342
  2. docker pull yirami/rqalpha-slim-buster:dev_v342
  3. docker pull yirami/rqalpha-slim-buster:v442
  4. docker pull yirami/rqalpha-slim-buster:dev
  1. Python

  2. TA-Lib

# download http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
# then compile and install
tar -xzf ta-lib-0.4.0-src.tar.gz
cd ta-lib/
./configure --prefix=/usr
make
sudo make install
# install python wrapper
# ensure pipenv environment
cd project_dir
pipenv shell
pipenv install TA-Lib --pypi-mirror https://pypi.tuna.tsinghua.edu.cn/simple --skip-lock
  1. Cython
pip install Cython --user
  1. line-profiler
# 需要提前安装Cython,从项目pipenv环境(可切换目录)执行如下安装
git clone https://github.com/rkern/line_profiler.git
find line_profiler -name '*.pyx' -exec cython {} \;
cd line_profiler
pipenv install ~/Downloads/line_profiler/ --skip-lock
pip install .
# 如果出错(fatal error: Python.h: No such file or directory)
# install header files and static libraries for python dev
#  for Ubuntu 18.04 LTS
sudo apt install python3-dev
#  and others take https://stackoverflow.com/questions/21530577/fatal-error-python-h-no-such-file-or-directory as reference
  1. bcolz
# 参考(https://github.com/Blosc/bcolz)安装指导
# 下载 c-blosc(https://github.com/Blosc/c-blosc/releases)
cd c-blosc
mkdir build
cd build
# define install dir == /usr/local
cmake -DCMAKE_INSTALL_PREFIX=/usr/local ..
# (可选的)安装测试
ctest
sudo cmake --build . --target install
# 下载 bcolz==1.2.0
git clone https://github.com/Blosc/bcolz.git
cd bcolz
git checkout 0e9addf
python setup.py build_ext --inplace --blosc=/usr/local
# 如果提示 ImportError(libblosc.so.1: cannot open shared object file),导入环境
export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
pipenv install ~/Downloads/bcolz/ --skip-lock
  1. rqalpha
# 安装
pipenv install rqalpha --pypi-mirror https://pypi.tuna.tsinghua.edu.cn/simple --skip-lock
# 验证
rqalpha version
# 验证
import tushare
print(tushare.__version__)
  1. tushare
# 安装
pipenv install tushare --pypi-mirror https://pypi.tuna.tsinghua.edu.cn/simple --skip-lock

镜像使用

参考 github.com:yirami/quantitative-investment-docker/run-docker.sh

# 拉取
docker pull yirami/rqalpha-slim-buster:dev
# 运行
ProcNumber=`docker ps -a | grep ${USER}.rqalpha | wc -l`
if [ $ProcNumber -le 0 ];then
  echo "start ..."
else
  echo "stop and then start ..."
  docker stop ${USER}.ssd
fi
xhost +local:${USER}
SHARE_DIR=/mnt/hgfs/GitRepo/
WORK_DIR=/share/yirami
PROJECT=docker-rqalpha
docker run -it --rm --name ${USER}.rqalpha \
-e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix \
-v ${SHARE_DIR}:${WORK_DIR} \
-w ${WORK_DIR}/${PROJECT} \
-e QT_X11_NO_MITSHM=1 \
--ipc=host \
yirami/rqalpha-slim-buster:latest \
/bin/bash

RQAlpha 配置

安装 Mod

# 进入模块目录
cd /share/yirami/mod/rqalpha-mod-tushare
# pip 安装
pip install -e .
# 启用Mod
rqalpha mod enable tushare
# 确认
rqalpha mod list

开发及部署

Pycharm

问题
  1. 重新安装numpy等库

由于numpy、pandas等包的复杂环境,Pycharm运行中可能出现如下错误

RuntimeError: implement_array_function method already has a docstring

不要慌,此时将这些库卸载,重新安装则稳如老狗

可能涉及的库有

  • numpy
  • scipy
  • pandas
  • matplotlib
  • ...

个人理解是先装numpy