学习backtrader框架---给策略添加参数、指标的一些注意地方(第二回)

参数 params

在XXXStrategy(bt.Strategy)中定义类变量 params,形如

params = (
    ('myparam', 27),
    ('exitbars', 5),
)

然后就可以在策略中使用self.params

addsize

cerebro.addsizer(bt.sizers.FixedSize, stake=10)

注:设置固定的赌注

指标

The backtrader platform assumes that the Strategy has the indicator in
place for a good reason, to use it in the decision making process. And
it makes no sense to try to make decisions if the indicator is not yet
ready and producing values.

注:指标(indicator)放在 __init__里的原因是用它决策过程,如果指标没有准备好、没有产生值,就没有做决策的意义。

self.next

next will be 1st called when all indicators have already reached the minimum needed period to produce a value.

注:self.next 是当所有指标完成了最小的必要的周期的计算以后,第一个被调用的方法。

注册指标

Even if indicators are not explicitly added to a member variable of the strategy (like self.sma = MovingAverageSimple…), they will autoregister with the strategy and will influence the minimum period for next and will be part of the plotting.

注: 即使没有刻意的把指标赋给策略的成员变量,它们也会自动注册给策略。另外它们会影响调用self.next因为最小周期的原因。另外它们也是绘图的一部分。

Let’s Optimize (优化)

Instead of calling addstrategy to add a stratey class to Cerebro, the call is made to optstrategy. And instead of passing a value a range of values is passed.

注:优化的时候,是用cerebro.optstrategy代替cerebro.addstrategy,另外添加参数maperiod=range(10, 31)

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值