Skip to content

Commit

Permalink
Merge branch 'v0.5.6rc'
Browse files Browse the repository at this point in the history
  • Loading branch information
toomore committed Jun 1, 2014
2 parents bc6d945 + a7698fb commit f2a0134
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 12,580 deletions.
10 changes: 9 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ grs 台灣上市上櫃股票價格擷取
-----------------------------

:Authors: Toomore Chiang
:Version: 0.5.5 of 2014/05/18
:Version: 0.5.6 of 2014/06/01
:Python Version: Python 2.7, PyPy
:Docs: http://grs-docs.toomore.net/

Expand Down Expand Up @@ -302,6 +302,14 @@ Quick Start
Change Logs
-----------------------------

0.5.6 2014/06/01
====================================

- 修正:tools 儲存路徑
- 新增:日常交易的代碼與名稱(`grs.twseno.ImportCSV.get_stock_list`)
- 新增:日常交易的類別代碼與名稱(`grs.twseno.ImportCSV.get_stock_comps_list`)
- 已知問題:盤中即時資訊擷取無法使用 grs.RealtimeStock/RealtimeWeight

0.5.5 2014/05/18
====================================

Expand Down
8 changes: 7 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ grs 台灣上市上櫃股票價格擷取
-----------------------------

:Authors: Toomore Chiang
:Version: 0.5.5 of 2014/05/18
:Version: 0.5.6 of 2014/06/01
:Python Version: Python 2.7, PyPy
:Docs: http://grs-docs.toomore.net/

Expand Down Expand Up @@ -81,6 +81,12 @@ Feature
Change Logs
-----------------------------

* 0.5.6 2014/06/01
- 修正:tools 儲存路徑
- 新增:日常交易的代碼與名稱(:func:`grs.twseno.ImportCSV.get_stock_list` )
- 新增:日常交易的類別代碼與名稱(:func:`grs.twseno.ImportCSV.get_stock_comps_list` )
- 已知問題:盤中即時資訊擷取無法使用 grs.RealtimeStock/RealtimeWeight

* 0.5.5 2014/05/18
- 修正: :func:`grs.fetch_data.SimpleAnalytics.CKMAO` to be classmethod.

Expand Down
4 changes: 4 additions & 0 deletions docs/source/realtime.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Realtime TWSE 台股盤中即時資訊
===============================

.. warning::

目前無法使用

.. autoclass:: grs.RealtimeStock
:members:

Expand Down
2 changes: 1 addition & 1 deletion grs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# THE SOFTWARE.

__title__ = 'grs'
__version__ = '0.5.5'
__version__ = '0.5.6'
__author__ = 'Toomore Chiang'
__license__ = 'MIT'
__copyright__ = 'Copyright (C) 2012, 2013, 2014 Toomore Chiang'
Expand Down
56 changes: 45 additions & 11 deletions grs/best_buy_or_sell.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,50 +48,77 @@ def check_mins_bias_ratio(self):

##### 四大買點 #####
def best_buy_1(self):
""" 量大收紅 """
""" 量大收紅
:rtype: bool
"""
result = self.data.value[-1] > self.data.value[-2] and \
self.data.price[-1] > self.data.openprice[-1]
return result

def best_buy_2(self):
""" 量縮價不跌 """
""" 量縮價不跌
:rtype: bool
"""
result = self.data.value[-1] < self.data.value[-2] and \
self.data.price[-1] > self.data.price[-2]
return result

def best_buy_3(self):
""" 三日均價由下往上 """
""" 三日均價由下往上
:rtype: bool
"""
return self.data.moving_average(3)[1] == 1

def best_buy_4(self):
""" 三日均價大於六日均價 """
""" 三日均價大於六日均價
:rtype: bool
"""
return self.data.moving_average(3)[0][-1] > \
self.data.moving_average(6)[0][-1]

##### 四大賣點 #####
def best_sell_1(self):
""" 量大收黑 """
""" 量大收黑
:rtype: bool
"""
result = self.data.value[-1] > self.data.value[-2] and \
self.data.price[-1] < self.data.openprice[-1]
return result

def best_sell_2(self):
""" 量縮價跌 """
""" 量縮價跌
:rtype: bool
"""
result = self.data.value[-1] < self.data.value[-2] and \
self.data.price[-1] < self.data.price[-2]
return result

def best_sell_3(self):
""" 三日均價由上往下 """
""" 三日均價由上往下
:rtype: bool
"""
return self.data.moving_average(3)[1] == -1

def best_sell_4(self):
""" 三日均價小於六日均價 """
""" 三日均價小於六日均價
:rtype: bool
"""
return self.data.moving_average(3)[0][-1] < \
self.data.moving_average(6)[0][-1]

def best_four_point_to_buy(self):
""" 判斷是否為四大買點 """
""" 判斷是否為四大買點
:rtype: str or False
"""
result = []
if self.check_mins_bias_ratio() and \
(self.best_buy_1() or self.best_buy_2() or self.best_buy_3() or \
Expand All @@ -110,7 +137,10 @@ def best_four_point_to_buy(self):
return result

def best_four_point_to_sell(self):
""" 判斷是否為四大賣點 """
""" 判斷是否為四大賣點
:rtype: str or False
"""
result = []
if self.check_plus_bias_ratio() and \
(self.best_sell_1() or self.best_sell_2() or self.best_sell_3() or \
Expand All @@ -129,7 +159,11 @@ def best_four_point_to_sell(self):
return result

def best_four_point(self):
""" 判斷買點或賣點 """
""" 判斷買點或賣點
:rtype: tuple
:returns: (bool, str)
"""
buy = self.best_four_point_to_buy()
sell = self.best_four_point_to_sell()

Expand Down
22 changes: 17 additions & 5 deletions grs/fetch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,10 @@ def moving_average(self, date):
return self.__calculate_moving_average(date, 6)

def MA(self, *args, **kwargs):
""" alias :func:`grs.fetch_data.SimpleAnalytics.moving_average()` """
""" alias :func:`grs.fetch_data.SimpleAnalytics.moving_average()`
.. versionadded:: 0.5.4
"""
return self.moving_average(*args, **kwargs)

def moving_average_value(self, date):
Expand All @@ -342,7 +345,10 @@ def moving_average_value(self, date):
return list(val), conti

def MAV(self, *args, **kwargs):
""" alias :func:`grs.fetch_data.SimpleAnalytics.moving_average_value()` """
""" alias :func:`grs.fetch_data.SimpleAnalytics.moving_average_value()`
.. versionadded:: 0.5.4
"""
return self.moving_average_value(*args, **kwargs)

def moving_average_bias_ratio(self, date1, date2):
Expand All @@ -363,7 +369,10 @@ def moving_average_bias_ratio(self, date1, date2):
return cal_list, cont

def MAO(self, *args, **kwargs):
""" alias :func:`grs.fetch_data.SimpleAnalytics.moving_average_bias_ratio()` """
""" alias :func:`grs.fetch_data.SimpleAnalytics.moving_average_bias_ratio()`
.. versionadded:: 0.5.4
"""
return self.moving_average_bias_ratio(*args, **kwargs)

@property
Expand All @@ -384,7 +393,7 @@ def openprice(self):

@property
def value(self):
""" 成交量序列
""" 成交量序列(張)
:rtype: list
"""
Expand Down Expand Up @@ -430,7 +439,10 @@ def check_moving_average_bias_ratio(cls, data, sample=5,

@classmethod
def CKMAO(self, *args, **kwargs):
""" alias :func:`grs.fetch_data.SimpleAnalytics.check_moving_average_bias_ratio()` """
""" alias :func:`grs.fetch_data.SimpleAnalytics.check_moving_average_bias_ratio()`
.. versionadded:: 0.5.4
"""
return self.check_moving_average_bias_ratio(*args, **kwargs)


Expand Down
File renamed without changes.
47 changes: 42 additions & 5 deletions grs/twseno.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def importcsv(self):
pass
return result

@staticmethod
def __industry_code():
def __industry_code(self):
''' import industry_code '''
csv_path = os.path.join(os.path.dirname(__file__),
self.industry_code_files)
Expand All @@ -64,8 +63,7 @@ def __industry_code():
result[i[0]] = i[1].decode('utf-8')
return result

@staticmethod
def __loadindcomps():
def __loadindcomps(self):
''' import industry comps '''
csv_path = os.path.join(os.path.dirname(__file__), self.stock_no_files)
with open(csv_path) as csv_file:
Expand Down Expand Up @@ -153,14 +151,53 @@ def industry_comps(self):
"""
return self.__loadindcomps()

def get_stock_comps_list(self):
""" 回傳日常交易的類別代碼與名稱
:rtype: dict
.. versionadded:: 0.5.6
"""
code_list = self.industry_code
stock_comps_list = {}

for i in code_list:
if len(i) == 2 and i.isdigit():
stock_comps_list.update({i: code_list[i]})

return stock_comps_list

def get_stock_list(self):
""" 回傳日常交易的代碼與名稱
:rtype: dict
.. versionadded:: 0.5.6
"""
all_stock = self.all_stock
industry_comps = self.industry_comps
result = {}

for comps_no in self.get_stock_comps_list():
if comps_no in industry_comps:
for stock_no in industry_comps[comps_no]:
result.update({stock_no: all_stock[stock_no]})
return result

class TWSENo(ImportCSV):
""" 上市股票代碼與搜尋 """
def __init__(self):
super(TWSENo, self).__init__('stock_no.csv', 'industry_code.csv')
super(TWSENo, self).__init__('twse_list.csv', 'industry_code.csv')


class OTCNo(ImportCSV):
""" 上櫃股票(OTC, Over-the-counter) 代碼與搜尋"""
def __init__(self):
super(OTCNo, self).__init__('otc_list.csv', 'industry_code_otc.csv')


if __name__ == '__main__':
t = TWSENo()
#t = OTCNo()
t_list = t.get_stock_list()
print t_list
34 changes: 26 additions & 8 deletions test_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,12 @@ def test_twse_no():
assert '1701' in result

@staticmethod
def test_otc_no():
otc_no = grs.OTCNo()
assert isinstance(otc_no.all_stock, dict)
result = otc_no.search(u'華')
# 8446 華研
assert '8446' in result
result = otc_no.searchbyno(46)
assert '8446' in result
def test_twse_code_comps():
twseno = grs.TWSENo()
industry_code = twseno.industry_code
industry_comps = twseno.industry_comps
for i in industry_comps:
assert i in industry_code

@staticmethod
def test_twse_open():
Expand All @@ -88,6 +86,7 @@ def test_twse_open():
assert result is False

@staticmethod
@unittest.skip('Known issues.')
def test_realtime():
real_time = grs.RealtimeStock('2618')
assert real_time.real['no'] == '2618'
Expand Down Expand Up @@ -159,5 +158,24 @@ def test_stock_value(self):
assert isinstance(self.data.openprice, list)
assert isinstance(self.data.value, list)

@staticmethod
def test_otc_no():
otc_no = grs.OTCNo()
assert isinstance(otc_no.all_stock, dict)
result = otc_no.search(u'華')
# 8446 華研
assert '8446' in result
result = otc_no.searchbyno(46)
assert '8446' in result

@staticmethod
def test_otc_code_comps():
twseno = grs.OTCNo()
industry_code = twseno.industry_code
industry_comps = twseno.industry_comps
for i in industry_comps:
assert i in industry_code


if __name__ == '__main__':
unittest.main()
Loading

0 comments on commit f2a0134

Please sign in to comment.