目的:找出存在负溢价的可转债,以获取快速套利。
import tushare as ts
import matplotlib.pyplot as plt
import mpl_finance as mpf
import matplotlib.dates as dates
import pandas as pd
import time
def yijialv(exch,close,stock):
exch_value = 100./ exch*stock
return (close - exch_value)/exch_value
date = time.strftime("%Y%m%d", time.localtime())
pro = ts.pro_api()
#获取可转债行情
df = pro.cb_daily(trade_date=date)
df2 = pro.cb_basic()
df3 = pro.daily(trade_date=date)
df['yjl'] = 0
df['cv_time']=0
df['name']=0
for index in df.ts_code:
# print (type(index))
close = df['close'][df.ts_code == index]
exch = df2['conv_price'][df2.ts_code == index]
stock_ID = df2['stk_code'][df2.ts_code == index]
stock_close =df3['close'][df3.ts_code == stock_ID.to_list()[0]]
a = yijialv(float(exch),float(close),float(stock_close))
df['yjl'][df.ts_code == index] = float(a)
df['cv_time'][df.ts_code == index] = df2['conv_start_date'][df2.ts_code == index].to_list()[0]
df['name'][df.ts_code == index] = df2['bond_short_name'][df2.ts_code == index].tolist()[0]
df.to_csv('kzz.csv')
来源:CSDN
作者:battlestar
链接:https://blog.csdn.net/battlestar/article/details/103772887