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
2094 小资金短线策略.py » 轻知量化 QMT、PTrade、聚宽策略分享交流平台

2094 小资金短线策略.py

# 标题:小资金短线策略
# 作者:rickch

'''
1、计算尾盘半小时收益率
2.计算尾盘半小时乖离率
3.合并两个因子排序选股
'''
import numpy as numpy
import pandas as pd

def initialize(context):
    # 设定沪深300作为基准
    set_benchmark('000905.XSHG')
    # True为开启动态复权模式,使用真实价格交易
    set_option('use_real_price', True) 
    # 设定成交量比例
    set_order_cost(OrderCost(close_tax=0.001, open_commission=0.0003, close_commission=0.0003, min_commission=5), type='stock')
    # 设定成交占比,避免价格冲击
    set_option('order_volume_ratio', 0.25)
    # 开盘价成交,理论上无滑点
    set_slippage(FixedSlippage(0))
    # 最大建仓数量
    g.max_hold_stocknum = 3
    #运行函数
    run_daily(before_trading_start, time='09:00')
    run_daily(trade, time='9:30')
    

## 交易函数
def trade(context):
    for security in context.portfolio.long_positions:
        # 全部卖出
        order_target(security, 0)
        # 记录这次卖出
    #log.info("Selling %s" % (context.portfolio.long_positions))
        
    for security in g.security:
        value = context.portfolio.available_cash / 3    #资金分成三份
        order_value (security, value, side='long')
    #log.info ("buying %s" % (g.security))
        
## 计算乖离率
def get_bias (series):   
    average = np.array (series.rolling (window=12).mean())
    Y = series.iloc[-1] / average[-1] - 1
    return Y

## 剔除st和停牌
def get_feasible (universe):
    curr_data = get_current_data()
    stocks = [stock for stock in universe if (not curr_data[stock].paused) and (not curr_data[stock].is_st) and ('ST' not in curr_data[stock].name)\
                and ('*' not in curr_data[stock].name) and ('退'not in curr_data[stock].name) ]
    return stocks
##def after_trading_end (context):

待解锁以下函数:

## 获取 购买标的
def before_trading_start (context):

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