区块键量化交易学习笔记(一)

本文记录了在Ubuntu系统上通过Docker安装Anaconda、Jupyter Notebook和Tushare的过程,包括Docker的安装、Anaconda的Docker镜像创建、Jupyter Notebook的配置,以及Tushare的安装和使用。
摘要由CSDN通过智能技术生成

一、安装篇
需要用到的软件工具Anaconda\Tushare\Jupyter Notebook,为方便以后使用不再配置建议使用Docker安装
1.安装Docker-ce
sudo apt-get remove docker docker-engine docker.io
sudo apt-get install  apt-transport-https  ca-certificates curl  software-properties-common
ubuntu18.04增加源及公钥
curl -fsSL  https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add
deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic stable
sudo apt-get update
sudo apt-get install docker-ce
2.Docker内安装Anaconda\Jupyter Notebook
docker pull centos:latest
docker run -it -p 宿主机端口:容器应用端口 centos:latest /bin/bash
# 在容器内进行

参考数据科学环境搭建的两个网站

https://blog.patricktriest.com/analyzing-cryptocurrencies-python/

http://www.360doc.com/content/17/1212/02/48630098_712275639.shtml(翻译)
yum install wget
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.1-Linux-x86_64.sh
bash Anaconda3-5.3.1-Linux-x86_64.sh
source ~/.bashrc
conda -V
conda upgrade -n base conda
conda install jupyter notebook
conda install ipython 
jupyter notebook --generate-config
# ipython 进入python shell交互 
 In [1]: from notebook.auth import passwd
 In [2]: passwd()
vi ~/.jupyter/jupyter_notebook_config.py 

c.NotebookApp.ip='*' # 设置所有ip皆可访问

c.NotebookApp.password = u'sha1:67c9e60b771089e11aed' #ipython上面生成的哈希值'  

c.NotebookApp.open_browser = False # 禁止自动打开浏览器

c.NotebookApp.port = 8080 #指定一个端口
c.NotebookApp.allow_password_change=False
# 启动jupyter notebook
jupyter notebook --no-browser --allow-root

安装jupyterlab同理

conda install -c conda-forge jupyter #一般不需要anaconda自带

conda install -c conda-forge jupyterlab

安装插件

conda install -c conda-forge nodejs

conda upgrade -n base nodejs #一定要升级不然装插件会出意外

具体插件参考https://zhuanlan.zhihu.com/p/101070029/

pip修改国内源添加-i https://pypi.tuna.tsinghua.edu.cn/simple

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple ipdb

conda修改为国内源

conda config --set show_channel_urls yes
nano .condarc

 

channels:
  - defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

3.安装Tushare
yum groupinstall "Development Tools"
yum install gcc libffi-devel python-devel openssl-devel 
pip install TA-Lib
如果安装不了需要自己编译
wget https://downloads.sourceforge.net/project/ta-lib/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz?r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fta-lib%2Ffiles%2Fta-lib%2F0.4.0%2F&ts=1509527628&use_mirror=nchc
#tar -xvf ta-lib-0.4.0-src.tar.gz
#cd ta-lib
#./configure 
#make && make install 
#echo "/usr/local/lib" >> /etc/ld.so.conf
#ldconfig
pip install TA-Lib
结果还是不行
conda install -c https://conda.anaconda.org/quantopian ta-lib
pip install tushare

安装graphlab用于图象处理(目前只支持python2.7)
参考网站

https://turi.com/download/install-graphlab-create.html?email=tangd86%40gmail.com&key=1825-54EB-DD4E-61BC-4ABB-0689-AFF7-F45A

# Create a new conda environment with Python 2.7.x
conda create -n gl-env python=2.7 
# Activate the conda environment
source activate gl-env
# Ensure pip is updated to the latest version
conda update pip

pip install --upgrade --no-cache-dir https://get.graphlab.com/GraphLab-Create/2.1/tangd86@gmail.com/1825-54EB-DD4E-61BC-4ABB-0689-AFF7-F45A/GraphLab-Create-License.tar.gz

import graphlab时报错,在终端内gl-env环境运行python2.7
[gl-env] python

>>> import graphlab

>>> graphlab.get_dependencies()

根据提示修改get_dependencies() 的源码,源码位置python->site-packages->graphlab->dependencies.py
(xzarchive_file, xzheaders) = urllib.urlretrieve('http://tukaani.org/xz/xz-5.2.1-windows.zip',reporthook = cbk)
(dllarchive_file, dllheaders) = urllib.urlretrieve('http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-gcc-libs-5.1.0-1-any.pkg.tar.xz',reporthook = cbk)

复制这两个网址下载这两个文件,然后在 dependencies.py 中注释掉这两句话分别改成:
xzarchive_file = '文件路径\\xz-5.2.1-windows.zip'
dllarchive_file = '文件路径\\mingw-w64-x86_64-gcc-libs-5.1.0-1-any.pkg.tar.xz'

# docker容器转镜像完成配置
sudo docker commit -m "镜像说明" -a “你的用户名" 容器id 镜像名:标签

Jupyter 插件

## 安装 ipywidgets, 会同时安装 widgetsnbextension
conda install ipywidgets
## 安装插件更丰富的jupyter_contrib_nbextensions
## Autopep8 插件需要额外安装库
conda install -c conda-forge jupyter_contrib_nbextensions
conda install autopep8 jupyter_contrib_nbextensions
## 安装插件管理器 jupyter_nbextensions_configurator
conda install -c conda-forge jupyter_nbextensions_configurator
折叠的标题Collapsible headings
通知机制Notify
折叠代码Code folding
轻轻一击就能获得简洁代码Autopep8
创建的所有变量的属性variable inspector

使用Tshare先要注册获得TOKEN,链接https://tushare.pro/register?reg=292031
import tushare as ts 
ts.set_token(065ae2706ad962f80030857336b65877bc579d9763a919b9018d2182) 
pro = ts.pro_api() 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值