def diff_svg(stock_a,stock_b): bk='主板' # init the figure pylab.figure(figsize=(9,6)) # get the dates, prepare the ticks, get today, and the mean price dates,ps,_=zip(*list(x.split() for x in open(bk+'_mean.txt'))) both_ticks=haitai.graph.gen_ticks(dates) today=dates[0] ps=numpy.array(list(map(float,ps))) # sets of stocks th = set(haitai.get_symbol_list(bk)) outfile='output/tmp.svg' # data of the stock_a rtn = netease_daily.load_fresh_stock(stock_a, dates) if rtn is None : return name, price, volum = rtn min_days=len(price) print(stock_a, name, today,end='\r') plot(price,outfile, background=ps[:min_days], title="%s (%s) %s"%(name, stock_a, today), both_ticks = both_ticks ) return (open(outfile).read())
def diff_svg(stock_a, stock_b): bk = '主板' # init the figure pylab.figure(figsize=(9, 6)) # get the dates, prepare the ticks, get today, and the mean price dates, ps, _ = zip(*list(x.split() for x in open(bk + '_mean.txt'))) both_ticks = haitai.graph.gen_ticks(dates) today = dates[0] ps = numpy.array(list(map(float, ps))) # sets of stocks th = set(haitai.get_symbol_list(bk)) outfile = 'output/tmp.svg' # data of the stock_a rtn = netease_daily.load_fresh_stock(stock_a, dates) if rtn is None: return name, price, volum = rtn min_days = len(price) print(stock_a, name, today, end='\r') plot(price, outfile, background=ps[:min_days], title="%s (%s) %s" % (name, stock_a, today), both_ticks=both_ticks) return (open(outfile).read())
def diff_all(): bk='主板' # init the figure pylab.figure(figsize=(9,6)) # get the dates, prepare the ticks, get today, and the mean price dates,ps,_=zip(*list(x.split() for x in open(bk+'_mean.txt'))) both_ticks=haitai.graph.gen_ticks(dates) today=dates[0] ps=numpy.array(list(map(float,ps))) # sets of stocks th = set(haitai.get_symbol_list(bk)) for f in sorted(th) : outfile='output/figs/'+f+'.svg' # if the svg file is new, do nothing if os.path.exists(outfile) : mtime=os.path.getmtime(outfile) mtime=datetime.date.fromtimestamp(mtime) if today < str(mtime) : continue rtn = netease_daily.load_fresh_stock(f, dates) if rtn is None : continue name, price, volum = rtn min_days=len(price) print(f,name, today,end='\r') plot(price,outfile, background=ps[:min_days], title="%s (%s) %s"%(name,f, today), both_ticks = both_ticks )
def diff_all(): bk = '主板' # init the figure pylab.figure(figsize=(9, 6)) # get the dates, prepare the ticks, get today, and the mean price dates, ps, _ = zip(*list(x.split() for x in open(bk + '_mean.txt'))) both_ticks = haitai.graph.gen_ticks(dates) today = dates[0] ps = numpy.array(list(map(float, ps))) # sets of stocks th = set(haitai.get_symbol_list(bk)) for f in sorted(th): outfile = 'output/figs/' + f + '.svg' # if the svg file is new, do nothing if os.path.exists(outfile): mtime = os.path.getmtime(outfile) mtime = datetime.date.fromtimestamp(mtime) if today < str(mtime): continue rtn = netease_daily.load_fresh_stock(f, dates) if rtn is None: continue name, price, volum = rtn min_days = len(price) print(f, name, today, end='\r') plot(price, outfile, background=ps[:min_days], title="%s (%s) %s" % (name, f, today), both_ticks=both_ticks)
import haitai.graph import haitai.common import haitai if __name__ == '__main__': ndays = 3000 bk = '全部' bk = '中小' bk = '主板' # dates dates = haitai.common.recent_n_days(ndays) # stocks th = set(haitai.get_symbol_list(bk)) d = 'data/163_daily' fs = os.listdir(d) fs = [f for f in fs if f != '000300.ss'] print(fs) #th = set(list(th)[:100]) # for debug only # get data pss, vols = haitai.common.load_stock_set(fs, ndays, dates) # compute p = sum(pss) print(p) p = p / p[0] v = haitai.common.mean_with_nan(vols)
# one diff svg #svg=get_svg(stock_id) if '-' in stock_id: stock_a, _, stock_b = stock_id.partition('-') else: stock_a = stock_id stock_b = None svg = haitai.diff.diff_svg(stock_a, stock_b) if svg is None: return "no such stock" return "<svg>%s</svg>" % (svg) if __name__ == '__main__': l = haitai.get_symbol_list() l = sorted(l) l = [x.split('.')[0] for x in l] stock_list = l stock_order = {k: v for v, k in enumerate(stock_list)} cherrypy.config.update("server.config") cherrypy.tree.mount( Figs(), '/figs', {'/': { 'request.dispatch': cherrypy.dispatch.MethodDispatcher() }}, ) cherrypy.engine.start()
bss.append(bs) return cal_mean(bss), list(reversed(cal_std(bss))) if __name__ == '__main__': ndays=3000 bk='全部' bk='中小' bk='主板' # dates dates=haitai.common.recent_n_days(ndays) # stocks th = set(haitai.get_symbol_list(bk)) d = 'data/163_daily' fs = os.listdir(d) fs = [f for f in fs if f != '000300.ss'] print(fs) #th = set(list(th)[:100]) # for debug only # get data pss, vols = haitai.common.load_stock_set(fs,ndays,dates) # compute p=sum(pss) print(p) p=p/p[0] v=haitai.common.mean_with_nan(vols)