コード例 #1
0
ファイル: ts_common.py プロジェクト: fswzb/fin_script
def list_stock_news(code, curdate, file):
	df = ts.get_notices(code, curdate)
	if df.empty:
		df = ts.get_notices(code)
	for index,row in df.iterrows():
		if index>1:
			break
		print row['date'],row['title']
	print ''
コード例 #2
0
ファイル: tu_api.py プロジェクト: kangnwh/MyDWTool
def generate_wordcloud_png(session,png_path,default_dict,default_word_font_ttf,stopwords,max_font_size=None,begin_code="000000"):

    log_file = (os.getcwd() + os.sep + "logs" + os.sep + "load_word_cloud_%s.log") % (
    dt.datetime.now().strftime('%Y-%m-%d'))
    logger = get_logger(log_file,'word_cloud')

    logger.info('Daily word cloud generation begins')
    logger.info("##########################################")

    logger.info("Begin get basic")

    code_basic = get_all_code_basic(session,begin_code=begin_code)

    for code in code_basic.code:
        logger.info("##########################################")
        logger.info("###Begin to generate for {code}###########".format(code = code))
        logger.info("##########################################")
        logger.info("Begin to generate for {code}".format(code = code))
        cloud_df = ts.get_notices(code)
        all = ""
        if isinstance(cloud_df,pd.DataFrame):
            for url in cloud_df.url:
                all += get_url_content(url)
        after = ' '.join(jieba.cut(all,cut_all=False))
        file = get_word_cloud(after,file_name=code+".png",dict=default_dict,max_words=2000,stopwords=stopwords,folder_path=png_path,max_font_size=max_font_size,font_path=default_word_font_ttf)
        logger.info("##########################################")
        logger.info("{file} was generated successfully !".format(file = file))
        logger.info("##########################################")

    logger.info("All word cloud files were generated successfully !")
コード例 #3
0
def store_news():
    # 获取新浪股吧的最新新闻
    sina_news = ts.guba_sina(show_content=True)

    # 防止数据未更新插入重复数据 2018/04/22 0:33
    # TODO 集合为空时的容错处理
    for i in db.news.sina.find().sort([("_id", -1)]).limit(1):
        for j in sina_news[:6][-1:].get("title"):
            if i.get("title") != j:
                db.news.sina.insert(
                    json.loads(sina_news[:6].to_json(orient='records')))

    # 获取前6条最新的即时新闻
    immediate_news = ts.get_latest_news(top=6, show_content=True)

    for i in db.news.immediate.find().sort([("_id", -1)]).limit(1):
        for j in immediate_news[-1:].get("title"):
            if i.get("title") != j:
                db.news.immediate.insert(
                    json.loads(immediate_news.to_json(orient='records')))

    # 获取个股信息地雷数据
    mines_news = ts.get_notices()

    if not mines_news is None:
        db.news.mines.insert(json.loads(mines_news.to_json(orient='records')))
コード例 #4
0
ファイル: update.py プロジェクト: wzlnju/Shrewd-Investments
def updatespecialnews():
    conn = ms.connect(host='localhost',
                      port=3306,
                      user='******',
                      passwd='123456',
                      db='investment',
                      charset="utf8")
    cur = conn.cursor()
    cur.execute('select code from mainlist')
    stus = cur.fetchall()
    code = ''
    for stu in stus:
        code = stu[0]
        specialnewsdatalist = ts.get_notices(code)
        specialnewsdata = pd.DataFrame(specialnewsdatalist)
        values = []
        print code
        for index, row in specialnewsdata.iterrows():
            values.append(
                (row['title'].encode("utf-8"), row['type'].encode("utf-8"),
                 row['date'].encode("utf-8"), row['url']))
        cur.execute('delete from specialnews_' + code)
        insertstr = 'insert into specialnews_' + code + ' (title,type,date,url) values(%s,%s,%s,%s)'
        cur.executemany(insertstr, values)
        conn.commit()
    cur.close()
    conn.close()
コード例 #5
0
def get_notices_by_code(code):
    try:
        notices = ts.get_notices(code=str(code), date=today)
        return notices
    except Exception as e:
        print(e)
        return None
コード例 #6
0
def nlpHandle(nlp, mic, profile, wxbot=None):
    """

        Arguments:
        text -- user-input, typically transcribed speech
        mic -- used to interact with the user (for both input and output)
        profile -- contains information related to the user (e.g., phone
                   number)
        wxbot -- wechat bot instance
    """
    def get_news(data):
        rs = []
        for index, row in data.iterrows():
            rs.append(str(index + 1))
            for col_name in data.columns:
                rs.append(row[col_name])
            rs.append('\n')
        return ' '.join(rs)

    sys.path.append(mic.dingdangpath.LIB_PATH)
    from app_utils import wechatUser
    text = nlp['text']
    if any(word in text for word in [u"财经新闻"]):
        news = ts.get_latest_news(top=10, show_content=False)
        t = mic.asyncSay("已获取财经新闻," +
                         ('将发送到您的微信' if wxbot != None else "篇幅较长,请登录微信获取"))
        if wxbot != None:
            wechatUser(profile, wxbot, '财经新闻', get_news(news))
        t.join()
    elif any(word in text for word in [u"信息地雷"]):
        orgName = None
        code = None
        items = nlp['items']
        for item in items:
            if item['ne'] == u'ORG':
                orgName = item['item']
                break
        if orgName:
            code = db.get_instance().get_stock_code(orgName)
        else:
            m = pattern.search(text)
            if m:
                code = m.group(2)

        if code:
            orgName = db.get_instance().get_stock_name(code)
            if not orgName:
                mic.say("股票代码可能不存在")
                return
            notices = ts.get_notices(code)
            notices = notices[0:10]
            tit = orgName + '的信息地雷'
            t = mic.asyncSay("已获取" + tit + "," +
                             ('将发送到您的微信' if wxbot != None else "篇幅较长,请登录微信获取"))
            if wxbot != None:
                wechatUser(profile, wxbot, tit, get_news(notices))
            t.join()
        else:
            mic.say("没能获取股票代码")
コード例 #7
0
ファイル: makeData.py プロジェクト: ylqfp/StockIndustryTrend
def processData():
    for k, v in dic_hangye1.items():
        print u"行业:", k
        for c in v:
            print c
            s = c.split(".")
            res = ts.get_notices(code=s[0])
            print res
コード例 #8
0
def test():
    ts.get_sz50s()
    ts.get_hs300s()
    ts.get_zz500s()
    ts.realtime_boxoffice()
    ts.get_latest_news()
    ts.get_notices(tk)
    ts.guba_sina()
    ts.get_cpi()
    ts.get_ppi()
    ts.get_stock_basics()
    ts.get_concept_classified()
    ts.get_money_supply()
    ts.get_gold_and_foreign_reserves()
    ts.top_list()  #每日龙虎榜列表
    ts.cap_tops()  #个股上榜统计
    ts.broker_tops()  #营业部上榜统计
    ts.inst_tops()  # 获取机构席位追踪统计数据
    ts.inst_detail()
コード例 #9
0
def news_notices_worker(engine, codes, ddate):
	pid = os.getpid()
	tsl.log("pid %i start with %i codes..." % (pid, len(codes)))
	df = pd.DataFrame()
	for code in codes:
		try:
			newdf = ts.get_notices(code, ddate, True)
			if newdf is not None:
				newdf['code'] = code
				df = df.append(newdf, ignore_index=True)
		except BaseException, e:
			print e
			tsl.log("pid %i error for %s" % (pid, code))
コード例 #10
0
def getnews1(code):
    news = ts.get_notices(code=code)
    type = list(news['type'])
    title = list(news['title'])
    date = list(news['date'])
    url = list(news['url'])
    print(len(type))
    for i in type:
        print(i)
    for i in title:
        print(i)
    for i in date:
        print(i)
    for i in url:
        print(i)
コード例 #11
0
def get_news(start_date, end_date):
    data = csv.reader(open('./input/tiker_list.csv', 'r'))
    news = np.zeros([0, 5])
    start_date = datetime.datetime.strptime(start_date, "%Y-%m-%d")
    end_date = datetime.datetime.strptime(end_date, "%Y-%m-%d")
    codes = []
    for num, line in enumerate(data):
        if num != 0 and num <= NUM_DATA:  #for test
            print("开始搜索有关" + line[1] + "(" + line[0] + ')' + "的新闻...")
            codes.append(line[0])
            day = start_date
            while day <= end_date:
                try:
                    hight = np.array(
                        ts.get_notices(line[0],
                                       day.strftime('%Y-%m-%d'))).shape[0]
                    news = np.vstack(
                        (news,
                         np.hstack(
                             (np.array([[line[0]] * hight]).T,
                              ts.get_notices(line[0],
                                             day.strftime('%Y-%m-%d'))))))
                    print("获取在" + day.strftime('%Y-%m-%d') + '的新闻成功')
                except IndexError:
                    pass
                except:
                    print("获取在" + day.strftime('%Y-%m-%d') + '的新闻失败,正在重试')
                    continue
                day += datetime.timedelta(days=1)
    writer = csv.writer(open('./input/news.csv', 'w'))
    writer.writerows(news)
    codes = np.array([list(codes)])
    codes = codes.T
    out = open('./input/finished.reuters', 'w', newline='')
    csv_write = csv.writer(out)
    csv_write.writerows(codes)
コード例 #12
0
def generate_wordcloud_png(session,
                           png_path,
                           default_dict,
                           default_word_font_ttf,
                           stopwords,
                           max_font_size=None,
                           begin_code="000000"):

    log_file = (os.getcwd() + os.sep + "logs" + os.sep +
                "load_word_cloud_%s.log") % (
                    dt.datetime.now().strftime('%Y-%m-%d'))
    logger = get_logger(log_file, 'word_cloud')

    logger.info('Daily word cloud generation begins')
    logger.info("##########################################")

    logger.info("Begin get basic")

    code_basic = get_all_code_basic(session, begin_code=begin_code)

    for code in code_basic.code:
        logger.info("##########################################")
        logger.info(
            "###Begin to generate for {code}###########".format(code=code))
        logger.info("##########################################")
        logger.info("Begin to generate for {code}".format(code=code))
        cloud_df = ts.get_notices(code)
        all = ""
        if isinstance(cloud_df, pd.DataFrame):
            for url in cloud_df.url:
                all += get_url_content(url)
        after = ' '.join(jieba.cut(all, cut_all=False))
        file = get_word_cloud(after,
                              file_name=code + ".png",
                              dict=default_dict,
                              max_words=2000,
                              stopwords=stopwords,
                              folder_path=png_path,
                              max_font_size=max_font_size,
                              font_path=default_word_font_ttf)
        logger.info("##########################################")
        logger.info("{file} was generated successfully !".format(file=file))
        logger.info("##########################################")

    logger.info("All word cloud files were generated successfully !")
コード例 #13
0
ファイル: search_news.py プロジェクト: yaoxingqi/vnpy_future
 def run(self):
     while not self.stop:
         for i, stock in enumerate(self.stocklist):
             print('processing: {0}.   By thread:{1}'.format(stock, self.ix))
             t = datetime(2015, 6, 20)
             t_delta = datetime.now() - t
             dframe = pd.DataFrame()
             while t_delta.days > 0:
                 t = t + timedelta(1)
                 t_delta = datetime.now() - t
                 subdf = ts.get_notices(stock, t)
                 if not (subdf is None or subdf is [None]):
                     subdf = subdf.ix[subdf.ix[:, 0].str.contains(key_word)]
                     subdf = subdf.ix[subdf.ix[:, 1].str.contains(key_word2)]
                 dframe = dframe.append(subdf, ignore_index=True)
             if len(dframe) == 0:
                 continue
             dframe.to_csv(to_file + stock + '.csv', index=False)
コード例 #14
0
 def __call__(self, conns):
     self.base = Base()
     self.financial_data = conns['financial_data']
     '''即时财经新闻'''
     latest_news = ts.get_latest_news()
     self.base.batchwri(latest_news, 'latest_news', self.financial_data)
     '''
     名称:个股信息地雷
     功能:获得个股信息地雷数据
     参数
         code:股票代码
         date:信息公布日期
     '''
     notices = ts.get_notices()
     self.base.batchwri(notices, 'notices', self.financial_data)
     '''新浪股吧新闻'''
     guba_sina = ts.guba_sina()
     self.base.batchwri(guba_sina, 'guba_sina', self.financial_data)
コード例 #15
0
def get_stock_news(code, start, end):
    start_date = datetime.strptime(start, '%Y-%m-%d')
    end_date = datetime.strptime(end, '%Y-%m-%d')

    res = None
    while start_date <= end_date:
        try:
            temp = ts.get_notices(code, start_date.strftime("%Y-%m-%d"))
        except:
            start_date += timedelta(days=1)
            continue
        print(temp)
        if res is None:
            res = temp
        else:
            res = res.append(temp, ignore_index=True)
        start_date += timedelta(days=1)

    return res
コード例 #16
0
ファイル: update.py プロジェクト: ZoRin1/Shrewd-Investments
def updatespecialnews():
    conn= ms.connect(host='localhost',port = 3306,user='******', passwd='123456',db ='investment',charset="utf8")
    cur = conn.cursor()
    cur.execute('select code from mainlist')
    stus = cur.fetchall()
    code=''
    for stu in stus:
        code=stu[0]
        specialnewsdatalist=ts.get_notices(code)
        specialnewsdata=pd.DataFrame(specialnewsdatalist)
        values=[]
        print code
        for index,row in specialnewsdata.iterrows():
            values.append((row['title'].encode("utf-8"),row['type'].encode("utf-8"),row['date'].encode("utf-8"),row['url']))
        cur.execute('delete from specialnews_'+code)
        insertstr='insert into specialnews_'+code+' (title,type,date,url) values(%s,%s,%s,%s)'
        cur.executemany(insertstr,values)
        conn.commit()
    cur.close()
    conn.close()
コード例 #17
0
 def fetchNewsByCode(self, code, drop=False):
     tableName = 'stockNews'
     param = []
     try:
         db, dbname = connectConfigDB('database')
         cursor = db.cursor()
         cursor.execute("SET NAMES utf8mb4;")
         if drop:
             cursor.execute("DROP TABLE IF EXISTS %s" % tableName)
             sql = """
                     CREATE TABLE 
                         `%s`.`%s` (
                         `code` VARCHAR(10) NOT NULL COMMENT '股票代码',
                         `title` VARCHAR(45) NULL COMMENT '标题',
                         `type` VARCHAR(45) NULL COMMENT '类型',
                         `date` VARCHAR(45) NULL COMMENT '日期',
                         `url` TEXT NULL COMMENT '链接',
                         PRIMARY KEY (`code`, `title`, `date`)
                         ) DEFAULT CHARSET=utf8mb4;  
                     """ % (dbname, tableName
                            )  # !IMPORTANT: DEFAULT CHARSET=utf8mb4;
             cursor.execute(sql)
             print('table %s created' % tableName)
         # fetch and insert data
         res = ts.get_notices(code)
         sql = 'INSERT IGNORE INTO `' + tableName + \
                 """` values(%s, %s, %s, %s, %s)
                 """
         for row in res.values:
             param.append([code] + row.tolist())
         cursor.executemany(sql, param)
         db.commit()
         print('\ntable %s inserted %s records.' %
               (tableName, len(res.values)))
     except:
         print_exc()
         db.rollback()
         return False
     finally:
         db.close()
     return True
コード例 #18
0
ファイル: ts_common.py プロジェクト: fswzb/fin_script
def list_latest_news(codeArray, curdate):
	cur_dt = datetime.datetime.strptime(curdate, '%Y-%m-%d').date()
	for code in codeArray:
		bFlag = 0
		news_ct = 0
		df = ts.get_notices(code)
		for index,row in df.iterrows():
			news_dt = datetime.datetime.strptime(row['date'], '%Y-%m-%d').date()
			delta = cur_dt-news_dt
			if delta.days<=0:
				print "==================================="
				bFlag=1
			else:
				if bFlag==0:
					news_ct += 1
				else:
					break
				if news_ct>1:
					break
			print row['date'],row['title']
		print ''
コード例 #19
0
ファイル: init.py プロジェクト: dengyongqing/one_strategy
def job_6():
    try:
        print("I'm working......新闻事件数据")
        # 即时新闻
        latest_news = ts.get_latest_news()
        data = pd.DataFrame(latest_news)
        data.to_sql('latest_news',engine,index=True,if_exists='replace')
        print("即时新闻......done")

        # 信息地雷
        notices = ts.get_notices()
        data = pd.DataFrame(notices)
        data.to_sql('notices',engine,index=True,if_exists='replace')
        print("信息地雷......done")

        # 新浪股吧
        guba_sina = ts.guba_sina()
        data = pd.DataFrame(guba_sina)
        data.to_sql('guba_sina',engine,index=True,if_exists='replace')
        print("新浪股吧......done")
    except Exception as e:
        print(e)
コード例 #20
0
ファイル: ggdr.py プロジェクト: SwoJa/ruman
def gonggao_dict(gongsi,year1,month1,day1,year2,month2,day2):
    gg = pd.DataFrame()
    ggl =[]
    dated = datelist(year1,month1,day1,year2,month2,day2)
    for date in dated:
    	print gongsi,date
        try:
            hhd = ts.get_notices(gongsi,date)
            gg = gg.append(hhd,ignore_index=True)
        except:
            pass
    try:
        for num in range(gg.iloc[:,0].size):
    	    ggd = {}
            ggd['stock_id'] = gongsi
            ggd['title'] = gg.loc[num]['title']
            ggd['publish_time'] = datetimestr2ts(gg.loc[num]['date'])
            ggd['url'] = gg.loc[num]['url']
            ggd['type'] = getkind(gg.loc[num]['title'])
            #ggd['content'] = '待取'
            ggl.append(ggd)
    except:
    	pass
    return ggl
コード例 #21
0
def gonggao_dict(gongsi, year1, month1, day1, year2, month2, day2):
    gg = pd.DataFrame()
    ggl = []
    dated = datelist(year1, month1, day1, year2, month2, day2)
    for date in dated:
        print gongsi, date
        try:
            hhd = ts.get_notices(gongsi, date)
            gg = gg.append(hhd, ignore_index=True)
        except:
            pass
    try:
        for num in range(gg.iloc[:, 0].size):
            ggd = {}
            ggd['stock_id'] = gongsi
            ggd['title'] = gg.loc[num]['title']
            ggd['publish_time'] = datetimestr2ts(gg.loc[num]['date'])
            ggd['url'] = gg.loc[num]['url']
            ggd['type'] = getkind(gg.loc[num]['title'])
            #ggd['content'] = '待取'
            ggl.append(ggd)
    except:
        pass
    return ggl
コード例 #22
0
ファイル: StockNews.py プロジェクト: yyf013932/CSE_MATCH
import tushare as ts
import sys

df = ts.get_notices(code=sys.argv[1])
path = sys.argv[2]
df.to_csv(path, encoding="utf8")
コード例 #23
0
ファイル: getMainEvent.py プロジェクト: Apocalpyse/NJU-SE3
import tushare as ts
from sqlalchemy import create_engine
import MySQLdb
import sys

reload(sys)
sys.setdefaultencoding("utf-8")

db = MySQLdb.connect("localhost", "root", "2578", "CSEIII-Data")
cursor = db.cursor()
DB_CONNECT_STRING = 'mysql+mysqldb://root:2578@localhost/CSEIII-Data?charset=utf8'
engine = create_engine(DB_CONNECT_STRING)

name = 'investnews'
sql = "CREATE TABLE " + name + """ (index VARCHAR(20) NOT NULL,
 title VARCHAR(20) NOT NULL,
 type VARCHAR(20) NOT NULL, 
 date VARCHAR(20) NOT NULL, 
 url VARCHAR(20) NOT NULL)"""
cursor.execute(sql)

sql = "SELECT code FROM codelist "
cursor.execute(sql)

for index in cursor.fetchall():
    df = ts.get_notices(str(index).split('(\'')[1].split('\'')[0])
    if df is None:
        pass
    else:
        df.to_sql(name, engine, if_exists='append')
コード例 #24
0
 def get_notices(self,code):
     notices = ts.get_notices(code,self.dateS)
     return notices
コード例 #25
0
df_forecast = ts.forecast_data(2017,4)
'''业绩预告'''
df_restrict = ts.xsg_data()
'''限售股解禁'''
df_fund = ts.fund_holdings(2017, 2)
'''基金持股'''
df_sh = ts.sh_margin_details(start='2015-01-01', end='2015-04-19', symbol='601989')
'''上交所融资融券明细'''
df_sz = ts.sz_margins(start='2015-01-01', end='2015-04-19')
df_sz_detail = ts.sz_margin_details('2015-04-20')
'''深交所融资融券总额'''
#==============================================================================新闻==============================================================================
ts.get_latest_news() #默认获取最近80条新闻数据,只提供新闻类型、链接和标题
ts.get_latest_news(top=5,show_content=True) #显示最新5条新闻,并打印出新闻内容
'''即时新闻'''
ts.get_notices('600028')
'''个股新闻'''
ts.guba_sina(True)
'''新浪股吧'''
#==============================================================================海外数据源==============================================================================
import pandas.io.data as web
DAX = web.DataReader(name='^GDAXI',data_source='yahoo',start='2000-1-1')#读取德国DAX指数
#data_source='yahoo'/'google'/'fred'圣路易斯储蓄银行/'famafrench'/'pandas.io.web'世界银行  

#write_code
#total_basic_data.to_excel(location_save_all_data+"/Basic_report_for_all_stocks.xlsx")
#total_financial_report.to_excel(location_save_all_data+"/all_general_financial_report.xlsx")
#total_profit_data.to_excel(location_save_all_data+"/all_profit_data.xlsx")
#total_operation_data.to_excel(location_save_all_data+"/all_operation_data.xlsx")
#total_growth_data.to_excel(location_save_all_data+"/all_growth_data.xlsx")
#total_leverage_data.to_excel(location_save_all_data+"/all_leverage_data.xlsx")
コード例 #26
0
# -*- coding: utf-8 -*-
import tushare as ts
'''
获取个股信息地雷数据。

参数说明:

code:股票代码
date:信息公布日期
返回值说明:

title:信息标题
type:信息类型
date:公告日期
url:信息内容URL
如果获取信息内容,请调用notice_content(url)接口,把url地址作为参数传入即可。
'''
data = ts.get_notices()
print(data)
コード例 #27
0
ファイル: qtshare.py プロジェクト: DeepAQ/QuantraFund
def stock_news(code):
    return tushare.get_notices('%06d' % code)
コード例 #28
0
import tushare as ts
from pandas import DataFrame

# print(tushare.__version__)

# 获取股票新闻
data = ts.get_notices(
    code="002131")  # 返回的对象是一个<class 'pandas.core.frame.DataFrame'>
# 使用pandas处理返回的对象
frame1 = DataFrame(data, columns=["title"],
                   index=[0, 1, 2])  # 只获取标题和url,并且只获取最近的3条记录
# print(frame1)

# 获取股票的历史行情
# 上证指数 深圳成指 沪深300指数 上证50 中小板 创业板
# 'sh','sz','hs300','sz50','zxb','cyb'
hist = ts.get_hist_data('sh', start='2019-03-25', end='2019-04-02')

# 只获取股票的开盘价和收盘价
# frame2 = DataFrame(hist, columns=["open", "close", "low", "high", "volume", "p_change", "price_change", "ma5", "ma10", "ma20", "v_ma5", "v_ma10", "v_ma20"])
# print(frame2)

# frame2.to_csv('F:/01/sh.csv')

# df = ts.get_index()
# print(df)

df = ts.get_index()
df.to_csv('F:/01/get_index.csv')
print(df)
コード例 #29
0
    def query_stock_info(ls_code, ls_all_stock_data, df_model_basics):

        [ df_stock_basics, df_quarter_report_data, df_profit_data, df_operation_data, df_growth_data, df_debtpaying_data, \
         df_cashflow_data, df_divi_data, df_forcast_quarter_report_data, df_restrict_stock_data, df_concept_classified ] = ls_all_stock_data

        space = lambda x: ' ' * x  # 方便区分不同季度数据
        pd.options.mode.chained_assignment = None  # 不显示warn信息 default='warn'
        dict_stock_info = {}

        for code in ls_code:

            try:
                basics = df_stock_basics.loc[int(code)]
                content = '\n{0}  {1}\n'.format(code, basics['name'])
                try:
                    cur_price = float(
                        Data().get_k_line_data(code).iloc[-1]['close'])
                except:
                    cur_price = float(
                        Data().get_realtime_quotes(code)['price'])

                content += '\nbasics:\n上市日期:{0}\n所属行业:{1}\t行业市盈率排名:{6}\n地区:{2}\n市盈率(动态):{3}\n市盈率(静态):{4:.2f}\n市净率:{5}\n'\
                 .format( basics[ 'timeToMarket' ], basics[ 'industry' ], basics[ 'area' ], basics[ 'pe' ], \
                   cur_price / float( basics[ 'esp' ] ), float( basics[ 'pb' ] ), df_model_basics[ 'rank_pe' ][ int( code ) ] )
                content += '每股公积金:{0}\n每股未分配利润:{1}\n'\
                 .format( basics[ 'reservedPerShare' ], basics[ 'perundp' ] )
                content += '总市值:{0:.2f} 亿元\n流动市值:{1:.2f} 亿元\n'\
                 .format( cur_price * float( basics[ 'totals' ] ), cur_price * float( basics[ 'outstanding' ] ) )
                content += '总资产:{0:.2f} 亿元\n固定资产:{1:.2f} 亿元\n流动资产:{2:.2f} 亿元\n'\
                 .format( float( basics[ 'totalAssets' ] ) / 10000, float( basics[ 'fixedAssets' ] ) / 10000, \
                   float( basics[ 'liquidAssets' ] ) / 10000 )
            except:
                content = '\n{0}\n'.format(code)

            try:
                content += '\nconcept:\n'

                id_concept = 1
                id_rank = 1
                name_concept = '_'.join(['concept', str(id_concept)])
                name_rank = '_'.join(['rank_pe', str(id_rank)])

                while df_model_basics[name_concept][int(code)] is not np.nan:
                    content += '{0}  市盈率排名:{1}\n'.format( df_model_basics[ name_concept ][ int( code ) ], \
                     df_model_basics[ name_rank ][ int( code ) ] )
                    id_concept += 1
                    id_rank += 1
                    if id_concept > 20:
                        break
                    name_concept = '_'.join(['concept',
                                             str(id_concept)])
                    name_rank = '_'.join(['rank_pe', str(id_rank)])

                content += '\n'
            except:
                pass

            try:
                profit = df_profit_data.loc[int(code)].sort_values(
                    by=['year',
                        'quarter'], axis=0, ascending=True).drop_duplicates()
                content += '\nprofit:\n排名:{0}\n年份   季度  净资产收益率  净利润(百万)  每股收益(元)每股主营业务收入(元)\n'\
                 .format( df_model_basics[ 'rank_profit_grow' ][ int( code ) ] )
                for id in range(profit.index.size):
                    content += '{5}{0}  {1}  {2:-10.2f}  {3:-12.2f}  {4:-15.2f}  {6:-20.2f}\n'.format( profit.iloc[ id ][ 'year' ], profit.iloc[ id ][ 'quarter' ], \
                      profit.iloc[ id ][ 'roe' ], profit.iloc[ id ][ 'net_profits' ], profit.iloc[ id ][ 'eps' ], \
                      space( int( profit.iloc[ id ][ 'quarter' ] ) - 1 ), profit.iloc[ id ][ 'bips' ] )
            except:
                pass

            try:
                operation = df_operation_data.loc[int(code)].sort_values(
                    by=['year',
                        'quarter'], axis=0, ascending=True).drop_duplicates()
                content += '\noperation:\n年份   季度  应收账款周转天数  存货周转天数  流动资产周转天数\n'

                for id in range(operation.index.size):
                    content += '{5}{0}  {1}  {2:-16.2f}     {3:-8.2f}     {4:-15.2f}\n'.format( operation.iloc[ id ][ 'year' ], \
                     operation.iloc[ id ][ 'quarter' ],operation.iloc[ id ][ 'arturndays' ], operation.iloc[ id ][ 'inventory_days' ], \
                     operation.iloc[ id ][ 'currentasset_days' ], space( int( operation.iloc[ id ][ 'quarter' ] ) - 1 ) )
            except:
                pass

            try:
                debtpaying = df_debtpaying_data.loc[int(code)].sort_values(
                    by=['year',
                        'quarter'], axis=0, ascending=True).drop_duplicates()
                content += '\ndebtpaying:\n年份   季度  流动比率  利息支付倍数  股东权益比率  股东权益增长率\n'

                for col in ['currentratio', 'icratio', 'sheqratio', 'adratio']:
                    for id in range(debtpaying.index.size):
                        try:
                            float(debtpaying[col].iloc[id])
                        except:
                            debtpaying[col].iloc[id] = np.nan

                for id in range(debtpaying.index.size):
                    content += '{5}{0}  {1}  {2:-8.2f}   {3:-12.2f}   {4:-10.2f}   {6:-14.2f}\n'.format( debtpaying.iloc[ id ][ 'year' ], \
                     debtpaying.iloc[ id ][ 'quarter' ], float( debtpaying.iloc[ id ][ 'currentratio' ] ), float( debtpaying.iloc[ id ][ 'icratio' ] ), \
                     float( debtpaying.iloc[ id ][ 'sheqratio' ] ), space( int( debtpaying.iloc[ id ][ 'quarter' ] ) - 1 ), \
                     float( debtpaying.iloc[ id ][ 'adratio' ] ) )
            except:
                pass

            try:
                divi = df_divi_data.loc[int(code)]
                content += '\ndivision:\n年份    公布日期  分红金额(每10股)  转增股数(每10股)\n'

                if type(divi) == pd.Series:
                    divi = divi.to_frame().T

                if type(divi) == pd.DataFrame:
                    divi = divi.sort_values(by=['year', 'report_date'],
                                            axis=0,
                                            ascending=True)
                    for id in range(divi.index.size):
                        content += '{0}  {1}  {2:-12d}  {3:-16d}\n'.format( divi.iloc[ id ][ 'year' ], divi.iloc[ id ][ 'report_date' ], int( divi.iloc[ id ][ 'divi' ] ), \
                        int( divi.iloc[ id ][ 'shares' ] ) )
                else:
                    ERROR('divi type error.')
            except:
                pass

            try:
                forcast_quarter_data = df_forcast_quarter_report_data.loc[int(
                    code)]
                content += '\nforcast quarter report:\n发布日期    业绩变动类型  上年同期每股收益  业绩变动范围\n'

                if type(forcast_quarter_data) == pd.Series:
                    forcast_quarter_data = forcast_quarter_data.to_frame().T

                if type(forcast_quarter_data) == pd.DataFrame:
                    forcast_quarter_data = forcast_quarter_data.sort_values(
                        by='report_date', axis=0, ascending=True)
                    for id in range(forcast_quarter_data.index.size):
                        content += '{0}  {1:>8s}  {2:-14.2f}  {3:>12s}\n'.format( forcast_quarter_data.iloc[ id ][ 'report_date' ], \
                         forcast_quarter_data.iloc[ id ][ 'type' ], float( forcast_quarter_data.iloc[ id ][ 'pre_eps' ] ), \
                         forcast_quarter_data.iloc[ id ][ 'range' ] )
                else:
                    ERROR('forcast_quarter_data type error.')
            except:
                pass

            try:
                restrict = df_restrict_stock_data.loc[int(code)]
                content += '\nrestrict:\n解禁日期    解禁数量(万股)  占总盘比率\n'

                if type(restrict) == pd.Series:
                    restrict = restrict.to_frame().T

                if type(restrict) == pd.DataFrame:
                    restrict = restrict.sort_values(by='date',
                                                    axis=0,
                                                    ascending=True)
                    for id in range(restrict.index.size):
                        content += '{0}  {1:-12.2f}  {2:-10.2f}\n'.format( restrict.iloc[ id ][ 'date' ], \
                          float( restrict.iloc[ id ][ 'count' ] ), float( restrict.iloc[ id ][ 'ratio' ] ) )
                else:
                    ERROR('restrict type error.')
            except:
                pass

            try:
                df_news = ts.get_notices(code)
                content += '\nnotice:\n'
                for index in range(0, 10):  # df_news.index:
                    content += '{3}、{0}\t{1}\tdate:{2}\n'.format( df_news[ 'title' ][ index ], \
                     df_news[ 'type' ][ index ], df_news[ 'date' ][ index ], index + 1 )
                    if index < 3:
                        content += ts.notice_content(df_news['url'][index])
                        content += '\n\n'
                    content += '\n'
            except:
                pass

            LOG(content)
            dict_stock_info[code] = content
        return dict_stock_info
コード例 #30
0
ファイル: getData.py プロジェクト: suruiqiang/StockTushare
def Getxinxidilei():
    df = ts.get_notices(date=getNowTime())
    print(df)
    return df
コード例 #31
0
 def getNotice(self):
     file_name = self.code + '_' + self.startDate + '.csv'
     path = self.index + self.index_notice + file_name
     data = ts.get_notices(code=self.code, date=self.startDate)
     data.to_csv(path, encoding='utf-8')
     print(file_name)
コード例 #32
0
ファイル: stock.py プロジェクト: ArseneLupinhb/py_al
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import tushare as ts

# 显示matplotlib路径
print(matplotlib.matplotlib_fname())
# 全局路径设置
os.getcwd()
source_path = os.getcwd() + r'/idea/work/'

# 一次性获取最近一个日交易日所有股票的交易数据
# ts_df = ts.get_today_all()
# 新闻数据
new_df = ts.get_notices()

# 保存数据到csv
# ts_df.to_csv(source_path + r'ts_df.csv', encoding='utf_8_sig')
# new_df.to_csv(source_path + r'new_df.csv', encoding='utf_8_sig')

# 从csv读取数据
ts_df = pd.read_csv(source_path + r'ts_df.csv')

ts_df.info()
ts_df.head()
ts_df.shape
# 使用 utf_8_sig 可以解决中文乱码问题

(ts_df['trade'] - ts_df['open']) / ts_df['open'] * 100
ts_df['settlement'] * (1 + ts_df['changepercent'] / 100)
コード例 #33
0
import tushare as ts

# 即时新闻
# 获取即时财经新闻,类型包括国内财经、证券、外汇、期货、港股和美股等新闻信息。
news = ts.get_latest_news()
print(news)

# 信息地雷
# 获取个股信息地雷数据
n = ts.get_notices('600000')
print(n)

# 新浪股吧
# 获取sina财经股吧首页的重点消息。股吧数据目前获取大概17条重点数据,可根据参数设置是否显示消息内容,默认情况是不显示。
gb = ts.guba_sina()
print(gb)
コード例 #34
0
ファイル: demo.py プロジェクト: CodingOneWorld/stockAnalysis
# -*- coding: utf-8 -*-

import tushare as ts

# ts.get_latest_news(show_content=True) #默认获取最近80条新闻数据,只提供新闻类型、链接和标题
# ts.get_latest_news(top=5,show_content=True) #显示最新5条新闻,并打印出新闻内容

news = ts.get_notices()
print(news)

news = ts.guba_sina()
print(news)
print(news['title'][4]['content'])