Skip to content

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

Open

Description

@HANdaQI

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

Activity

  1. HANdaQI commented on Sep 4, 2019

    @HANdaQI
    Author

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

  2. HANdaQI commented on Sep 4, 2019

    @HANdaQI
    Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions