Beispiel #1
0
def merge_length(start, end):

    lens = np.arange(start=0.0100, stop=0.0200, step=0.0001)
    columns = []
    for x in lens:
        columns.append("%.4f" % x)
    print(columns)
    df = pd.DataFrame(columns=columns)
    eq = ts.Equity()
    all = eq.Equ(equTypeCD='A', listStatusCD='L', field='ticker')
    all['ticker'] = all['ticker'].map(lambda x: str(x).zfill(6))
    for i, row in all.iterrows():
        path = cfg.get_length_ratio_path(row['ticker'], start, end)
        try:
            if os.path.exists(path):
                len_df = pd.DataFrame.from_csv(path)
                len_df.index = len_df.index.map(lambda x: "%.4f" % x)
                # print(len_df.index)
                for len in columns:
                    # print(len_df.loc[len, 'ratio'])
                    df.loc[row['ticker'], len] = len_df.loc[len, 'ratio']
                print(row['ticker'])
        except Exception as e:
            print(e.message)
            continue

    df.to_csv("/home/chengang/tab.csv")
Beispiel #2
0
def stock_open_data_download():
    # 获取沪深A股正常股票信息,listStatusCD上市状态,可选状态有L——上市,S——暂停,DE——已退市,UN——未上市
    eq = ts.Equity()
    df = eq.Equ(equTypeCD='A',
                listStatusCD='L',
                field='ticker,secShortName,totalShares,nonrestFloatShares')
    df['ticker'] = df['ticker'].map(lambda x: str(x).zfill(6))
    df.to_csv("./data/stock_open.csv")
def fetch_stock_list_to_mongo():
    eq = ts.Equity()
    df = eq.Equ(equTypeCD='A', listStatusCD='L', field='')
    df['ticker'] = df['ticker'].map(lambda x: str(x).zfill(6))
    mongo = Mongo()
    db = mongo.getDB()
    cursor = db.stock_list.find()
    if cursor.count() == 0:
        db.stock_list.insert(json.loads(df.to_json(orient='records')))
Beispiel #4
0
def get_float_share(code, date):
    '''
    every day will update local storage
    :param code:
    :param start: 20100101
    :param end: 20100101
    :return:
    '''

    share_path = cfg.get_today_share_path(code)
    # if os.path.exists(share_path)
    eq = ts.Equity()
Beispiel #5
0
def find_nonrest():
    eq = ts.Equity()
    df = eq.Equ(equTypeCD='A', listStatusCD='L', field='ticker')
    df['ticker'] = df['ticker'].map(lambda x: str(x).zfill(6))
    for i, row in df.iterrows():
        print(row['ticker'])
        dff = eq.EquShare(
            ticker=row['ticker'],
            field='ticker,changeDate,totalShares,sharesA,floatA,nonrestfloatA')
        for j, first in dff.iterrows():
            print(j)
            if j != 0:
                break
            if first['floatA'] != first['nonrestfloatA']:
                print(first)
Beispiel #6
0
def get_share_online(code):
    '''
    get share from ipo till now
    :param code:
    :return:
    '''
    eq = ts.Equity()
    ipo = eq.EquIPO(ticker=code, field='publishDate,onlineIssueDate,listDate')
    start = '2006-01-01'
    if not ipo.empty:
        print(ipo)
        start = ipo.iat[0, 0]
    start = start.replace("-", "")
    # end = datetime.date.today().strftime("%Y%m%d")
    # print(start, end)
    share = eq.EquShare(ticker=code, beginDate=start)
    print(share)
Beispiel #7
0
def fetch_():
    ts.set_token(cfg.get_datayes_key())
    eq = ts.Equity()
    df = eq.Equ(equTypeCD='A', listStatusCD='L', field='ticker')
    df['ticker'] = df['ticker'].map(lambda x: str(x).zfill(6))
    start, end = '20150901', '20160326'
    # thread can not make full use of cpu
    for i, row in df.iterrows():
        csv = cfg.get_ratio_table_path(row['ticker'], start, end)
        if os.path.exists(csv):
            print("{0}/{1} {2} exists.".format(i, len(df.index), row['ticker']))
            continue
        # code_queue.put(row['ticker'])
        # code_list.append(str(row['ticker']))
        proc_queue.put(row['ticker'])

    # for i in range(3):
    #     thread = ExportThread(thread_id, code_queue, start, end)
    #     thread.start()
    #     threads.append(thread)
    #     thread_id += 1
    #
    # get_code_and_export(0, code_queue, start, end)
    #
    # for t in threads:
    #     t.join()
    #
    # print("Exit main thread.")

    processes = 4
    for i in range(processes):
        p = ExportProcess(i+1, start, end, proc_queue)
        p.start()
        procs.append(p)

    for p in procs:
        p.join()

    print("Exit main")
Beispiel #8
0
#-*- coding: UTF-8 -*-  
import sys
reload(sys)
sys.setdefaultencoding('utf8')

from sqlalchemy import create_engine
import tushare as ts
#import pandas as pd
#import numpy as np
import time
#nowtime = datetime.datetime.now()
nowtime = time.strftime('%Y-%m-%d %H:%M:%S')
engine = create_engine('mysql://*****:*****@127.0.0.1/db_equ?charset=utf8')

eq = ts.Equity()

import MySQLdb
# 打开数据库连接
db = MySQLdb.connect("127.0.0.1","root","root","db_mkt" )
# 使用cursor()方法获取操作游标 
cursor = db.cursor()

#股票列表: 获取沪深上市公司基本情况
def stock():
	dflist = ts.get_stock_basics()
	dflist.insert(0,'uploadtime',nowtime)
	dflist.to_sql('tb_list',engine,if_exists='append')
	#dflist.to_excel('E:/Anaconda/getdata/test.xlsx')
	def insertid():
		sql = """ALTER TABLE tb_list 
				ADD list_id int(20) not null auto_increment ,
Beispiel #9
0
import matplotlib.pyplot as plt
#%matplotlib inline

import tushare as ts
ts.set_token(
    '6cbc132dcf304322dc7b6f1d714d792fe224049b2038abf29e7711bf71334b52')
'''
股票数据:名称、上市交易所 上市时间, 历史日数据

历史某天的分笔数据
'''
#DataAPI.TickRTIntraDayMoneyFlowOrderGet(securityID=u"000001.XSHE",startTime=u"09:30",endTime=u"11:00",field=u"",pandas="1")
eq_mt = ts.Master()
SecID = eq_mt.SecID(cnSpell='gxgk')

eq_tl = ts.Equity()
candi_stock_ipo = eq_tl.EquIPO(secID='002074.XSHE')

candi_stock_d = ts.get_h_data('002074', start='2006-10-18', end='2016-04-12')

## 获取历史分笔数据

candi_stock_fb = ts.get_tick_data('002074', date='2016-04-12')
candi_stock_fb.head(10)
dates = pd.to_datetime(shz.index)


## 第一种作图方法
def simple_plot(dates, data):
    fig = plt.figure(figsize=(10, 4))
    plt_sh = fig.add_subplot(1, 1, 1)