Warning: file_exists(): open_basedir restriction in effect. File(/www/wwwroot/com.xiximiao.oa/com.cmstop/public/www/wp-content/db.php) is not within the allowed path(s): (/www/wwwroot/com.xiximiao.oa/com.cmstop/public/www/:/tmp/:/proc/:/var/log/nginx/:/www/wwwroot/com.xiximiao.oa/com.cmstop/public/:/www/wwwroot/com.xiximiao.oa/com.cmstop/vendor/:/www/wwwroot/com.xiximiao.oa/com.cmstop/ppk/) in /www/wwwroot/com.xiximiao.oa/com.cmstop/public/www/wp-includes/load.php on line 707
2084 ETF网格交易策略.py » 轻知量化 QMT、PTrade、聚宽策略分享交流平台

2084 ETF网格交易策略.py

策略源码

# 标题:ETF网格交易策略

# 导入函数库
import jqdata

# 初始化函数,设定要操作的股票、基准等等
def initialize(context):
    # 定义一个全局变量, 保存要操作的股票
    # 000001(股票:平安银行)
    g.security = '512900.XSHG'
    # 设定沪深300作为基准
    set_benchmark('000300.XSHG')
    # 开启动态复权模式(真实价格)
    set_option('use_real_price', True)
    run_daily(market_open, time='14:45:00')
    set_slippage(PriceRelatedSlippage(0.002))
    #设置参数 区间 网格间距 
    uplimit=1.5
    downlimit=0.9
    space=6
    number=3     #cash分隔份数
    #单位间隔
    g.unitprice=(uplimit-downlimit)/space
    #2019-04-01 收盘价格
    g.initialprice=0.976
    #get_price(security=g.security, end_date='2020-06-02',fields='close',count=10)['close'][-2]
    g.initial_buy=downlimit+0*g.unitprice
    g.initial_sell=downlimit+1*g.unitprice
    #将现金分割成几份
    g.cash = context.portfolio.cash/number
    #打印每个买卖区间
    for i in range(0,space+1):
        print(uplimit-i*g.unitprice)
    #run_daily(market_open, time='every_bar', reference_security='000300.XSHG')
    run_daily(after_market, time='after_close', reference_security='000300.XSHG')

2025-02-21
⚠️
本站资源大多来自网络,仅供网友学习交流,未经作者或上传书面授权,请勿作他用。
站长 vx: xiangyin615 或者 留言反馈 ,我们将尽快处理。
Notice: When you of the legal rights be violate, please stir to vx: xiangyin615
个人中心
购物车
优惠劵
搜索