1 Star 0 Fork 0

jx0913/stock

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
bond_monitor.py 2.20 KB
一键复制 编辑 原始数据 按行查看 历史
#-*-coding=utf-8
'''
可转债监控 python2
'''
# from __future__ import division
import tushare as ts
from setting import get_engine
import pandas as pd
import datetime,time
from numpy import inf
engine = get_engine('db_bond')
class ConvertBond():
def __init__(self):
self.conn=ts.get_apis()
self.available_bonds = pd.read_sql('tb_bond_jisilu', engine, index_col='index')['可转债代码'].values
self.allBonds=ts.new_cbonds(default=0,pause=2)
self.onSellBond=self.allBonds.dropna(subset=['marketprice'])
self.today=datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
self.total = self.onSellBond[self.onSellBond['bcode'].isin(self.available_bonds)]
def stockPrice(self,code):
stock_df = ts.quotes(code,conn=self.conn)
price = float(stock_df['price'].values[0])
print(code,price)
return price
def dataframe(self):
s_price_list=[]
b_price_list=[]
for code in self.total['scode'].values:
s_price_list.append(self.stockPrice(code))
# b_price_list.append(self.stockPrice(str(code[1])))
# time.sleep(2)
self.total['stock_price']=s_price_list
self.total=self.total[self.total['stock_price']!=0]
# self.total['bond_price']=b_price_list
self.total['Bond Value'] = self.total['stock_price'] / self.total['convprice']*100
self.total['ratio']=(self.total['marketprice']/self.total['Bond Value']-1)*100
self.total['ratio']=self.total['ratio'].map(lambda x:round(x,2))
self.total['Bond Value']=self.total['Bond Value'].map(lambda x:round(x,2))
self.total['Updated']=self.today
print(self.total)
self.total.to_sql('tb_bond',engine,if_exists='replace')
def closed(self):
ts.close_apis(self.conn)
def calculation():
df=pd.read_sql('bond',engine,index_col='index')
df['ration']=(df['stock_price']/df['convprice']*100-df['marketprice'])/(df['stock_price']/df['convprice']*100)
# print(df[df['ration']>0])
df.to_sql('tb_bond',engine,if_exists='replace')
def main():
bond=ConvertBond()
bond.dataframe()
bond.closed()
# calculation()
if __name__=='__main__':
main()
print('done')
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jx0913/stock.git
git@gitee.com:jx0913/stock.git
jx0913
stock
stock
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385