반응형
snowman95
코딩수련장
snowman95
전체 방문자
오늘
어제
  • 분류 전체보기 (230)
    • 앱테크 (3)
    • 옵시디언 (5)
    • 드라마, 영화 (1)
    • 개발자 이야기 (24)
    • 프로젝트 (10)
      • 프로젝트 방법론 (7)
      • 프로젝트 기록 (2)
      • Github (1)
    • 개발 지식 (0)
      • 디자인 패턴 (0)
    • 프론트엔드 개발 (5)
      • 테크트리 (2)
      • React.js (19)
      • ReactNative (2)
      • Next.js (6)
      • GraphQL (6)
      • 패키지 매니저 (2)
      • 라이브러리 (3)
      • 상태관리 라이브러리 (4)
      • Web 지식 (3)
      • HTML CSS (26)
      • Javascript (16)
      • 도구 (Tool) (3)
      • 성능 최적화 (1)
      • 디자인시스템 (0)
    • Python (53)
      • 모음집 (1)
      • 문법 (12)
      • 라이브러리 (15)
      • 알고리즘 (10)
      • 백준 문제풀이 (9)
      • 코딩테스트 (2)
      • 도구 (Tool) (3)
    • C++ (20)
      • 알고리즘 (6)
      • 삼성SW기출 (6)
      • 삼성 A형 (6)
    • 데이터사이언스 (1)
    • 인프라 (9)
      • 하드웨어 지식 (4)
      • Ansible (2)
      • Database (2)
      • 쉘스크립트 (1)
    • 주식 (0)
    • 취업 준비 (4)
      • 취업 이야기 (0)

블로그 메뉴

  • 홈
  • 태그

공지사항

인기 글

태그

  • 25년도채용시장
  • 백준
  • 전공 요약 #데이터베이스
  • Next.js #graphql #tailwind.css
  • 삼성SDS
  • 알고리즘
  • 오블완
  • 개발자이직회고
  • 삼성SW역량테스트
  • 개발자이직
  • 전공요약
  • 언어
  • C++
  • 개발자취업시장
  • 면접
  • 나의 해방일지
  • A형
  • 티스토리챌린지
  • 기계식키보드 #nuphy
  • 전공 요약 #네트워크

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
snowman95

코딩수련장

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

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

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>    
  • fd.income_statement()
up to 2005 Slow, depends on source
  • fd.balance_sheet()
up to 2005 Slow, depends on source
  • fd.cashflow_statement()
up to 2005 Slow, depends on source
<u>Financial ratios and key metrics</u>    
  • fd.ratio()
up to 2005 Slow
  • fd.key_metrics()
Most recent data Fast
<u>Earnings and revenue estimates</u>    
  • fd.earnings_estimate()
Most recent data Fast
  • fd.earnings_estimates_trends()
Recent trend Fast
  • fd.earnings_history()
4 quarters Fast
  • fd.revenue_estimates()
Most recent data Fast
  • fd.growth_estimates()
Most recent data Fast
<u>Earnings call transcripts</u>    
  • fd.transcripts()
up to 2018 Slow
<u>Insider transactions and analyst ratings</u>    
  • fd.insider_transactions()
Most recent data Fast
  • fd.analyst_ratings()
Most recent data Fast
<u>ESG data</u>    
  • fd.esg_score()
Most recent data Fast
  • fd.corporate_governance_score()
Most recent data Fast
<u>Company profile</u>    
  • fd.profile()
Most recent data Fast
  • fd.executives_info()
Most recent data Fast
Price data    
  • historical_prices(ticker)
Timeseries Fast
  • yahoo_option_chain(ticker)
Most recent data Fast
  • cboe_option_chain(ticker)
Most recent data Fast
  • historical_futures_contracts(date_range)
Timeseries Very slow
  • futures_contracts(date)
Any date Fast
Economic data    
OECD Data    
oecd = OecdData( country_code, **args )    
<u>Composite leading indicators</u>    
  • oecd.cli(subject = 'amplitude)
Timeseries Not that slow
  • oecd.cci()
Timeseries Not that slow
  • oecd.bci()
Timeseries Not that slow
<u>Financial indicators</u>    
  • oecd.monetary_aggregates_m1()
Timeseries Not that slow
  • oecd.monetary_aggregates_m3()
Timeseries Not that slow
  • oecd.interbank_rates()
Timeseries Not that slow
  • oecd.short_term_rates()
Timeseries Not that slow
  • oecd.long_term_rates()
Timeseries Not that slow
  • oecd.all_share_prices( )
Timeseries Not that slow
  • oecd.share_prices_industrials()
Timeseries Not that slow
  • oecd.usd_exchange_rates_spot()
Timeseries Not that slow
  • oecd.usd_exchange_rates_average( )
Timeseries Not that slow
  • oecd.rer_overall()
Timeseries Not that slow
<u>Trade indicators</u>    
  • oecd.exports_value()
Timeseries Not that slow
  • oecd.imports_value( )
Timeseries Not that slow
<u>Labour market indicators</u>    
  • oecd.unemployment_rate( )
Timeseries Not that slow
<u>Price indices</u>    
  • oecd.cpi_total()
Timeseries Not that slow
  • oecd.cpi_city_total( )
Timeseries Not that slow
  • oecd.cpi_non_food_non_energy()
Timeseries Not that slow
  • oecd.cpi_energy( )
Timeseries Not that slow
<u>Business tendency and consumer opinion </u>    
  • oecd.business_tendency_survey( sector )
Timeseries Not that slow
  • oecd.consumer_opinion_survey( measure = ‘national' )
Timeseries Not that slow
<u>National accounts </u>    
  • oecd.gdp_deflator()
Timeseries Not that slow
  • oecd.gdp_total()
Timeseries Not that slow
  • oecd.gdp_final_consumption()
Timeseries Not that slow
  • oecd.gdp_government_consumption()
Timeseries Not that slow
  • oecd.gdp_fixed_capital_formation()
Timeseries Not that slow
  • oecd.gdp_exports()
Timeseries Not that slow
  • oecd.gdp_imports()
Timeseries Not that slow
<u>Production and sales </u>    
  • oecd.total_manufacturing_index()
Timeseries Not that slow
  • oecd.total_industry_production_ex_construction()
Timeseries Not that slow
  • oecd.total_construction()
Timeseries Not that slow
  • oecd.total_retail_trade()
Timeseries Not that slow
  • oecd.passenger_car_registration()
Timeseries Not that slow
  • oecd.construction_permits_issued()
Timeseries Not that slow
<u>OECD Business Tendency Survey </u>    
  • oecd.economic_situation_survey(sector)
Timeseries Not that slow
  • oecd.consumer_confidence_survey()
Timeseries Not that slow
  • oecd.consumer_prices_inflation_survey()
Timeseries Not that slow
<u>OECD Balance of Payments </u>    
Current Account    
  • oecd.current_account(percent_of_gdp = False)
Timeseries Not that slow
  • oecd.goods_balance( xm = ‘balance’ )
Timeseries Not that slow
  • oecd.services_balance( xm = ‘balance’ )
Timeseries Not that slow
Financial account    
  • oecd.financial_account(assets_or_liabs = None)
Timeseries Not that slow
  • oecd.direct_investment(assets_or_liabs = None)
Timeseries Not that slow
  • oecd.portfolio_investment(assets_or_liabs = None)
Timeseries Not that slow
  • oecd.other_investment(assets_or_liabs = None)
Timeseries Not that slow
  • oecd.financial_derivatives()
Timeseries Not that slow
  • oecd.reserve_assets()
Timeseries Not that slow
EIA Data    
eia = EiaData()    
  • eia.eia_petroleum_series()
Timeseries Not that slow
<u>Weekly balances</u>    
  • eia.weekly_balance()
Timeseries Not that slow
  • eia.last_weekly_balance()
Most recent data Not that slow
<u>Crude oil supply</u>    
  • eia.crude_production()
Timeseries Not that slow
  • eia.crude_supply_and_disposition()
Timeseries Not that slow
  • eia.rig_count()
Timeseries Not that slow
  • eia.crude_reserves()
Timeseries Not that slow
<u>Refining and Processing</u>    
  • eia.weekly_refinery_inputs()
Timeseries Not that slow
  • eia.refinery_utilisation()
Timeseries Not that slow
  • eia.refinery_yield()
Timeseries Not that slow
  • eia.crude_acquisition_cost()
Timeseries Not that slow
  • eia.crude_inputs_quality()
Timeseries Not that slow
  • eia.refineries()
Timeseries Not that slow
<u>Imports and Exports</u>    
  • eia.weekly_xm()
Timeseries Not that slow
  • eia.monthly_xm()
Timeseries Not that slow
  • eia.weekly_imports_by_country()
Timeseries Not that slow
  • eia.crude_imports_quality()
Timeseries Not that slow
<u>Stocks</u>    
  • eia.weekly_stocks()
Timeseries Not that slow
  • eia.monthly_product_stocks()
Timeseries Not that slow
  • eia.monthly_refinery_stocks()
Timeseries Not that slow
  • eia.monthly_tank_and_pipeline_stocks()
Timeseries Not that slow
<u>Consumption and sales</u>    
  • eia.weekly_product_supplied()
Timeseries Not that slow
  • eia.monthly_product_supplied()
Timeseries Not that slow
  • eia.product_prices_sales_and_stock()
Timeseries Not that slow
News data    
news = NewsData( ticker, keyword_string )    
  • news.barrons()
Timeseries Slow
  • news.cnbc()
Timeseries Very slow
  • news.ft()
Timeseries Very slow
  • news.nyt()
Timeseries Very slow
  • news.reuters()
Timeseries Very slow
  • news.seeking_alpha()
Timeseries Slow
  • news.wsj()
Timeseries Very slow
Other data    
  • nasdaq_tickers()
List of stock tickers Fast
  • global_tickers()
List of stock tickers Slow
  • cftc()
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

 

반응형
저작자표시 동일조건 (새창열림)

'Python > 라이브러리' 카테고리의 다른 글

파이썬 라이브러리 - datetime  (0) 2021.03.23
파이썬 (python) 라이브러리 - Pandas 판다스  (0) 2021.03.22
파이썬 (python) 라이브러리 - yahoo_fin  (0) 2021.03.18
파이썬(python) 라이브러리 - numpy  (0) 2021.03.17
파이썬 (python) 라이브러리 - openpyxl, xlrd (excel 다루기)  (0) 2021.03.09
    'Python/라이브러리' 카테고리의 다른 글
    • 파이썬 라이브러리 - datetime
    • 파이썬 (python) 라이브러리 - Pandas 판다스
    • 파이썬 (python) 라이브러리 - yahoo_fin
    • 파이썬(python) 라이브러리 - numpy
    snowman95
    snowman95
    (17~19) Unity/Unreal Engine 게임 프로그래머 (20~21) System Administrator ___________ (22~) React 웹 프론트앤드 개발자 __________ 깃헙 : https://github.com/snowman95

    티스토리툴바