文章链接综合交易模型---高频分时网格交易,提供源代码 (qq.com)

今天加入了分时高频网格模块做T,网格合适趋势向上的标的,波动回撤小的标的,这个天然就合适债券etf,这个本身是t0的合适网格,这几天真刺激,已经老实了,我一千块买了红利etf,2天亏了15%不好玩了,00后真的干不过老股民了,我现在老实了。还是继续我稳稳幸福的策略,最近打算做一个债券网格策略去做t,比较稳定今天测试了效果不错,债券符合网格的前提

设计的原理,不断触发调整网格起点

图片

今天测试了一下效果不错,独立出来,目前是做为模块在系统中使用

图片

今天测试的

图片

图片

网格模块设置

1开启自定义交易模块

图片

2选择是监测持股还是自定义过程

图片

设置自定义股票池,文件夹下面修改自定义股票池标的就可以

图片

自定义股票池文件夹

图片

3设置网格参数可以修改

图片

 "自定义交易模块":{        "条件单分时网格":{                "函数名称":"conditional_single_time_sharing_grid(name='条件单分时网格',x1=0.3,x2=-0.4)",                "是否开启":"是",                "资金模型":"数量",                "交易值":100,                "持有值":200,                "数据类型":"高频行情"        },

资金默认支持数量,金额,百分比,交易值每次下单的数量,持有值最多持有的数量,数据类型支持高频行情,历史行情,数据结果

历史行情数据格式                   date   open  close   high    low   volume           成交额    振幅   涨跌幅   涨跌额   换手率                0    2021-01-04  33.82  33.37  34.58  32.97  1027586  3.603294e+09  4.80 -0.54 -0.18  1.21                1    2021-01-05  33.08  35.12  35.37  32.87  1072169  3.824581e+09  7.49  5.24  1.75  1.26                2    2021-01-06  35.15  35.53  36.03  34.57  1097482  4.029568e+09  4.16  1.17  0.41  1.29                3    2021-01-07  36.07  38.96  39.23  35.85  1401786  5.461736e+09  9.51  9.65  3.43  1.65                4    2021-01-08  38.96  38.94  39.95  37.58  1459535  5.862015e+09  6.08 -0.05 -0.02  1.72                ..          ...    ...    ...    ...    ...      ...           ...   ...   ...   ...   ...                902  2024-09-23  15.84  16.24  16.31  15.83   508098  8.208300e+08  3.03  2.46  0.39  0.60                903  2024-09-24  16.37  16.67  16.71  16.09   685346  1.129299e+09  3.82  2.65  0.43  0.81                904  2024-09-25  16.86  16.70  17.18  16.63   719915  1.219051e+09  3.30  0.18  0.03  0.85                905  2024-09-26  16.70  17.19  17.19  16.62   714270  1.214062e+09  3.41  2.93  0.49  0.84                906  2024-09-27  17.49  17.82  17.93  17.33   852418  1.504914e+09  3.49  3.66  0.63  1.01        高频数据格式                date     价格   成交量  性质  close     实时涨跌幅       涨跌幅            0      91500  17.19     2   4  17.19       NaN  0.000000            1      91503  17.19   133   4  17.19  0.000000  0.000000            2      91507  17.20   570   4  17.20  0.000582  0.058173            3      91509  17.20   685   4  17.20  0.000000  0.058173            4      91512  17.20   762   4  17.20  0.000000  0.058173            ...      ...    ...   ...  ..    ...       ...       ...            3617  145651  17.82    23  买盘  17.82  0.000000  3.664921            3618  145654  17.81    12  卖盘  17.81 -0.000561  3.606748            3619  145657  17.82    30  买盘  17.82  0.000561  3.664921            3620  145700  17.82    29  买盘  17.82  0.000000  3.664921            3621  150000  17.82  2885  卖盘  17.82  0.000000  3.664921        '''

设置qmt路径账户等参数进入交易

图片

点击tarder进入实盘交易

图片

运行的显示

图片

  • -10 21:48:20.129344 模块条件单分时网格 卖出511130 目前涨跌幅1.106899166034881 大于目前标涨跌幅0.3 None交易类型24 代码511130.SH 价格106.688 数量100 订单编号1082130496持股数据调整成功511130没有持股账户资金调整完成分钟脉冲卖出 2024-10-10 21:48:15.443485 不开启2024-10-10 21:48:21.660562 模块当日止损 不符合模型511130 涨跌幅1.14 条件单冲高回落 2024-10-10 21:48:15.443485 不开启条件单反弹卖出 2024-10-10 21:48:15.443485 不开启分钟脉冲买入 2024-10-10 21:48:15.443485 不开启当日止盈 2024-10-10 21:48:15.443485 不开启条件单上涨买入 2024-10-10 21:48:15.443485 不开启条件单上涨卖出 2024-10-10 21:48:15.443485 不开启条件单下跌卖出 2024-10-10 21:48:15.443485 不开启条件单下跌买入 2024-10-10 21:48:15.443485 不开启条件单账户止盈 2024-10-10 21:48:15.443485 不开启条件单账户止损 2024-10-10 21:48:15.443485 不开启作者微信15117320079**********************授权码正确,到期日2025-01-04 剩余天数86******************买入可转债为空

下单的内容

图片

保存的交易记录

图片

  证券代码  模块名称  交易时间  触发时间  触发的价格  资金类型  交易值  持有值  交易类型  交易数量0  511090  条件单分时网格  2024-10-10  2024-10-10 21:48:15  117.407  数量  100  200  sell  1001  511130  条件单分时网格  2024-10-10  2024-10-10 21:48:15  106.688  数量  100  200  sell  100

运行自定义函数模块

def run_custom_trading_modules(self):        '''        运行自定义交易模型        '''        with open('分析配置.json','r+',encoding='utf-8') as f:            com=f.read()        text=json.loads(com)        user_models=text['自定义交易模块']        stock_type=text['自定义模块股票池']        name_list=list(user_models.keys())        if self.check_is_trader_date_1()==True:            now_date=datetime.now()            trader_date=str(datetime.now())[:10]            if stock_type=='持股':                df=pd.read_excel(r'持股数据\持股数据.xlsx')            else:                df=pd.read_excel(r'自定义股票池\自定义股票池.xlsx')            log=pd.read_excel(r'自定义模块交易记录\自定义模块交易记录.xlsx')            log=log[['证券代码','模块名称','交易时间','触发时间','触发的价格','资金类型','交易值','持有值','交易类型']]            log['触发时间']=log['触发时间'].astype(str)            log['证券代码']=log['证券代码'].astype(str)            now_date=datetime.now()            trader_date=str(datetime.now())[:10]            #读取今天            log=log[log['交易时间']==trader_date]            if df.shape[0]>0:                df['证券代码']=df['证券代码'].apply(lambda x: '0'*(6-len(str(x)))+str(x))                for stock in df['证券代码'].tolist():                    try:                        for name in name_list:                            user_set=user_models[name]                            func=user_set['函数名称']                            is_open=user_set['是否开启']                            cash_type=user_set['资金模型']                            value=user_set['交易值']                            limit_value=user_set['持有值']                            data_type=user_set['数据类型']                            if is_open=='是':                                spot_data=self.data.get_spot_data(stock=stock)                                price=spot_data['最新价']                                lof_list=text['lof基金列表']                                stock=str(stock)                                if stock[:6] in lof_list:                                    price=price                                else:                                    price=price                                if data_type=='历史行情':                                    hist=self.data.get_hist_data_em(stock=stock)                                    hist['证券代码']=stock                                else:                                    hist=self.data.get_spot_trader_data(stock=stock)                                    hist['证券代码']=stock                                models=custom_trading_modules(stock=stock,cash_type=cash_type,                                                value=value,limit_value=limit_value,data_type=data_type,df=hist)                                func='models.{}'.format(func)                                trader_type=eval(func)                                if trader_type=='buy':                                    if cash_type=='数量':                                        #检查目标持股限制                                        trader_type,amount,price=self.trader.order_target_volume(stock=stock,amount=limit_value,price=price)                                    elif cash_type=='金额':                                        trader_type,amount,price=self.trader.order_target_value(stock=stock,value=limit_value,price=price)                                    elif cash_type=='百分比':                                        trader_type,amount,price=self.trader.order_target_percent(stock=stock,target_percent=limit_value,price=price)                                    else:                                        trader_type=''                                        amount=''                                        price=''                                    if trader_type=='buy':                                        if cash_type=='数量':                                            amount=value                                            self.trader.buy(security=stock,price=price,amount=value)                                        elif cash_type=='金额':                                            trader_type,amount,price=self.trader.order_value(stock=stock,value=value,price=price,trader_type='buy')                                            if trader_type=='buy' and amount>=10:                                                self.trader.buy(security=stock,price=price,amount=amount)                                            else:                                                pass                                        elif cash_type=='百分比':                                            trader_type,amount,price=self.trader.order_percent(stock=stock,percent=value,price=price,trader_type='buy')                                            if trader_type=='buy' and amount>=10:                                                self.trader.buy(security=stock,price=price,amount=amount)                                            else:                                                pass                                        else:                                            pass                                elif trader_type=='sell':                                    if cash_type=='数量':                                        amount=value                                        self.trader.sell(security=stock,price=price,amount=value)                                    elif cash_type=='金额':                                        trader_type,amount,price=self.trader.order_value(stock=stock,value=value,price=price,trader_type='sell')                                        if trader_type=='sell' and amount>=10:                                            self.trader.sell(security=stock,price=price,amount=amount)                                        else:                                            pass                                    elif cash_type=='百分比':                                        trader_type,amount,price=self.trader.order_percent(stock=stock,percent=value,price=price,trader_type='sell')                                        if trader_type=='sell' and amount>=10:                                            self.trader.sell(security=stock,price=price,amount=amount)                                        else:                                            pass                                    else:                                        pass                                else:                                    trader_type=''                                if (trader_type=='buy' or trader_type=='sell') and  amount>=10:                                    df1=pd.DataFrame()                                    df1['证券代码']=[stock]                                    df1["模块名称"]=[name]                                    df1['交易时间']=[trader_date]                                    df1['触发时间']=[now_date]                                    df1['触发的价格']=[price]                                    df1['资金类型']=[cash_type]                                    df1['交易值']=[value]                                    df1['持有值']=[limit_value]                                    df1['交易类型']=[trader_type]                                    df1['交易数量']=[amount]                                    log=pd.concat([log,df1],ignore_index=True)                                    log.to_excel(r'自定义模块交易记录\自定义模块交易记录.xlsx')                                    #调整持股                                    self.adjust_hold_data(stock=stock,trader_type=trader_type,price=price,amount=amount)                                    #调整账户资金                                    self.adjust_account_cash(stock=stock,trader_type=trader_type,price=price,amount=amount)                                else:                                    pass                            else:                                print(name,'{} 不开启'.format(now_date))                                        except Exception as e:                        print(e,name,'有问题************')                                else:                print('自定义交易模块没有持股')           else:            print('自定义交易模块{} 目前不是交易时间'.format(datetime.now()))  

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐