Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一到画图就直接系统重启 #49

Open
HANdaQI opened this issue Sep 4, 2019 · 2 comments
Open

一到画图就直接系统重启 #49

HANdaQI opened this issue Sep 4, 2019 · 2 comments

Comments

@HANdaQI
Copy link

HANdaQI commented Sep 4, 2019

MACOS配置的本地的csv数据源,调了很久终于可以跑起来了,结果一到plt.show()就系统直接重启了,,,,,一头雾水!

@HANdaQI
Copy link
Author

HANdaQI commented Sep 4, 2019

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()

@HANdaQI
Copy link
Author

HANdaQI commented Sep 4, 2019

add_strategy()我给他添加了个参数[开始时间,结束时间],因为我看原本好像是默认的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant