Python/라이브러리

파이썬 (python) 라이브러리 - finpie

snowman95 2021. 3. 19. 19:54
728x90
반응형

# finpie 

- 링크/문서 : pypi.org/project/finpie/#A2

- 용도 : 재무/경제 데이터를 다운로드 가능

           MarketWatch, The Motley Fool, Finviz와 Macrotrends 사이트에서 데이터 스크랩할 수 있는 함수 제공

   . Company Fundamental data : 야후 파이낸스, finbiz 및 OBOE 에서 재무 Data 수집

   . Economic data : OECD database에서 수집,

   . news module : 과거의 뉴스 해드라인을 수집 : FT, NYT, WSJ, Barrons, Seeking Alpha, Reuters 에서

   . other : 모든 나스닥 종목의 ticker 와 시세 가져오기 가능 

 

# Required

- 파이썬 버전 : Python3
- 구글크롬 버전 : 85.*.****.*** 이상 버전 필요(Selenium 관련 일부 기능 사용을 위함)
   - 구글 크롬 87 버전을 써야지 수행이 가능한 함수가 존재함.
      Failed to start driver: Message: session not created:

      This version of ChromeDriver only supports Chrome version 87

- Selenium은 방화벽과 함께 Chrome 사용 못할 수 있음.

 

 # Module & Method

Output Data Output Runtime
Company Fundamentals    
fd = Fundamentals( ticker, source, freq )    
<u>Financial statements</u>    
up to 2005 Slow, depends on source
up to 2005 Slow, depends on source
up to 2005 Slow, depends on source
<u>Financial ratios and key metrics</u>    
up to 2005 Slow
Most recent data Fast
<u>Earnings and revenue estimates</u>    
Most recent data Fast
Recent trend Fast
4 quarters Fast
Most recent data Fast
Most recent data Fast
<u>Earnings call transcripts</u>    
up to 2018 Slow
<u>Insider transactions and analyst ratings</u>    
Most recent data Fast
Most recent data Fast
<u>ESG data</u>    
Most recent data Fast
Most recent data Fast
<u>Company profile</u>    
Most recent data Fast
Most recent data Fast
Price data    
Timeseries Fast
Most recent data Fast
Most recent data Fast
Timeseries Very slow
Any date Fast
Economic data    
OECD Data    
oecd = OecdData( country_code, **args )    
<u>Composite leading indicators</u>    
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
<u>Financial indicators</u>    
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
<u>Trade indicators</u>    
Timeseries Not that slow
Timeseries Not that slow
<u>Labour market indicators</u>    
Timeseries Not that slow
<u>Price indices</u>    
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
<u>Business tendency and consumer opinion </u>    
Timeseries Not that slow
Timeseries Not that slow
<u>National accounts </u>    
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
<u>Production and sales </u>    
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
<u>OECD Business Tendency Survey </u>    
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
<u>OECD Balance of Payments </u>    
Current Account    
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Financial account    
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
EIA Data    
eia = EiaData()    
Timeseries Not that slow
<u>Weekly balances</u>    
Timeseries Not that slow
Most recent data Not that slow
<u>Crude oil supply</u>    
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
<u>Refining and Processing</u>    
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
<u>Imports and Exports</u>    
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
<u>Stocks</u>    
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
<u>Consumption and sales</u>    
Timeseries Not that slow
Timeseries Not that slow
Timeseries Not that slow
News data    
news = NewsData( ticker, keyword_string )    
Timeseries Slow
Timeseries Very slow
Timeseries Very slow
Timeseries Very slow
Timeseries Very slow
Timeseries Slow
Timeseries Very slow
Other data    
List of stock tickers Fast
List of stock tickers Slow
Timeseries Not that slow

 

# 주의 (반드시 필독)

 실제 함수명이 문서와 상이한것

fd.earnings_estimates(Ticker)  실제로는 fd.earnings_estimate(Ticker) 로 동작함.

fd.earnings_estimates_trends() → 실제로는 fd.earnings_estimate_trends() 로 동작함

fd.ratios() → 실제로는 fd.ratio() 로 동작함

 

● 구글 87버전이 필요한 함수 (다른버전 안되고 87버전만 가능)

fd.income_statement()

fd.balance_sheet()

fd.cashflow_statement()

fd.ratio()

 

● 특히 fd.ratio() 같은 경우에는

finpie.Fundamentals('AAPL') 이렇게 해야 동작함.

티커 뒤에 다른 파라미터 넣으면 사용불가

 

# Method 설명 및 사용 방법

# 전체 Module 간략 요약

# [Module] Company Fundamentals
import finpie
fd = finpie.Fundamentals(ticker, source, freq)


# [Module] Price data
import finpie.price_data


# [Module] Economic
import finpie.economic_data

### [Sub Module] OECD Data
import finpie.economic_data.oecd_data
oecd = OecdData( country_code, **args )

### [Sub Module] EIA Petroleum Data : 석유 데이터
import finpie.economic_data.eia_data
eia = EiaData()


# [Module] News data
import finpie.NewsData
news = NewsData( ticker, keyword_string )


# Other data
nasdaq_tickers()
global_tickers()
cftc( report_type = 'futures_traders', year = 2000 )

 

# Module 세부 분석

 

● Company Fundamental data

 

# finpie.Fundamentals(ticker, source='macrotrends', freq='A')

Macrotrends는 Selenium 에서 실행되며 웹사이트가 때때로 로드되지 않을 수 있음.

import finpie # or import finpie.fundamental_data

fd = finpie.Fundamentals(ticker, source, freq)
# source : 'yahoo', 'marketwatch', 'macrotrends' (default : 'macrotrends')
# freq : 'A'(annual data) or 'Q'(quarterly data) (default : 'A')
# default key metrics for marketwatch and macrotrends come from Finviz

# Financial statements / ratios (구글 87버전이 필요)

# Financial statements
fd.income_statement()
fd.balance_sheet()
fd.cashflow_statement()

# Financial ratios and key metrics
fd.ratio()

# key_metrics

1. yahoo 에서 가져오기

fd = finpie.Fundamentals('AAPL','yahoo')

fd.key_metrics()
... (생략)
            shares_outstanding         float  %_held_by_insiders  \
date
2021-03-20        1.679000e+10  1.677000e+10              0.0007


fd.key_metrics().iloc[0]

beta_(5y_monthly)                                        1.25
52-week_change                                         1.1031
sandp500_52-week_change                                0.6526
52_week_high                                           145.09
52_week_low                                             53.15
50-day_moving_average                                   128.0
200-day_moving_average                                 123.07
avg_vol_(3_month)                                 110580000.0
avg_vol_(10_day)                                  108930000.0
shares_outstanding                              16790000000.0
float                                           16770000000.0
%_held_by_insiders                                     0.0007
%_held_by_institutions                                 0.5966
shares_short_(feb_25_2021)                        100800000.0
short_ratio_(feb_25_2021)                                0.97
short_%_of_float_(feb_25_2021)                          0.006
short_%_of_shares_outstanding_(feb_25_2021)             0.006
shares_short_(prior_month_jan_28_2021)             91860000.0
forward_annual_dividend_rate                             0.82
forward_annual_dividend_yield                          0.0068
trailing_annual_dividend_rate                            0.81
trailing_annual_dividend_yield                         0.0067
5_year_average_dividend_yield                            1.42
payout_ratio                                           0.2177
dividend_date                                     Feb 10 2021
ex-dividend_date                                  Feb 04 2021
last_split_factor                                         4:1
last_split_date                                   Aug 30 2020
fiscal_year_ends                                  Sep 25 2020
most_recent_quarter_(mrq)                         Dec 25 2020
profit_margin                                          0.2174
operating_margin_(ttm)                                 0.2525
return_on_assets_(ttm)                                 0.1336
return_on_equity_(ttm)                                 0.8209
revenue_(ttm)                                  294140000000.0
revenue_per_share_(ttm)                                 17.13
quarterly_revenue_growth_(yoy)                          0.214
gross_profit_(ttm)                             104960000000.0
ebitda                                          85160000000.0
net_income_avi_to_common_(ttm)                  63930000000.0
diluted_eps_(ttm)                                        3.69
quarterly_earnings_growth_(yoy)                         0.293
total_cash_(mrq)                                76830000000.0
total_cash_per_share_(mrq)                               4.58
total_debt_(mrq)                               112040000000.0
total_debtequity_(mrq)                                 169.19
current_ratio_(mrq)                                      1.16
book_value_per_share_(mrq)                               3.94
operating_cash_flow_(ttm)                       88920000000.0
levered_free_cash_flow_(ttm)                    66890000000.0
ticker                                                   AAPL

fd.revenue_estimates()
                      reference_date  no_of_analysts  avg_estimate  low_estimate  high_estimate  year_ago_sales  sales_growth_(yearest)
date
2021-03-19  Current Qtr. (E6ar 2021)            27.0  7.692000e+10  7.079000e+10   8.319000e+10    5.831000e+10                   0.319
2021-03-19      Next Qtr. (Jun 2021)            25.0  6.883000e+10  6.171000e+10   7.704000e+10    5.969000e+10                   0.153
2021-03-19       Current Year (2021)            35.0  3.334200e+11  3.162700e+11   3.435500e+11    2.745100e+11                   0.215
2021-03-19          Next Year (2022)            34.0  3.477100e+11  2.915600e+11   3.865000e+11    3.334200e+11                   0.043

fd.earnings_estimate()
                      reference_date  no_of_analysts  avg_estimate  low_estimate  high_estimate  year_ago_eps
date
2021-03-19  Current Qtr. (E6ar 2021)            30.0          0.98          0.85           1.09          0.64
2021-03-19      Next Qtr. (Jun 2021)            28.0          0.82          0.70           0.98          0.64
2021-03-19       Current Year (2021)            39.0          4.45          4.10           4.89          3.28
2021-03-19          Next Year (2022)            38.0          4.68          3.64           5.50          4.45


2. Finbiz 에서 가져오기

아래 3개는 모두 다 동일 데이터 들고옴
fd = finpie.Fundamentals('AAPL')
fd = finpie.Fundamentals('AAPL', 'macrotrends')
fd = finpie.Fundamentals('AAPL', 'marketwatch')

stock_datas = fd.key_metrics().iloc[0]
print(stock_datas)

revenue_ttm = stock_datas['sales']
shares_outstanding(ttm) = stock_datas['shs_outstand']
p_s_ratio = stock_datas['p_to_s']
p_e_ratio = stock_datas['p_to_e']


fd.key_metrics().iloc[0]
index                 DJIA S&P500
market_cap        2029880000000.0
income              63930000000.0
sales              294130000000.0
book_to_sh                   3.91
cash_to_sh                   4.54
dividend                     0.82
dividend_%                 0.0068
employees                147000.0
optionable                    Yes
shortable                     Yes
recom                         2.0
p_to_e                      32.44
forward_p_to_e              25.63
peg                          2.21
p_to_s                        6.9
p_to_b                      30.69
p_to_c                      26.42
p_to_fcf                    30.73
quick_ratio                   1.1
current_ratio                 1.2
debt_to_eq                   1.69
lt_debt_to_eq                 1.5
sma20                     -0.0249
eps_(ttm)                     3.7
eps_next_y                   4.68
eps_next_q                   0.98
eps_this_y                  0.102
eps_next_y                 0.0521
eps_next_5y                0.1469
eps_past_5y                 0.073
sales_past_5y               0.033
sales_q_to_q                0.214
eps_q_to_q                  0.346
earnings              Jan 27 AE6C
sma50                     -0.0739
insider_own                0.0007
insider_trans             -0.0505
inst_own                    0.598
inst_trans                      -
roa                         0.194
roe                         0.906
roi                         0.317
gross_margin                0.388
oper_margin                 0.252
profit_margin               0.217
payout                      0.216
sma200                     0.0362
shs_outstand        16940000000.0
shs_float           16780000000.0
short_float                 0.006
short_ratio                  0.91
target_price               151.75
52w_range          53.15 - 145.09
52w_high                   -0.173
52w_low                    1.2575
rsi_(14)                    41.49
rel_volume                   1.67
avg_volume            110690000.0
volume                184768356.0
perf_week                 -0.0086
perf_month                -0.0749
perf_quarter              -0.0612
perf_half_y                0.0875
perf_year                  0.9608
perf_ytd                  -0.0957
beta                         1.23
atr                          3.72
volatility        2.34E-2 3.09E-2
prev_close                 120.53
price                      119.99
change                    -0.0045


analyst들의 평가 (Finviz)
# fd.analyst_ratings()
                action      rating_institution      rating    price_target
date
2021-03-20  Reiterated                 Needham         Buy     $140 → $170
2021-03-20  Reiterated  Monness Crespi & Hardt         Buy     $144 → $170
2021-03-20  Reiterated       Canaccord Genuity         Buy     $150 → $155
2021-03-20  Reiterated                 Wedbush  Outperform     $160 → $175
2021-03-20  Reiterated                   Cowen  Outperform     $133 → $153
2021-03-20  Reiterated          Morgan Stanley  Overweight     $144 → $152
2021-03-20  Reiterated       Canaccord Genuity         Buy     $145 → $150
2021-03-20  Reiterated          Morgan Stanley  Overweight     $136 → $144
2021-03-20  Reiterated                 Wedbush  Outperform     $150 → $160
2021-03-20     Upgrade            Loop Capital  Hold → Buy     $110 → $131
2021-03-20     Resumed       Atlantic Equities  Overweight            $150
2021-03-20  Reiterated               Citigroup         Buy  $112.50 → $125
2021-03-20  Reiterated               Jefferies         Buy  $116.25 → $135
2021-03-20  Reiterated                 Needham         Buy  $112.50 → $140
2021-03-20  Reiterated             Oppenheimer  Outperform     $105 → $125
2021-03-20  Reiterated               JP Morgan  Overweight     $115 → $150
2021-03-20  Reiterated                   Cowen  Outperform     $530 → $133
2021-03-20  Reiterated  Monness Crespi & Hardt         Buy  $117.50 → $144
2021-03-20  Reiterated                 Wedbush  Outperform     $515 → $600
2021-03-20  Reiterated                   Cowen  Outperform     $470 → $530

 

 

● Price Data

finpie.price_data.historical_prices(Ticker)
                  open        high         low       close   adj_close       volume
date
1980-12-12    0.128348    0.128906    0.128348    0.128348    0.100922  469033600.0
1980-12-15    0.122210    0.122210    0.121652    0.121652    0.095657  175884800.0
1980-12-16    0.113281    0.113281    0.112723    0.112723    0.088636  105728000.0
1980-12-17    0.115513    0.116071    0.115513    0.115513    0.090830   86441600.0
1980-12-18    0.118862    0.119420    0.118862    0.118862    0.093463   73449600.0
...                ...         ...         ...         ...         ...          ...
2021-03-15  121.410004  124.000000  120.419998  123.989998  123.989998   92403800.0
2021-03-16  125.699997  127.220001  124.720001  125.570000  125.570000  114740000.0
2021-03-17  124.050003  125.860001  122.339996  124.760002  124.760002  111437500.0
2021-03-18  122.879997  123.180000  120.320000  120.529999  120.529999  121229700.0
2021-03-19  119.900002  121.430000  119.675003  120.214996  120.214996   50705960.0

 

반응형