您的位置:首页 > 运维架构 > Docker

PythonStock(18):使用docker 安装 quantlib 源码安装&lib库安装

2018-01-11 11:04 531 查看

前言

使用Python开发一个股票项目。

项目地址:

https://github.com/pythonstock/stock

相关资料:

http://blog.csdn.net/freewebsys/article/details/78294566

主要使用开发语言是python。

使用的lib库是pandas,tushare,TensorFlow,tornado等。

本文的原文连接是: http://blog.csdn.net/freewebsys/article/details/79031223

未经博主允许不得转载。

博主地址是:http://blog.csdn.net/freewebsys

1,关于quantlib

QuantLib 是一个专注于 Quantitative Finance 计算与开发的 C++ 库。

是非常大的一个lib库。

官方网站是:

http://quantlib.org/index.shtml

核心代码是c++ 写的,使用swig进行封装,支持python,java等好多语言。

github 项目地址:

https://github.com/lballabio/quantlib

是BSD开源项目。

学习文档:

http://gouthamanbalaraman.com/blog/quantlib-python-tutorials-with-examples.html

关于quantlib的文档挺少的,还是这个哥们写的比较全面。以后慢慢研究。

2,编译安装quantlib

linux安装文档:

http://quantlib.org/install/linux-python.shtml

首先要准备 libboost库

然后开始编译 quantlib ,发现编译的时间超级的长。

从编译出现的一些问题,到找到尝试。折腾了不少时间:

整理了下安装脚本如下:

cd /root
echo "############ 1 download file ############ "
curl -o QuantLib-1.11.tar.gz https://codeload.github.com/lballabio/QuantLib/tar.gz/QuantLib-v1.11 curl -o QuantLib-SWIG-1.11.tar.gz https://codeload.github.com/lballabio/QuantLib-SWIG/tar.gz/QuantLib-SWIG-v1.11 echo "############ 2 install ubuntu libs ############ "
apt-get update && apt-get install -y python-dev swig automake autoconf libtool libboost-all-dev
#echo "############ 3 uncompress tar files ############ "
tar -zxvf QuantLib-1.11.tar.gz && tar -zxvf QuantLib-SWIG-1.11.tar.gz
echo "############ 5 install quantlib ############ "
cd QuantLib-QuantLib-v1.11 && ./autogen.sh && \
./configure && make && make install && ldconfig
echo "############ 5 install quantlib-python3 ############ "
cd ../QuantLib-SWIG-QuantLib-SWIG-v1.11 && ./autogen.sh && ./configure PYTHON=/usr/bin/python3 && \
make -C Python && make -C Python install
echo "############ 6 rm tmp files ############ "
rm -rf /root/QuantLib-QuantLib-v1.11 /root/QuantLib-SWIG-QuantLib-SWIG-v1.11
rm -f /root/QuantLib-1.11.tar.gz /root/QuantLib-SWIG-1.11.tar.gz


别看就是个编译,不知道为啥这么耗时间。

编译 quantlib 就花了一个小时,编译 QuantLib-SWIG 我都放到晚上做了。

然后第二天再来看。

3,编译docker镜像

#需要编译数个小时,慢慢等待。
RUN cd /root && curl -o QuantLib-1.11.tar.gz https://codeload.github.com/lballabio/QuantLib/tar.gz/QuantLib-v1.11 && \
curl -o QuantLib-SWIG-1.11.tar.gz https://codeload.github.com/lballabio/QuantLib-SWIG/tar.gz/QuantLib-SWIG-v1.11 && \
apt-get update && apt-get install -y python-dev swig automake autoconf libtool libboost-all-dev && \
tar -zxvf QuantLib-1.11.tar.gz && tar -zxvf QuantLib-SWIG-1.11.tar.gz && \
cd QuantLib-QuantLib-v1.11 && ./autogen.sh && ./configure && make && make install && ldconfig
# 变成两个任务,防止第二个失败了,人崩溃了。
RUN cd /root/QuantLib-SWIG-QuantLib-SWIG-v1.11 && ./autogen.sh && ./configure PYTHON=/usr/bin/python3 && \
make -C Python && make -C Python install && apt-get remove -y python-dev swig automake autoconf libtool && \
rm -rf /root/QuantLib-QuantLib-v1.11 && rm -rf /root/QuantLib-SWIG-QuantLib-SWIG-v1.11  && \
rm -f /root/QuantLib-1.11.tar.gz  /root/QuantLib-SWIG-1.11.tar.gz


编译之后可以使用了:

>>> import QuantLib as ql
>>> print(ql.__version__)
1.11


4,python2 直接安装

如果是python2 的环境直接使用apt-get 进行安装:

apt-get install -y quantlib-python


安装完成之后的版本是 1.7 是 2015 年发布的。

>>> import QuantLib as ql
>>> print(ql.__version__)
1.7


最新的是 1.11 ,要想安装最新的还是源码安装。

要想方便还是 apt-get 安装快。

5,总结

编译quantlib 没有啥技术含量,就是编译时间太长了。

最新的 1.11 使用 1.7 的版本也没有啥问题。

本文的原文连接是: http://blog.csdn.net/freewebsys/article/details/79031223

未经博主允许不得转载。

博主地址是:http://blog.csdn.net/freewebsys
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python stock quantlib