Stock 擷取股票資訊

擷取股票股價(上市 / 上櫃)

class grs.Stock(stock_no, mons=3, twse=False, otc=False)

擷取股票股價

Parameters:
  • stock_no (str) – 股價代碼
  • mons (int) – 擷取近 n 個月的資料
  • twse (bool) – 直接指定 stock_no 為上市股票,否則會進行查表動作
  • otc (bool) – 直接指定 stock_no 為上櫃股票,否則會進行查表動作
Return type:

grs.fetch_data.TWSEFetch or grs.fetch_data.OTCFetch 並且繼承 grs.fetch_data.SimpleAnalytics

class:Stock(TWSEFetch, SimpleAnalytics)
class:Stock(OTCFetch, SimpleAnalytics)

Returns:

stock_no 判斷上市或上櫃股票回傳資料

Raises:

StockNoError – 查無股票代碼

擷取上市股票股價

class grs.fetch_data.TWSEFetch

Bases: grs.fetch_data.FetchData

fetch_data(stock_no, nowdatetime)

Fetch data from twse.com.tw return list. 從 twse.com.tw 下載資料,回傳格式為 csv.reader

  1. 日期
  2. 成交股數
  3. 成交金額
  4. 開盤價
  5. 最高價(續)
  6. 最低價
  7. 收盤價
  8. 漲跌價差
  9. 成交筆數
Parameters:
  • stock_no (str) – 股票代碼
  • nowdatetime (datetime) – 此刻時間
Return type:

list

info

(股票代碼, 股票名稱)

Return type:tuple
Returns:(股票代碼, 股票名稱)
plus_mons(month)

增加 n 個月的資料

Parameters:month (int) – 增加 n 個月的資料
Return type:tuple
serial_fetch(stock_no, month, twse=None)

串接每月資料 舊→新

Parameters:
  • stock_no (str) – 股票代碼
  • month (int) – 擷取 n 個月的資料
  • twse (bool) – 指定是否為上市資料
Return type:

tuple

to_list(csv_file)

串接每日資料 舊→新

Parameters:csv_file (csv) – csv files
Return type:list

擷取上櫃股票股價

class grs.fetch_data.OTCFetch

Bases: grs.fetch_data.FetchData

fetch_data(stock_no, nowdatetime)

Fetch data from gretai.org.tw(OTC) return list. 從 gretai.org.tw 下載資料,回傳格式為 csv.reader

  1. 日期
  2. 成交股數
  3. 成交金額
  4. 開盤價
  5. 最高價(續)
  6. 最低價
  7. 收盤價
  8. 漲跌價差
  9. 成交筆數
Parameters:
  • stock_no (str) – 股票代碼
  • nowdatetime (datetime) – 此刻時間
Return type:

list

info

(股票代碼, 股票名稱)

Return type:tuple
Returns:(股票代碼, 股票名稱)
plus_mons(month)

增加 n 個月的資料

Parameters:month (int) – 增加 n 個月的資料
Return type:tuple
serial_fetch(stock_no, month, twse=None)

串接每月資料 舊→新

Parameters:
  • stock_no (str) – 股票代碼
  • month (int) – 擷取 n 個月的資料
  • twse (bool) – 指定是否為上市資料
Return type:

tuple

to_list(csv_file)

串接每日資料 舊→新

Parameters:csv_file (csv) – csv files
Return type:list

簡單分析工具

class grs.fetch_data.SimpleAnalytics

簡單計算

classmethod CKMAO(*args, **kwargs)

alias grs.fetch_data.SimpleAnalytics.check_moving_average_bias_ratio()

New in version 0.5.4.

MA(*args, **kwargs)

alias grs.fetch_data.SimpleAnalytics.moving_average()

New in version 0.5.4.

MAO(*args, **kwargs)

alias grs.fetch_data.SimpleAnalytics.moving_average_bias_ratio()

New in version 0.5.4.

MAV(*args, **kwargs)

alias grs.fetch_data.SimpleAnalytics.moving_average_value()

New in version 0.5.4.

classmethod check_moving_average_bias_ratio(data, sample=5, positive_or_negative=False)

判斷正負乖離轉折點位置

Parameters:
  • data (list) – 計算資料
  • sample (int) – 計算的區間樣本數量
  • positive_or_negative (bool) – 正乖離 為 True,負乖離 為 False
Return type:

tuple

Returns:

(True or False, 第幾個轉折日, 轉折點值)

get_raw_rows(rows=6)

取出某一價格序列 (舊→新)

預設序列收盤價 (self.__serial_price(6))

Return type:list
Returns:預設序列收盤價 (self.__serial_price(6))
get_raw_rows_name

原始檔案的欄位名稱

  1. 日期
  2. 成交股數
  3. 成交金額
  4. 開盤價
  5. 最高價(續)
  6. 最低價
  7. 收盤價
  8. 漲跌價差
  9. 成交筆數
Return type:list
moving_average(date)

計算 n 日收盤均價與持續天數

Parameters:date (int) – n 日
Return type:tuple (序列 舊→新, 持續天數)
moving_average_bias_ratio(date1, date2)

計算乖離率(均價) date1 - date2

Parameters:
  • data1 (int) – n 日
  • data2 (int) – m 日
Return type:

tuple (序列 舊→新, 持續天數)

moving_average_value(date)

計算 n 日成交股數均量與持續天數

Parameters:date (int) – n 日
Return type:tuple (序列 舊→新, 持續天數)
openprice

開盤價股價序列

Return type:list
out_putfile(fpath)

輸出成 CSV 檔

Parameters:fpath (path) – 檔案輸出位置

Todo

files output using with syntax.

plus_mons(month)

新增擴充月份資料

Parameters:month (int) – 增加 n 個月的資料
price

收盤價股價序列

Return type:list
raw

擷取原始檔案

Return type:list
Returns:data in list
value

成交量序列(張)

Return type:list

擷取工具

class grs.fetch_data.FetchData

Bases: object

fetch_data(*args, **kwargs)

Inherit grs.fetch_data.TWSEFetch.fetch_data() or grs.fetch_data.OTCFetch.fetch_data()

info

(股票代碼, 股票名稱)

Return type:tuple
Returns:(股票代碼, 股票名稱)
plus_mons(month)

增加 n 個月的資料

Parameters:month (int) – 增加 n 個月的資料
Return type:tuple
serial_fetch(stock_no, month, twse=None)

串接每月資料 舊→新

Parameters:
  • stock_no (str) – 股票代碼
  • month (int) – 擷取 n 個月的資料
  • twse (bool) – 指定是否為上市資料
Return type:

tuple

to_list(csv_file)

串接每日資料 舊→新

Parameters:csv_file (csv) – csv files
Return type:list