Giter VIP home page Giter VIP logo

Comments (2)

HANdaQI avatar HANdaQI commented on July 26, 2024

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.

HANdaQI avatar HANdaQI commented on July 26, 2024

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

from quantdigger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.