由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Stock版 - 共享一个自己写的python程序,有兴趣的可以玩玩
相关主题
几个股票的Short % of Float1:10 reverse split,持有5个put会怎么换算?
看不懂今天的走势银子的底部在哪?
Holy, 听了版上大牛的话,把老爸的几年虾青素钱赚来了第一次 买option 看看手气
Walmart suffers 1st US sales declineItaly delivers tough austerity measures
天啊, AMR持有者明天要大翻身了!!请问在IB烧裸扑最少要放多少钱?谢谢
Option Risk Management - Theory of Stop Loss on Time (转载)FOREX和股票的操作手法完全不同啊
nake short option 问题假涨?Many underline stocks are not rising much
用options 挣了一个IPAD钱的看过来Microsoft 其实就是Fired掉一个码农,不要大惊小怪
相关话题的讨论汇总
话题: axs话题: close话题: datime话题: 033话题: previous
进入Stock版参与讨论
1 (共1页)
h*********w
发帖数: 1549
1
import ystockquote
from pprint import pprint
import sys
from numpy import *
import matplotlib.pyplot as plt
import datetime
#print name,':', ystockquote.get_price(name)
#pprint(ystockquote.get_historical_prices('GOOG', '2013-01-03', '2013-01-08'
))
#print ystockquote.get_historical_prices('GOOG', '2013-01-03', '2013-01-08')
['2013-01-04']['Open']
#pprint(ystockquote.get_all(name))
#ystockquote.urlopen('http://www.google.com/finance/getprices?i=60&p=10d&f=d,o,h,l,c,v&df=cpct&q=IBM')
#print ystockquote.get_bid_realtime('GOOG')
class bcolors:
Red = '\033[91m'
Green = '\033[92m'
Blue = '\033[94m'
Cyan = '\033[96m'
White = '\033[97m'
Yellow = '\033[93m'
Magenta = '\033[95m'
Grey = '\033[90m'
Black = '\033[90m'
Bold = '\033[1m'
Underline = '\033[4m'
Default = '\033[99m'
ENDC = '\033[0m'
def disable(self):
self.Red = ''
self.Green = ''
self.Blue = ''
self.Cyan = ''
self.White = ''
self.Yellow = ''
self.Magenta = ''
self.Grey = ''
self.Black = ''
self.Bold = ''
self.Underline = ''
self.Default = ''
self.ENDC = ''
def plot_price(name):
f,axs = plt.subplots(4,1, figsize=(8,10))
url = 'http://chartapi.finance.yahoo.com/instrument/1.0/'+name+'/chartdata;type=quote;range=1d/csv'
req = ystockquote.Request(url)
resp = ystockquote.urlopen(url)
content = resp.read().split('\n')[:-1]
for n in range(len(content)):
if content[n].find('previous_close')==0:
previous_close = float(content[n].replace('previous_close:',''))
if content[n].find(':')==-1:
break
content = content[n:]
timestamp,close,high,low,open1,volume = array([tmp.split(',') for tmp in
content],dtype=float).T
url = 'http://finance.yahoo.com/d/quotes.csv?s='+name+'&f=aba5b6'
req = ystockquote.Request(url)
resp = ystockquote.urlopen(url)
content = resp.read().split('\n')[0].split(',')
ask,bid,askSize,bidSize = content
# 1 day
datime = [datetime.datetime.fromtimestamp(tmp) for tmp in timestamp]
axs[0].plot(datime,open1)
axs[0].plot([datime[0],datime[0]+datetime.timedelta(0,23400)],previous_
close*ones(2),'k')
axs[0].grid('on')
axs[0].set_xlim(datime[0],datime[0]+datetime.timedelta(0,23400))
# duo days
for n,N in enumerate([30,365,1826]):
datime = [datetime.datetime.now()+datetime.timedelta(days=i) for i
in range(-N,1)]
quote = ystockquote.get_historical_prices(name, datime[0].strftime('
%Y-%m-%d'), datime[-1].strftime('%Y-%m-%d'))
datime = sorted([datetime.datetime.strptime(tmp,'%Y-%m-%d') for tmp
in quote.keys()])
quote = [quote[tmp]['Close'] for tmp in sorted(quote)]
axs[n+1].plot(datime,quote)
axs[n+1].grid('on')
for ax in axs:
plt.setp( ax.xaxis.get_majorticklabels(), rotation=12)
plt.subplots_adjust(left=0.06, bottom=0.05, right=0.95, top=0.98, wspace
=0.05, hspace=0.3)
f.canvas.set_window_title(name)
# bid
axs[0].text(0.95, 0.95, 'bid: ' +bid+'x'+bidSize+' '+'ask: '+ask+'x'+
askSize,
verticalalignment='top', horizontalalignment='right',
transform=axs[0].transAxes, fontsize=15)
axs[0].text(0.70, 0.80, str(close[-1]),
verticalalignment='top', horizontalalignment='right', color='b',
transform=axs[0].transAxes, fontsize=15)
color = 'r'*int(close[-1]previous_
close)+'0.5'*int(close[-1]==previous_close)
axs[0].text(0.95, 0.80, '%+-.2f'%(close[-1]-previous_close)+' %+-.2f'%(
float(close[-1]-previous_close)/float(previous_close)*100)+'%',
verticalalignment='top', horizontalalignment='right', color=color,
transform=axs[0].transAxes, fontsize=15)
# stuff
all1 = ystockquote.get_all(name)
print bcolors.Bold+name+' '+bcolors.Blue+str(close[-1])+bcolors.ENDC
if float(all1['change'])>0:
print bcolors.Green+all1['change']+' +'+'%.2f'%(float(close[-1]-
previous_close)/float(all1['price'])*100)+'%'+bcolors.ENDC
else:
print bcolors.Red+all1['change']+' '+'%.2f'%(float(close[-1]-
previous_close)/float(all1['price'])*100)+'%'+bcolors.ENDC
print '---------------------'
# pprint(all1)
return close[-1]
if __name__=='__main__':
if len(sys.argv)<=1:
sys.argv = ['','spy','atvi','tsla','goog']
print '---------------------'
for name in sys.argv[1:]:
close = plot_price(name)
if len(sys.argv[0])>1:
plt.show()
F****s
发帖数: 3761
2
楼主一般怎么用程序判底。。
h*********w
发帖数: 1549
3
刚开始玩,知识还不全面,打算继续用一定策略筛选潜力股。

【在 F****s 的大作中提到】
: 楼主一般怎么用程序判底。。
1 (共1页)
进入Stock版参与讨论
相关主题
Microsoft 其实就是Fired掉一个码农,不要大惊小怪天啊, AMR持有者明天要大翻身了!!
option call 的思考Option Risk Management - Theory of Stop Loss on Time (转载)
以前做option时写的notenake short option 问题
Yellen Claus is the last hope for bulls this year用options 挣了一个IPAD钱的看过来
几个股票的Short % of Float1:10 reverse split,持有5个put会怎么换算?
看不懂今天的走势银子的底部在哪?
Holy, 听了版上大牛的话,把老爸的几年虾青素钱赚来了第一次 买option 看看手气
Walmart suffers 1st US sales declineItaly delivers tough austerity measures
相关话题的讨论汇总
话题: axs话题: close话题: datime话题: 033话题: previous