Comments (2)
from quantdigger import *
class DemoStrategy(Strategy):
""" 策略A1 """
def on_init(self, ctx):
"""初始化数据"""
ctx.ma10 = MA(ctx.close, 10, 'ma10', 'y', 1)
ctx.ma20 = MA(ctx.close, 20, 'ma20', 'b', 1)
ctx.dt = DateTimeSeries()
ctx.month_price = NumberSeries()
def on_bar(self, ctx):
ctx.dt.update(ctx.datetime)
if ctx.dt[1].month != ctx.dt[0].month:
ctx.month_price.update(ctx.close)
if ctx.curbar > 20:
if ctx.pos() == 0 and ctx.ma10[2] < ctx.ma20[2] and ctx.ma10[1] > ctx.ma20[1]:
ctx.buy(ctx.close, 100)
ctx.plot_text("buy", 1, ctx.curbar, ctx.close, "buy", 'black', 15)
elif ctx.pos() > 0 and ctx.ma10[2] > ctx.ma20[2] and
ctx.ma10[1] < ctx.ma20[1]:
ctx.sell(ctx.close, ctx.pos())
ctx.plot_text("sell", 1, ctx.curbar, ctx.close, "sell", 'blue', 15)
#ctx.plot_line("month_price", 1, ctx.curbar, ctx.month_price, 'y--', lw=2)
return
def on_exit(self, ctx):
return
if name == 'main':
import timeit
from quantdigger.digger.analyze import AnalyzeFrame
import matplotlib.pyplot as plt
start = timeit.default_timer()
set_config({'source': 'csv','data_path': '/Users/a031/Desktop/lianghua/SourceData'})
profiles = add_strategies(['00001.HK-1.DAY'], [
{
'strategy': DemoStrategy('A1'),
'capital': 50000.0,
},],['2019-1-1','2019-8-20'])
stop = timeit.default_timer()
print("运行耗时: %d秒" % ((stop - start)))
AnalyzeFrame(profiles[0])
plt.show()
from quantdigger.
add_strategy()我给他添加了个参数[开始时间,结束时间],因为我看原本好像是默认的
from quantdigger.
Related Issues (20)
- 针对不同的合约可设置不同的费率。
- 支持小于日线的回测吗 HOT 1
- 现版本支持自定义数据源格式么 HOT 1
- 策略组合DEMO 的示例代码运行不了 HOT 4
- 直接安装Anaconda是不是好一些? HOT 1
- done HOT 3
- 关于 max_drawdown(networth) 的疑问
- 执行demo的时候,提示这个错 HOT 3
- 如何支持复权计算
- matplotlib.finance HOT 1
- Atlas (http://math-atlas.sourceforge.net/) libraries not found.
- AttributeError: 'SourceWrapper' object has no attribute 'open'
- 运行策略组合DEMO 源码 后报错,运行不了呢
- 请教数据源 HOT 1
- 请问下是在python2还是python3下面运行,目前我这2个都报错,。。
- 寻求课程合作 HOT 1
- 又是一个弃坑的项目吗? HOT 1
- demo都跑不起来,各种报错,无奈弃了 ,唉
- 有用这个项目的交流群吗,一起交流下?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quantdigger.