Skip to main content

The service of NeuroStats website

Project description

neurostats_API

檔案架構

├── neurostats_API
│   ├── __init__.py
│   ├── cli.py
│   ├── main.py
│   ├── fetchers
│   │   ├── __init__.py
│   │   ├── base.py
│   │   ├── finance_overview.py
│   │   ├── tech.py
│   │   └── value_invest.py
│   ├── tools
│   │   ├── finance_overview_dict.yaml
│   │   ├── profit_lose.yaml
│   │   └── seasonal_data_field_dict.txt
│   └── utils
│       ├──__init__.py
│       ├── data_process.py
│       ├── datetime.py
│       ├── db_client.py
│       └── fetcher.py
├──  test
│    ├── __init__.py
│    └── test_fetchers.py
├── Makefile
├── MANIFEST.in
├── README.md
├── requirement.txt
├── setup.py

  • neurostats_API: 主要的package運行內容
    • fetchers: 回傳service內容的fetcher檔案夾
      • base.py: 基本架構
      • value_invest.py: iFa.ai -> 價值投資
      • finance_overview.py: iFa.ai -> 財務分析 -> 重要指標
      • tech.py: iFa.ai -> 技術指標
    • tools: 存放各種設定檔與資料庫index對應領域的dictionary
    • utils:
      • fetcher.py: Service的舊主架構, 月營收, 損益表, 資產負債表, 資產收益表目前在這裡
      • data_process.py: config資料的讀取
      • datetime.py: 時間格式,包括日期,年度,月份,日,季度

下載

pip install neurostats-API

確認下載成功

>>> import neurostats_API
>>> print(neurostats_API.__version__)
0.0.5

得到最新一期的評價資料與歷年評價

from neurostats_API.fetchers import ValueFetcher
ticker = 2330 # 換成tw50內任意ticker
fetcher = ValueFetcher(ticker)
data = stats_fetcher.query_data()

回傳(2330為例)

{
    "ticker": 股票代碼,
    "company_name": 公司中文名稱,
    "daily_data":{
    ## 以下八個是iFa項目
        "P_E": 本益比,
        "P_B": 股價,
        "P_FCF": 股價自由現金流比,
        "P_S": 股價營收比,
        "EV_EBIT: ,
        "EV_EBITDA": ,
        "EV_OPI": ,
        "EV_S"; 
    ## 以上八個是iFa項目
        "close": 收盤價,
    }

    "yearly_data": pd.DataFrame (下表格為範例)
        year    P_E       P_FCF   P_B        P_S     EV_OPI    EV_EBIT   EV_EBITDA       EV_S
    0   107  16.68   29.155555  3.71  11.369868  29.837201  28.798274  187.647704  11.107886
    1   108  26.06   67.269095  5.41  17.025721  50.145736  47.853790  302.526388  17.088863
    2   109  27.98   95.650723  7.69  22.055379  53.346615  51.653834  205.847232  22.481951
    3   110  27.83  149.512474  7.68  22.047422  55.398018  54.221387  257.091893  22.615355
    4   111  13.11   48.562021  4.25  11.524975  24.683850  24.226554   66.953260  12.129333
    5   112  17.17  216.371410  4.59  16.419533  40.017707  37.699267  105.980652  17.127656
    6  過去4季    NaN -24.929987   NaN  4.300817      83.102921   55.788996 -1073.037084  7.436656
}

這裡有Nan是因為本益比與P/B等資料沒有爬到最新的時間

回傳月營收表

from neurostats_API.utils import StatsFetcher
ticker = 2330 # 換成tw50內任意ticker
fetcher = StatsFetcher()
data = stats_fetcher.get_month_revenue_sheet(ticker)

回傳

{
        "_id": 671b776dd834afbfbeb9adb3
        "ticker": 2330
        "company_name":台積電
        "month_revenue":
                   2014         2015  ...           2023           2024
1            51,429,993   87,120,068  ...    200,050,544    215,785,127
2            46,829,051   62,645,075  ...    163,174,097    181,648,270
...                 ...          ...  ...            ...            ...
12           69,510,190   58,347,005  ...    176,299,866           None
grand_total        None  639,978,805  ...  1,536,206,985  2,025,846,521

        "this_month_revenue_over_years":
               2015        2016  ...         2023         2024
revenue  64,514,083  89,702,807  ...  180,430,282  251,872,717
MoM            None        None  ...         None         None
...             ...         ...  ...          ...          ...
YoY_5          None        None  ...         None         None
YoY_10         None        None  ...         None         None


        "grand_total_over_years":
                2015         2016  ...           2023           2024
revenue  639,978,805  685,711,092  ...  1,536,206,985  2,025,846,521
MoM             None         None  ...           None           None
...              ...          ...  ...            ...            ...
YoY_5           None         None  ...           None           None
YoY_10          None         None  ...           None           None


}
  • 'ticker': 股票代碼
  • 'company_name': 公司名稱
  • 'month_revenue': 歷年的月營收以及到今年最新月份累計的月營收表格
  • 'this_month_revenue_over_years': 今年這個月的月營收與歷年同月份的營收比較
  • 'grand_total_over_years': 累計至今年這個月的月營收與歷年的比較

大部分資料(成長率)缺失是因為尚未計算,僅先填上已經有的資料

財務分析: 重要指標

對應https://ifa.ai/tw-stock/2330/finance-overview

from neurostats_API.fetchers import FinanceOverviewFetcher
ticker = "2330"
fetcher = FinanceOverviewFetcher(ticker = "2330")
data = fetcher.query_data()

回傳

型態為Dict:

{
        ticker: str #股票代碼,
        company_name: str #公司名稱,
        seasonal_data: Dict # 回傳資料
}

以下為seasonal_data目前回傳的key的中英對應(中文皆參照iFa.ai)

markdown 複製程式碼

英文 中文
revenue 營業收入
gross_profit 營業毛利
operating_income 營業利益
net_income 淨利
operating_cash_flow 營業活動之現金流
invest_cash_flow 投資活動之淨現金流
financing_cash_flow 籌資活動之淨現金流
revenue_per_share 每股營收
gross_per_share 每股營業毛利
operating_income_per_share 每股營業利益
eps 每股盈餘(EPS)
operating_cash_flow_per_share 每股營業現金流
fcf_per_share 每股自由現金流
debt_to_operating_cash_flow 每股有息負債
equity 每股淨值
roa 資產報酬率
roe 股東權益報酬率
gross_over_asset 營業毛利÷總資產
roce ROCE
gross_profit_margin 營業毛利率
operation_profit_rate 營業利益率
net_income_rate 淨利率
operating_cash_flow_profit_rate 營業現金流利潤率
revenue_YoY 營收年成長率
gross_prof_YoY 營業毛利年成長率
operating_income_YoY 營業利益年成長率
net_income_YoY 淨利年成長率
dso 應收帳款收現天數
account_receive_over_revenue 應收帳款佔營收比率
dio 平均售貨天數
inventories_revenue_ratio 存貨佔營收比率
dpo 應付帳款付現日天數
cash_of_conversion_cycle 現金循環週期
asset_turnover 總資產週轉率
applcation_turnover 不動產、廠房及設備週轉率
current_ratio 流動比率
quick_ratio 速動比率
debt_to_equity_ratio 負債權益比率
net_debt_to_equity_ratio 淨負債權益比率
interest_coverage_ratio 利息保障倍數
debt_to_operating_cash_flow 有息負債÷營業活動現金流
debt_to_free_cash_flow 有息負債÷自由現金流
cash_flow_ratio 現金流量比率
current_assets 流動資產
current_liabilities 流動負債
non_current_assets 非流動資產
non_current_liabilities 非流動負債
total_asset 資產總額
total_liabilities 負債總額
equity 權益

以下數值未在回傳資料中,待資料庫更新

英文 中文
operating_cash_flow_YoY (not in list, inferred) 營業現金流年成長率
fcf_YoY (not in list, inferred) 自由現金流年成長率
operating_cash_flow_per_share_YoY (not in list, inferred) 每股營業現金流年成長率
fcf_per_share_YoY (not in list, inferred) 每股自由現金流年成長率

損益表

from neurostats_API.utils import StatsFetcher
fetcher = StatsFetcher()
ticker = 2330 # 換成tw50內任意ticker
data = fetcher.get_profit_lose(ticker)

回傳

因項目眾多,不列出詳細內容,僅列出目前會回傳的項目

{
        "ticker": "2330"
        "company_name": "台積電"
        # 以下皆為pd.DataFrame
        "profit_lose":  #損益表,
        "grand_total_profit_lose": #今年度累計損益表,
        # 營業收入
        "revenue":
        "grand_total_revenue":
        # 毛利
        "gross_profit":
        "grand_total_gross_profit":
        "gross_profit_percentage":
        "grand_total_gross_profit_percentage"
        # 營利
        "operating_income":
        "grand_total_operating_income":
        "operating_income_percentage":
        "grand_total_operating_income_percentage":
        # 稅前淨利
        "net_income_before_tax":
        "grand_total_net_income_before_tax":
        "net_income_before_tax_percentage":
        "grand_total_net_income_before_tax_percentage":
        # 本期淨利
        "net_income":
        "grand_total_net_income":
        "net_income_percentage":
        "grand_total_income_percentage":
        # EPS
        "EPS":
        "EPS_growth":
        "grand_total_EPS":
        "grand_total_EPS_growth":
}

資產負債表

from neurostats_API.utils import StatsFetcher
fetcher = StatsFetcher()
ticker = 2330 # 換成tw50內任意ticker
stats_fetcher.get_balance_sheet(ticker)

回傳

{
        "ticker": "2330"
        "company_name": "台積電"
        "balance_sheet":
                   2018Q2_value  2018Q2_percentage  ...  2024Q2_value  2024Q2_percentage
流動資產                        NaN                NaN  ...           NaN            NaN
現金及約當現金             632229880.0              30.79  ...  1.799127e+09          30.07
...                         ...                ...  ...           ...  ...                              ...
按攤銷後成本衡量之金融資產非流動           NaN                NaN  ...  8.868079e+07     1.48
其他權益                        NaN                NaN  ...           NaN             NaN

        "total_asset":
              2018Q2_value  2018Q2_percentage  ...  2024Q2_value  2024Q2_percentage
total_asset   2.053413e+09             100.00  ...  5.982364e+09             100.00
total_debt    5.627777e+08              27.41  ...  2.162216e+09              36.14
total_equity  1.490635e+09              72.59  ...  3.820148e+09              63.86

        "current_asset":
               2018Q2_value  2018Q2_percentage  ...  2024Q2_value  2024Q2_percentage
current_asset   959042679.0               46.7  ...  2.591658e+09              43.32

        "non_current_asset":
                   2018Q2_value  2018Q2_percentage  ...  2024Q2_value  2024Q2_percentage
non_current_asset  1.094370e+09               53.3  ...  3.390706e+09              56.68

        "current_debt":
              2018Q2_value  2018Q2_percentage  ...  2024Q2_value  2024Q2_percentage
current_debt  1.094370e+09               53.3  ...  3.390706e+09              56.68

        "non_current_debt":
                  2018Q2_value  2018Q2_percentage  ...  2024Q2_value  2024Q2_percentage
non_current_debt  1.094370e+09               53.3  ...  3.390706e+09              56.68

        "equity":
        2018Q2_value  2018Q2_percentage  ...  2024Q2_value  2024Q2_percentage
equity  1.094370e+09               53.3  ...  3.390706e+09              56.68

}
  • 'ticker': 股票代碼
  • 'company_name': 公司名稱
  • 'balance_sheet': 歷年當季資場負債表"全表"
  • 'total_asset': 歷年當季資產總額
  • 'current_asset': 歷年當季流動資產總額
  • 'non_current_asset': 歷年當季非流動資產
  • 'current_debt': 歷年當季流動負債
  • 'non_current_debt': 歷年當季非流動負債
  • 'equity': 歷年當季權益

現金流量表

from neurostats_API.utils import StatsFetcher
fetcher = StatsFetcher()
ticker = 2330 # 換成tw50內任意ticker
stats_fetcher.get_cash_flow(ticker)

回傳

{
        "ticker":2330
        "company_name":台積電
        "cash_flow":
                    2018Q2_value  2018Q2_percentage  ...  2024Q2_value  \
    營業活動之現金流量間接法            NaN                NaN  ...           NaN
    繼續營業單位稅前淨利淨損   187531229.0           0.645548  ...   572853779.0
    ...                      ...                ...  ...           ...
    存出保證金增加                  NaN                NaN  ...     -122271.0
    收取之股利                    NaN                NaN  ...      895503.0

                    2024Q2_percentage
    營業活動之現金流量間接法                 NaN
    繼續營業單位稅前淨利淨損           0.703769
    ...                           ...
    存出保證金增加                  0.000755
    收取之股利                   -0.005530

            "CASHO":
                    2018Q2_value  2018Q2_percentage  ...  2024Q2_value  \
    營業活動之現金流量間接法            NaN                NaN  ...           NaN
    繼續營業單位稅前淨利淨損   187531229.0           0.645548  ...   572853779.0
    ...                      ...                ...  ...           ...
    退還支付之所得稅       -31709079.0          -0.109154  ...   -89154446.0
    營業活動之淨現金流入流出   290499278.0           1.000000  ...   813979318.0

                    2024Q2_percentage
    營業活動之現金流量間接法                 NaN
    繼續營業單位稅前淨利淨損           0.703769
    ...                           ...
    退還支付之所得稅              -0.109529
    營業活動之淨現金流入流出           1.000000

            "CASHI":
                            2018Q2_value  2018Q2_percentage  ...  2024Q2_value  \
    投資活動之現金流量                        NaN                NaN  ...           NaN
    取得透過其他綜合損益按公允價值衡量之金融資產   -47523622.0           0.355889  ...   -43780180.0
    ...                              ...                ...  ...           ...
    其他投資活動                     -149104.0           0.001117  ...     7956680.0
    投資活動之淨現金流入流出          -133534789.0           1.000000  ...  -357414321.0

                            2024Q2_percentage
    投資活動之現金流量                             NaN
    取得透過其他綜合損益按公允價值衡量之金融資產           0.122491
    ...                                   ...
    其他投資活動                          -0.022262
    投資活動之淨現金流入流出                   1.000000

            "CASHF":
            2018Q2_value  2018Q2_percentage  ...  2024Q2_value  \
    籌資活動之現金流量           NaN                NaN  ...           NaN
    短期借款減少      -33743725.0           0.387977  ...           NaN
    ...                 ...                ...  ...           ...
    存出保證金增加             NaN                NaN  ...     -122271.0
    收取之股利               NaN                NaN  ...      895503.0

            2024Q2_percentage
    籌資活動之現金流量                NaN
    短期借款減少                   NaN
    ...                      ...
    存出保證金增加             0.000755
    收取之股利              -0.005530

}
  • 'ticker': 股票代碼
  • 'company_name': 公司名稱
  • 'cash_flow': 歷年當季現金流量表"全表"
  • 'CASHO': 歷年當季營運活動之現金流量
  • 'CASHI': 歷年當季投資活動之現金流量
  • 'CASHF': 歷年當季籌資活動之現金流量

大部分資料缺失是因為尚未計算,僅先填上已經有的資料

cli 範例輸入

python ./cli.py --ticker 1101

cli 輸出

_id
ObjectId('67219e046104872ef7490cd3')
ticker
'1101'
company_name
'台泥'
yearly_data
   year    P_E      P_FCF   P_B       P_S         EV_OPI     EV_EBIT    EV_EBITDA      EV_S
0   107   9.78  66.346637  1.07  1.963814      16.061211   14.807325    32.858903  3.685025
1   108  10.76  23.532308  1.35  3.296749      21.995948   19.877169    44.395187  5.338454
2   109  10.29 -26.134468  1.32  4.282560      26.353871   23.417022    46.269197  6.908155
3   110  14.08  22.345215  1.50  5.558267      42.034804   32.290621    77.139298  7.973839
4   111  28.04 -63.248928  1.16  4.595606 -136332.740038  149.169022  -756.781156  7.324556
5   112  29.53 -18.313377  1.15  5.301801      98.225453   65.598234   321.991608  8.582981
6  過去4季    NaN -24.929987   NaN  4.300817      83.102921   55.788996 -1073.037084  7.436656
daily_data
{ 'EV_EBIT': 55.78899626851681,
  'EV_EBITDA': -1073.037084015388,
  'EV_OPI': 83.10292101832388,
  'EV_S': 7.436656083243897,
  'P_B': None,
  'P_E': None,
  'P_FCF': -24.92998660989962,
  'P_S': 4.300817175744059,
  'close': 32.150001525878906,
}

這裡有Nan是因為本益比與P/B等資料沒有爬到最新的時間

TODO

  • 將utils/fetcher.py中的功能切分到fetchers資料夾中

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

neurostats_api-0.0.5.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

neurostats_API-0.0.5-py3-none-any.whl (29.6 kB view details)

Uploaded Python 3

File details

Details for the file neurostats_api-0.0.5.tar.gz.

File metadata

  • Download URL: neurostats_api-0.0.5.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for neurostats_api-0.0.5.tar.gz
Algorithm Hash digest
SHA256 7be0d0efce16dfe3164e1cd7e34569812c46b29a1a35c6616722f195adeccfd6
MD5 d1261e80565fc08cc8384a8bf751eff9
BLAKE2b-256 8a843df1cfbecf111817bdd2d7b37169768d4a34fbc34d1854c2c10852c13d94

See more details on using hashes here.

File details

Details for the file neurostats_API-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: neurostats_API-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 29.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for neurostats_API-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e01a6dc6bd361a9b1a67a607504955a98d14e2c7e1689f61e58c0db28261bcc5
MD5 53ab4b3e19df586da1d711711a55c407
BLAKE2b-256 115a8badcb7b4cc5e8bdeb3dfbff1ff5c1395c61b6f7081293e03410f84f3d3e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page