Backtrader 量化平台研究

Backtrader 中国期货回测

Backtrader 简介

先说几句题外话,Backtrader 到底谁在用?一下内容转自backtrader官方网站中References部分:https://www.backtrader.com/home/references/who-is-using-it/
Who is using it
我简单说几点:

  1. 2家 Eurostoxx50 银行
  2. 6家量化私募
    不过这些都是很早以前的数据,还有一些做能源交易的对冲基金。
    reddit里面有个algo trading 板块,里面有人提了backtrader到底有多火的问题?一下引用了部分:
    No. There is not a list. This is actually outdated: the number of banks remains at 2 (there may be more, but I don’t know it), but there are more than 6 firms using it for internal purposes, including for example companies working in energy markets, due to the compensation feature which allows buying and selling different assets which compensate each other (this is probably not available in zipline) which allows to model using spot and futures prices (this is a particularity of energy markets to avoid having the actual goods delivered to you)

The thing here is that one would have to define usage. I can for example quote what someone from one of those banks told me: “we use backtrader to quickly prototype our ideas and backtest them. If they prove to be what we expected and after further refinement, they will be rewritten in Java and put into our production system”

This is actually the same scheme which one of the Quant firms (which I personally visited) used: prototyping in backtrader and production in Java.

As you may imagine I don’t track the lifes of those using backtrader, so it may also be that some of the banks and companies decided to no longer use backtrader.

I do also guess that some banks and quant firms use zipline following the same scheme.

Backtrader 螺纹钢回测

数据准备:这里用本地csv数据,数据频率是15分钟,全部历史(2009-03-27到2020-06-18)。
在这里插入图片描述
在这里插入图片描述
跑的是sar策略,下面贴上部分代码

# -*- coding:utf-8 -*-
# 引入python3.X的一些特性
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
import datetime  # For datetime objects
import backtrader as bt
import backtrader
### BackTrader 量化交易平台资源获取 对于希望深入了解 `BackTrader` 的用户来说,获取高质量的学习资料至关重要。虽然直接提供特定 PDF 文件下载链接可能涉及版权问题[^1],可以建议访问官方文档网站以及合法渠道购买或借阅相关书籍。 #### 官方文档与社区资源 - **官方网站**: 访问 [BackTrader官网](https://www.backtrader.com/) 获取最新版本说明、教程和支持论坛。 - **GitHub仓库**: 浏览 [BackTrader GitHub页面](https://github.com/mementum/backtrader),这里不仅有详细的安装指南和技术细节描述,还有活跃开发者贡献的各种案例研究和脚本分享。 #### 合法途径获得专业图书 为了更深入理解如何应用 `BackTrader` 进行实际交易模拟及数据分析工作,推荐通过正规书店或电子书平台(如亚马逊 Kindle Store 或者国内当当网等)查找并购买《BackTrader量化交易图解》这类专著。这些书籍通常会附带丰富的实例解析和图表展示,有助于读者更好地掌握该工具的应用技巧[^2]。 ```python import backtrader as bt class MyStrategy(bt.Strategy): params = ( ('maperiod', 15), ) def __init__(self): self.sma = bt.indicators.SimpleMovingAverage( self.data.close, period=self.params.maperiod) def next(self): if not self.position: if self.data.close[0] > self.sma[0]: self.buy() elif self.data.close[0] < self.sma[0]: self.sell() cerebro = bt.Cerebro() data = bt.feeds.YahooFinanceData(dataname='AAPL', fromdate=datetime(2020, 1, 1), todate=datetime(2021, 1, 1)) cerebro.adddata(data) cerebro.addstrategy(MyStrategy) print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue()) cerebro.run() print('Ending Portfolio Value: %.2f' % cerebro.broker.getvalue()) ```
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值