可转债PYTHON
通过您可转债的代码:
#setting文件
import os
import MySQLdb
from sqlalchemy import create_engine
MYSQL_USER = "root"
MYSQL_PASSWORD = 1234
MYSQL_HOST ="127.0.0.1"
MYSQL_PORT =3306
def get_engine(db):
engine = create_engine('mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8'.format(MYSQL_USER, MYSQL_PASSWORD, MYSQL_HOST, MYSQL_PORT, db))
return engine
#-*-coding=utf-8
'''
可转债
pip install pymysql
'''
import tushare as ts
from setting import get_engine
engine = get_engine('new_schema')
import pandas as pd
import datetime
class ConvertBond():
def __init__(self):
self.conn=ts.get_apis()
self.allBonds=ts.new_cbonds(pause=2)
self.onSellBond=self.allBonds.dropna(subset=['marketprice'])
self.today=datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
def stockPrice(self,code):
stock_df = ts.get_realtime_quotes(code)
price = float(stock_df['price'].values[0])
return price
def dataframe(self):
price_list=
for code in self.onSellBond['scode']:
price_list.append(self.stockPrice(code))
self.onSellBond['stock_price']=price_list
self.onSellBond['ratio'] = (
self.onSellBond['marketprice']
/(self.onSellBond['stock_price'] / self.onSellBond['convprice'])-1)*100
self.onSellBond['Updated']=self.today
self.onSellBond.to_sql('tb_bond',engine,if_exists='append')
def closed(self):
ts.close_apis(self.conn)
def main():
bond=ConvertBond()
bond.dataframe()
bond.closed()
if __name__=='__main__':
main()
运行后很久都结束不了,而且也没有获取数据成功。
这是什么原因,哪里错了吗?
没有找到相关结果
已邀请:
1 个回复
李魔佛 - 公众号:可转债量化分析 【论坛注册:公众号后台留言邮箱】
赞同来自: