def update_fund_nav(): db_config = setting.DATABASES['fund_stat'] conn, cr = create_db_connection(db_config['HOST'], db_config['DB'], db_config['PORT'], db_config['USER'], db_config['PASSWD']) fd = ts.Fund() cnt = 0 for line in open("fundcode"): tc = line.strip() print cnt, "code:", tc cnt += 1 #Get fund info f1 = fd.FundNav( ticker=tc, field="secID,secShortName,endDate,NAV,ACCUM_NAV,ADJUST_NAV") if not f1.empty: f1['code'] = tc pd.io.sql.to_sql(f1, "fund_nav", conn, flavor='mysql', if_exists='append', index=False) conn.commit() db_close(conn, cr)
def preprocess(): db_config = setting.DATABASES['fund_stat'] conn,cr = create_db_connection(db_config['HOST'],db_config['DB'],db_config['PORT'],db_config['USER'],db_config['PASSWD']) fd = ts.Fund() cnt = 0 for line in open("fundcode"): tc = line.strip() print cnt,"code:",tc cnt += 1 f1 = fd.FundNav(ticker = tc, field = "secID,secShortName,endDate,NAV,ACCUM_NAV,ADJUST_NAV") if not f1.empty: secID = f1.ix[0, "secID"] # print secID sql = "update fund_nav set code= %s where secID=%s" cr.execute(sql, (tc, secID)) if cnt % 50 == 0: print "commit" conn.commit() # for rz in cr.fetchall(): # print rz conn.commit() db_close(conn,cr)
def fund(self): fd = ts.Fund() df = fd.FundDiv( ticker='184688', adjustedType='D', beginDate='20000101', field= 'secShortName,effectDate,publishDate,dividendAfTax,dividendBfTax') print(df) dd = ts.fund_holdings(2015, 4) print(dd[['name', 'nums', 'clast', 'amount']])
import tushare as ts import sys import os import marshal import numpy as np import pandas as pd from pandas.compat import StringIO from sklearn.linear_model import LinearRegression as lr import warnings import MySQLdb mysql = MySQLdb.connect(host='localhost', port=3306, user='******', passwd='', db='fund_stat') ts.set_token('eaf6b3ffd2808fee8221dbbc2ab223c1ffa4e64c29ce508d7fcdaefd09c264ba') fd = ts.Fund() cnt = 0 for line in open("fundcode"): tc = line.strip() print cnt,"code:",tc cnt += 1 #Get fund info f1 = fd.FundNav(ticker = tc, field = "secID,secShortName,endDate,NAV,ACCUM_NAV,ADJUST_NAV") if not f1.empty: pd.io.sql.to_sql(f1, "fund_nav", mysql, flavor='mysql', if_exists='append', index=False)
def get_fund_data(fund_code): fd = ts.Fund() return fd.FundNav( ticker=fund_code, beginDate='20150101', field='ticker,endDate,NAV,publishDate,ACCUM_NAV,ADJUST_NAV')