Skip to content

Commit

Permalink
Merge branch 'rc'
Browse files Browse the repository at this point in the history
  • Loading branch information
toomore committed Dec 15, 2013
2 parents a51bf89 + 453a45b commit 5395c08
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 17 deletions.
7 changes: 6 additions & 1 deletion README.rest
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ grs 台灣上市股票價格擷取
-----------------------------

:Authors: Toomore Chiang
:Version: 0.2.0 of 2012/04/13
:Version: 0.2.1 of 2013/12/16
:Python Version: Python 2.6-2.7

-----------------------------
Expand Down Expand Up @@ -258,6 +258,11 @@ Quick Start
Change Logs
-----------------------------

0.2.1 2013/12/16
====================================

- 修正:部分資料改用 tuple

0.2.0 2012/04/13
====================================

Expand Down
26 changes: 13 additions & 13 deletions grs/fetch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ def __fetch_data(self, stock_no, nowdatetime=datetime.today()):
return csv_read

def __to_list(self, csv_file):
""" [list] 串接每日資料 舊→新"""
""" [tuple] 串接每日資料 舊→新"""
tolist = []
for i in csv_file:
i = [v.strip().replace(',', '') for v in i]
try:
for v in [1, 2, 3, 4, 5, 6, 8]:
for v in (1, 2, 3, 4, 5, 6, 8):
i[v] = float(i[v])
except:
pass
Expand All @@ -104,20 +104,20 @@ def __to_list(self, csv_file):
self.__info = (tolist[0][0].split(' ')[1],
tolist[0][0].split(' ')[2].decode('cp950'))
self.__RawRowsName = tolist[1]
return tolist[2:]
return tuple(tolist[2:])
else:
return []
return tuple([])

def __serial_fetch(self, no, month):
""" [list] 串接每月資料 舊→新 """
re = []
""" [tuple] 串接每月資料 舊→新 """
re = ()
self.__getMons = month
self.__getNo = no
for i in range(month):
nowdatetime = datetime.today() - relativedelta(months=i)
tolist = self.__to_list(self.__fetch_data(no, nowdatetime))
re = tolist + re
return re
return tuple(re)

def __plusMons(self, month):
re = []
Expand Down Expand Up @@ -146,8 +146,8 @@ def __serial_price(self, rows=6):
""" [list] 取出某一價格序列 舊→新
預設序列收盤價 → __serial_price(6)
"""
re = [float(i[rows]) for i in self.__raw_data]
return re
re = (float(i[rows]) for i in self.__raw_data)
return list(re)

def __cal_MA(self, date, row):
""" 計算移動平均數
Expand Down Expand Up @@ -190,8 +190,8 @@ def MA(self, date):
def MAV(self, date):
""" 計算成交股數均量與持續天數 """
val, conti = self.__cal_MA(date, 1)
val = [round(i / 1000, 3) for i in val]
return val, conti
val = (round(i / 1000, 3) for i in val)
return list(val), conti

def MAO(self, date1, date2):
""" 計算乖離率(均價)
Expand Down Expand Up @@ -220,8 +220,8 @@ def openprice(self):
@property
def value(self):
""" 成交量序列 """
val = [round(i / 1000, 3) for i in self.__serial_price(1)]
return val
val = (round(i / 1000, 3) for i in self.__serial_price(1))
return list(val)

def __cal_MAOPoint(self, data, s=5, pm=False):
"""判斷轉折點位置
Expand Down
11 changes: 9 additions & 2 deletions grs/stock_no.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"證期會代碼","公司簡稱","TSE 產業別"
UPDATE,"2012-03-28",0
"證期會代碼","公司簡稱","TSE產業別"
UPDATE,"2012-07-31",0
1101,"台泥",1
1102,"亞泥",1
1103,"嘉泥",1
Expand Down Expand Up @@ -46,6 +46,7 @@ UPDATE,"2012-03-28",0
1325,"恒大",3
1326,"台化",3
1337,"F-再生",3
1339,"昭輝",3
1402,"遠東新",4
1409,"新纖",4
1410,"南染",4
Expand Down Expand Up @@ -129,6 +130,7 @@ UPDATE,"2012-03-28",0
1560,"中砂",5
1582,"信錦",28
1583,"程泰",5
1589,"F-永冠",5
1590,"F-亞德",5
1603,"華電",6
1604,"聲寶",6
Expand Down Expand Up @@ -591,6 +593,7 @@ UPDATE,"2012-03-28",0
3593,"力銘",26
3596,"智易",27
3598,"奕力",24
3599,"旺能",26
3605,"宏致",28
3607,"谷崧",28
3617,"碩天",31
Expand All @@ -616,6 +619,8 @@ UPDATE,"2012-03-28",0
4108,"懷特",22
4119,"旭富",22
4133,"亞諾法",22
4141,"F-龍燈",22
4142,"國光生",22
4144,"F-康聯",22
4306,"炎洲",3
4414,"如興",4
Expand All @@ -642,6 +647,7 @@ UPDATE,"2012-03-28",0
5007,"三星",10
5203,"訊連",30
5215,"F-科嘉",25
5234,"達興",26
5305,"敦南",24
5388,"中磊",27
5434,"崇越",29
Expand All @@ -660,6 +666,7 @@ UPDATE,"2012-03-28",0
5871,"F-中租",20
5880,"合庫金",17
5906,"F-台南",18
5907,"F-大洋",18
6005,"群益證",17
6108,"競國",28
6112,"聚碩",30
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'含即時盤、台灣時間轉換、開休市判斷。'

setup(name='grs',
version='0.2.0',
version='0.2.1',
description=description,
long_description=long_description,
author='Toomore Chiang',
Expand Down
17 changes: 17 additions & 0 deletions test_prof.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from time import time
from datetime import datetime
from grs import stock
t = time()
a = []
times = 1

for i in range(times):
tt = time()
stock(1201).MA(3)
a.append(time()-tt)

print "end {0}".format(datetime.now())
print "Max: {0}".format(max(a))
print "Min: {0}".format(min(a))
print "ALL: {0}".format(time()-t)
print "Avg: {0}".format((sum(a)-max(a)-min(a))/(times-2))

0 comments on commit 5395c08

Please sign in to comment.