新股申购和逆回购操作demo(版本V2.0)

量化交流搬运工
量化交流搬运工 90后,坚持量化学习

0 People liked this article · 2116 views


IPO_FLAG = True # 新股申购开关
STOCK_IPO_FLAG = True # 股票新股申购开关
BOND_IPO_FLAG = True # 可转债申购开关
RR_FLAG = True # 逆回购开关
SH_RR_FLAG = True #上证逆回购开关
SZ_RR_FLAG = False # 深圳逆回购开关
# 定义一个财务数据获取函数,每天执行一次
def initialize(context):
if IPO_FLAG:
run_daily(context, IPO_func, time='10:30')
if RR_FLAG:
run_daily(context, ReverseRepo_func, time='14:58')
g.security = '600570.SS'
set_universe(g.security)
# 逆回购定时运行函数
def ReverseRepo_func(context):
cash = context.portfolio.cash
#逆回购最多需要万3 的手续费
cash = cash*0.9996
#上海逆回购
if SH_RR_FLAG:
amount = int((cash/100)/1000)*1000
order('204001.SS', -amount)
log.info('进行上海市场逆回购,共%s 张'%amount)
#深圳逆回购
if SZ_RR_FLAG:
amount = int((cash/100)/10)*10
order('131810.SZ', -amount)
log.info('进行深圳市场逆回购,共%s 张'%amount)
# 新股申购定时运行函数
def IPO_func(context):
print_info = {0:'上证普通代码', 1:'上证科创板代码',
2:'深证普通代码', 3:'深证创业板代码',
}
if STOCK_IPO_FLAG:
for i in [0, 1, 2, 3]:
ipo_stocks_order(market_type=i)
log.info(print_info[i]+'新股申购')
if BOND_IPO_FLAG:

ipo_stocks_order(market_type=4)
log.info('可转债代码申购')
# 盘中运行
def handle_data(context, data):
pass

Published on 2024-05-06 14:33

Disclaimers:

This document is written by 量化交流搬运工 Original published on 百果量化交流平台 ,The copyright belongs to the author。

Log in,More exciting content waiting for you to find,Contribute wonderful answers,Participate in comment interaction

go Sign in! No accountgoregister

xuk55590
2025-03-28 23:06
能用吗?
1235
2024-10-02 22:10
if IPO_FLAG: 这里就报错了