1. 導讀
兼容backtrader, pyfolio, zipline, yfinance的安裝版本
save Backtrader and Pyfolio plot image 储存backtrader和pyfolio的图片
2. 前言
所謂一步一坑,當項目要自動化部署時,就要自己填坑了。
3. 安裝流程
3.1 Dockerfile
FROM amd64/python:3.6 ENV PYTHONUNBUFFERED 1 RUN pip install --upgrade pip COPY requirements1.txt /app/requirements1.txt COPY requirements2.txt /app/requirements2.txt ADD .fix /app/.fix WORKDIR /app RUN pip install --no-cache-dir -r requirements1.txt RUN pip install --no-cache-dir -r requirements2.txt --no-dependencies ADD .fix /usr/local/lib/python3.6/site-packages CMD ["-h"] ENTRYPOINT ["/usr/local/bin/python"]
有兩點注意事項:
a. yfinance要另外安裝,因它不支援舊版的pandas。
b. /.fix/ 是修改過的site-packages。因要支持backtrader使用zipline,pyfolio,PyPortfolioOpt來繪圖。
庫 | site-packages |
1. backtrader | /backtrader/plot/locator.py |
2. pyfolio |
/pyfolio/plotting.py |
3. yfinance | /yfinance/base.py |
3.2 requirements1.txt
backtrader==1.9.76.123 pyfolio==0.9.2 zipline==1.3.0 pandas==0.22.0 PyPortfolioOpt==1.5.2 mplfinance==0.12.9b7 multitasking==0.0.11 deap==1.3.3 Flask==2.0.3 mysql-connector-python==8.0.33
注意,必需是這版本的backtrader,zipline,pyfolio,PyPortfolioOpt才能兼容。
3.2 requirements2.txt
yfinance==0.1.70
暇後是獨立安裝,不支持舊版的庫。
3.3 build & run docker
docker build -t dbpower/backtrader:3.6.a .
build docker image
docker run -it dbpower/backtrader:3.6.a /bin/bash
inside docker image
docker run --name dbpower_backtrader_001 --rm -t -v ~/PycharmProjects/dbpower.backtrader.001/app:/app dbpower/backtrader:3.6.a /app/main.py >> ~/PycharmProjects/dbpower.backtrader.001/log/main_`date +\%Y\%m\%d_\%H\%M\%S`.log 2>&1
run *.py
标签:pyfolio,--,app,backtrader,腳手,docker,txt From: https://www.cnblogs.com/chenkuang/p/17355935.html