BackTrader学习笔记

一、BackTrader介绍 BackTrader是开源免费的量化交易策略回测系统, 运行流程: 引入backtrader 加载和注入数据Feed(cerebro.adddata) 执行:cerebro.run() 可视化结果:cerebro.plot() 二、安装BackTrader 1、安装环境要求: Python 2.7 Python 3.2 / 3.3/ 3.4 / 3.5 pypy/pypy3 Matplotlib> = 1.4.1(如果需要绘图的话需要配置) 2、兼容Python2.x/3.x from __future__ import (absolute_import, division, print_function,unicode_literals) 3.1、通过pip安装: pip install backtrader 如果想同时安装matplotlib: pip install backtrader[plotting] 3.2、通过源安装 https://github.com/mementum/backtrader python安装源文件,自己搜索 3.3、通过pycharm安装 新建项目 -> Files -> Settings -> Project 项目名称 -> Project Interpreter -> 右侧加号,搜索backtrader Install Package即可 三、backtrader用法 1、使用前说明 常用数据名称: 开盘价,最高价,最低价,收盘价,成交量,持仓量 数据索引方式: 当前值:[0] 前一个值:[-1] 前2个值:[-2] …… 说明:所有的数字都是历史值,所以只能往后推 1、基本功能 from __future__ import (absolute_import, division, print_function,unicode_literals) #让python2兼容python3,python3环境下可以不用写 #引入backtrader import backtrader as bt if __name__ == '__main__': cerebro = bt....

December 23, 2019 · 2 min · 288 words · Aixin.me

Numpy学习笔记

生成数组 numpy.arange([start, ]stop, [step, ]dtype=None) 示例 np.arange(3) array([0, 1, 2]) np.arange(3.0) array([ 0., 1., 2.]) np.arange(3,7) array([3, 4, 5, 6]) np.arange(3,7,2) array([3, 5]) 生成随机整数 numpy.random.randint(low, high=None, size=None, dtype=‘l’) 示例 np.random.randint(2, size=10) array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0]) np.random.randint(1, size=10) array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) 随机排列 np.random.shuffle(x) 示例 arr = np.arange(10) np.random.shuffle(arr) arr [1 7 5 2 9 4 3 6 0 8] 随机采样...

November 6, 2019 · 1 min · 87 words · Aixin.me