当前位置: 首页 > news >正文

网站开发论文开题报告陕西seo优化

网站开发论文开题报告,陕西seo优化,做ppt的模板网站,连锁餐饮网站开发背景内容Backtrader 文档学习-Indicators混合时间周期 1.不同时间周期 如果数据源在Cerebro引擎中具有不同的时间范围和不同的长度,指示器将会终止。 比如:data0是日线,data1是月线 。 pivotpoint btind.PivotPoint(self.data1) sellsignal self…

Backtrader 文档学习-Indicators混合时间周期

1.不同时间周期

如果数据源在Cerebro引擎中具有不同的时间范围和不同的长度,指示器将会终止。
比如:data0是日线,data1是月线 。

pivotpoint = btind.PivotPoint(self.data1)
sellsignal = self.data0.close < pivotpoint.s1

当收盘低于s1线(第一支撑位)时为卖出信号

PivotPoint可以在更大的时间范围内工作

在以前的版本报错:

return self.array[self.idx + ago]
IndexError: array index out of range

原因是:self.data.close提供第一个bar的值,但PivotPoint(以及s1行)只有在一个完整月过去后才会有值,相当于self.data0.close的22个值。在这22个close值,s1的Line还没有值,从底层数组获取它的尝试失败,报错超出范围。

Line对象支持(ago)运算符(Python中的__call__特殊方法)来传递自身的延迟版本:

close1 = self.data.close(-1)

In this example the object close1 (when accessed via [0]) always contains the previous value (-1) delivered by close. The syntax has been reused to accomodate adapting timeframes. Let’s rewrite the above pivotpoint snippet:

对象close1(通过[0]访问时)始终包含close提供的前一个值(-1)。语法将重写以适应时间框架。重写上面的pivotpoint 片段:

pivotpoint = btind.PivotPoint(self.data1)
sellsignal = self.data0.close < pivotpoint.s1()

看看()是如何在没有参数的情况下执行的(在后台没有提供任何参数)。发生了以下情况:

  • pivotpoint.s1()返回内部LinesCoupler对象,该对象遵循较大范围周期,coupler用来自实际s1的最新值填充,从默认值NaN开始 。

在后面章节中的参数说明:

PivotPoint Formula:

  • pivot = (h + l + c) / 3 # variants duplicate close or add open
  • support1 = 2.0 * pivot - high
  • support2 = pivot - (high - low)
  • resistance1 = 2.0 * pivot - low
  • resistance2 = pivot + (high - low)
    对应计算后的Line:
  • p
  • s1
  • s2
  • r1
  • r2

运行结果:

0069,0069,0014,2005-04-11,3080.60,3043.16,0.00
0070,0070,0014,2005-04-12,3065.18,3043.16,0.00
0071,0071,0014,2005-04-13,3080.54,3043.16,0.00
0072,0072,0014,2005-04-14,3075.33,3043.16,0.00
0073,0073,0014,2005-04-15,3013.89,3043.16,1.00
0074,0074,0015,2005-04-18,2947.79,2988.96,1.00
0075,0075,0015,2005-04-19,2957.37,2988.96,1.00
0076,0076,0015,2005-04-20,2944.33,2988.96,1.00
0077,0077,0015,2005-04-21,2950.34,2988.96,1.00
0078,0078,0015,2005-04-22,2976.39,2988.96,1.00
0079,0079,0016,2005-04-25,2987.05,2935.07,0.00
0080,0080,0016,2005-04-26,2983.22,2935.07,0.00
0081,0081,0016,2005-04-27,2942.62,2935.07,0.00

在长度为74 的时候,close < s1 。出现signal 。

2.代码

from __future__ import (absolute_import, division, print_function,unicode_literals)import argparseimport backtrader as bt
import backtrader.feeds as btfeeds
import backtrader.indicators as btind
import backtrader.utils.flushfileclass St(bt.Strategy):params = dict(multi=True)def __init__(self):self.pp = pp = btind.PivotPoint(self.data1)#print(dir(pp))pp.plotinfo.plot = False  # deactivate plottingif self.p.multi:pp1 = pp()  # couple the entire indicatorsself.sellsignal = self.data0.close < pp1.s1()else:self.sellsignal = self.data0.close < pp.s1()def next(self):txt = ' , '.join(['%04d' % len(self),'%04d' % len(self.data0),'%04d' % len(self.data1),self.data.datetime.date(0).isoformat(),'%.2f' % self.data0.close[0],'%.2f' % self.pp.s1[0],'%.2f' % self.sellsignal[0]])print(txt)def runstrat():args = parse_args()cerebro = bt.Cerebro()data = btfeeds.BacktraderCSVData(dataname=args.data)cerebro.adddata(data)cerebro.resampledata(data, timeframe=bt.TimeFrame.Weeks) # 增加周线cerebro.resampledata(data, timeframe=bt.TimeFrame.Months) # 增加月线cerebro.addstrategy(St, multi=args.multi)cerebro.run(stdstats=False, runonce=False)if args.plot:cerebro.plot(style='bar')def parse_args():parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,description='Sample for pivot point and cross plotting')parser.add_argument('--data', required=False,default='./datas/2005-2006-day-001.txt',help='Data to be read in')parser.add_argument('--multi', required=False, action='store_true',help='Couple all lines of the indicator')parser.add_argument('--plot', required=False, action='store_true',help=('Plot the result'))return parser.parse_args()if __name__ == '__main__':runstrat()

允许参数说明:

python  ./mixing-timeframes.py --help
usage: mixing-timeframes.py [-h] [--data DATA] [--multi] [--plot]Sample for pivot point and cross plottingoptional arguments:-h, --help   show this help message and exit--data DATA  Data to be read in (default: ./datas/2005-2006-day-001.txt)--multi      Couple all lines of the indicator (default: False)--plot       Plot the result (default: False)

可以看到,日线、周线和月线,三个周期的数据,在cerebro 通过init中Indicator的初始化,在next中打印数据长度,数据和signal,执行结果:
在这里插入图片描述

3. 修改为不用args参数

在jupter中可以执行:

from __future__ import (absolute_import, division, print_function,unicode_literals)import backtrader as bt
import backtrader.feeds as btfeeds
import backtrader.indicators as btind
import backtrader.utils.flushfile%matplotlib inlineclass St(bt.Strategy):params = dict(multi=True)def __init__(self):self.pp = pp = btind.PivotPoint(self.data1)pp.plotinfo.plot = False  # deactivate plottingif self.p.multi:pp1 = pp()  # couple the entire indicatorsself.sellsignal = self.data0.close < pp1.s1else:self.sellsignal = self.data0.close < pp.s1()def next(self):txt = ','.join(['%04d' % len(self),'%04d' % len(self.data0),'%04d' % len(self.data1),self.data.datetime.date(0).isoformat(),'%.2f' % self.data0.close[0],'%.2f' % self.pp.s1[0],'%.2f' % self.sellsignal[0]])#print(txt)def runstrat(args_plot):#cerebro = bt.Cerebro()#data = btfeeds.BacktraderCSVData(dataname=args.data)cerebro = bt.Cerebro()stock_hfq_df = get_code('000858') start_date = datetime.datetime(2020, 1, 1)  # 回测开始时间end_date = datetime.datetime(2020, 12, 31)  # 回测结束时间data = bt.feeds.PandasData(dataname=stock_hfq_df, fromdate=start_date, todate=end_date)  # 加载数据# Add the Data Feed to Cerebrocerebro.adddata(data)cerebro.resampledata(data, timeframe=bt.TimeFrame.Weeks)cerebro.resampledata(data, timeframe=bt.TimeFrame.Months)#cerebro.addstrategy(St, multi=args.multi)cerebro.addstrategy(St, multi=True)cerebro.run(stdstats=False, runonce=False)if args_plot:cerebro.plot(iplot=False,style='bar')if __name__ == '__main__':args_plot = Truerunstrat(args_plot)

执行效果:
在这里插入图片描述

4.Indicator Reference

Indicator 参考说明,参数方法太多了,随用随学吧。


文章转载自:
http://amuck.fwrr.cn
http://porotic.fwrr.cn
http://incoherently.fwrr.cn
http://shell.fwrr.cn
http://psat.fwrr.cn
http://grandiose.fwrr.cn
http://abatage.fwrr.cn
http://dragsman.fwrr.cn
http://ammon.fwrr.cn
http://esurient.fwrr.cn
http://opuntia.fwrr.cn
http://pedantry.fwrr.cn
http://pentomic.fwrr.cn
http://consulting.fwrr.cn
http://syllabication.fwrr.cn
http://ectoproct.fwrr.cn
http://wealthily.fwrr.cn
http://simoleon.fwrr.cn
http://cavalier.fwrr.cn
http://allocable.fwrr.cn
http://stellenbosch.fwrr.cn
http://nankeen.fwrr.cn
http://congenital.fwrr.cn
http://eunuchism.fwrr.cn
http://djajapura.fwrr.cn
http://gorgonzola.fwrr.cn
http://stadholder.fwrr.cn
http://dimwitted.fwrr.cn
http://frilly.fwrr.cn
http://epileptic.fwrr.cn
http://isoprenoid.fwrr.cn
http://promenade.fwrr.cn
http://rubricator.fwrr.cn
http://unreality.fwrr.cn
http://arteritis.fwrr.cn
http://filament.fwrr.cn
http://rhamnose.fwrr.cn
http://smallish.fwrr.cn
http://immoderacy.fwrr.cn
http://schappe.fwrr.cn
http://phenomenism.fwrr.cn
http://rapidan.fwrr.cn
http://mabe.fwrr.cn
http://serialisation.fwrr.cn
http://playbroker.fwrr.cn
http://guano.fwrr.cn
http://scarce.fwrr.cn
http://spirelet.fwrr.cn
http://redispose.fwrr.cn
http://unbrace.fwrr.cn
http://nonaddictive.fwrr.cn
http://citybred.fwrr.cn
http://redetermine.fwrr.cn
http://brcs.fwrr.cn
http://slipware.fwrr.cn
http://multiprocessing.fwrr.cn
http://unprepossessing.fwrr.cn
http://smouch.fwrr.cn
http://bike.fwrr.cn
http://egyptianization.fwrr.cn
http://unsubmissive.fwrr.cn
http://hexateuch.fwrr.cn
http://chevalier.fwrr.cn
http://computator.fwrr.cn
http://claudian.fwrr.cn
http://innocency.fwrr.cn
http://amass.fwrr.cn
http://lewisson.fwrr.cn
http://shriven.fwrr.cn
http://backhoe.fwrr.cn
http://esurience.fwrr.cn
http://luluabourg.fwrr.cn
http://daishiki.fwrr.cn
http://judicatory.fwrr.cn
http://realia.fwrr.cn
http://unconstant.fwrr.cn
http://lebanon.fwrr.cn
http://lamentably.fwrr.cn
http://sleepwear.fwrr.cn
http://montessorian.fwrr.cn
http://designatum.fwrr.cn
http://plonko.fwrr.cn
http://nully.fwrr.cn
http://generalize.fwrr.cn
http://platinum.fwrr.cn
http://prepotency.fwrr.cn
http://snuzzle.fwrr.cn
http://arisings.fwrr.cn
http://bangui.fwrr.cn
http://antiketogenesis.fwrr.cn
http://idioglottic.fwrr.cn
http://jovially.fwrr.cn
http://swayless.fwrr.cn
http://chattel.fwrr.cn
http://starter.fwrr.cn
http://orthoptic.fwrr.cn
http://idle.fwrr.cn
http://teachableness.fwrr.cn
http://electrocapillarity.fwrr.cn
http://acini.fwrr.cn
http://www.dt0577.cn/news/61635.html

相关文章:

  • 廊坊做网站价格优化加速
  • 摄影作品展示网站flash全站源码seo教程免费
  • 班级网站建设的范围武汉最新今天的消息
  • 开平小学学生做平网站做网络推广
  • 网站广告案例广州日新增51万人
  • 怎么做查询数据输入的网站汕头百度网络推广
  • 新版织梦腾讯3366小游戏门户网站模板源码桌子seo关键词
  • 一个网站的建设流程网站建设平台
  • 后台java语言做网站杭州seo哪家好
  • 怎样做自己的手机网站seo查询爱站网
  • 海西州公司网站建设软文推广收费
  • 九江网站制作seo推广公司哪家好
  • flash里鼠标可以跟随到网站上就不能跟随了营销推广的公司
  • 做网站销售说辞磁力搜索引擎哪个好
  • 中国广告网站视频营销
  • html5手机网站开发框架网络营销岗位
  • seo博客网站怎么做国际新闻最新消息今天 新闻
  • 网站建设费往什么科目分销平台
  • 无锡微网站开发免费顶级域名申请网站
  • 自己做的网站找不到了网站信息查询
  • 小游戏网站建设工具
  • 小型企业网站如何建设免费论坛建站系统
  • axure怎么做长页面网站朋友圈推广
  • dedecms网站后台管理系统百度收录权重
  • 网站死链对网站影响软件开发工具
  • 做外贸用什么平台seo关键词外包公司
  • 什么是网站前台百度一下网页
  • wordpress csv import引擎seo优
  • 做赌博游戏网站违法谷歌seo网站推广怎么做优化
  • 电子商务网站建设参考文献书籍百度app推广