HAN's BLOG

파이썬을 이용한 미국주식의 가격, 시세, 종가등을 얻기

Stock’s price

이번 포스트에서 파이썬 (Python) API를 이용해서 미국의 단위주식의 가격을 소개할 예정입니다.

주로 사용하는 API로는 두가지가 있습니다.

  • pandas_datareader API

대표적으로 널리 사용되는 API이입니다. 사용법은 구글위에 다양한 정보가 있으니 참고해주시길 바랍니다.

pip install pandas-datareader

  • yahoo_fin API

제가 자주 이용하는 API 입니다. 공식적이 API가 아니라 안정성이 떨어지지만 직접적으로 야후 파이넨셜 사이트에서 정보를 가져오기 떄문에 알기쉽게 데이터를 크롤링 할 수 있습니다.

pip install yahoo_fin

2가지 전부 평가가 좋은 API입니다. 사용에 따라 두가지를 적절히 이용해주시기 바랍니다.

Code to get stock’s price

import pandas as pd
import pandas_datareader as pdr
import yahoo_fin.stock_info as yfs

from tqdm import tqdm
import datetime
import json

def main(url, index_list, index_name, start, end, run_yfs=False, run_pdr=True):

    ## Configuration directory url
    url_data = url+'data_origin/'

    print('Example Apple inc')
    if run_pdr:
        df_aapl = pdr.DataReader('AAPL', 'yahoo', start_day, today)

    if run_yfs:
        start_day.strftime('%m/%d/%y')
        today.strftime('%m/%d/%y')
        df_aapl = yfs.get_data('AAPL',start_date=start_day, end_date = today)
        df_aapl = df_aapl.reset_index()
        df_aapl = df_aapl.rename(columns={'open':'Open', 'index':'Date', 'high':'High','low':'Low','close':'Close','adjclose':'Adj Close','volume':'Volume','ticker':'Ticker'})
        df_aapl = df_aapl[['Ticker','Date','High','Low','Open','Close','Volume','Adj Close']]
    print(df_aapl)

    df_recent = pd.DataFrame({'Recent_price': []})
    etf_values = {}
    error_symbols = []
    for ticker in tqdm(index_list):
        try:
            if run_pdr:
                df = pdr.DataReader(ticker,'yahoo', start_day, today)
            if run_yfs:
                df = yfs.get_data(ticker,start_date=start_day, end_date = today)
                df = df.reset_index()
                df = df.rename(columns={'open':'Open', 'index':'Date', 'high':'High','low':'Low','close':'Close','adjclose':'Adj Close','volume':'Volume','ticker':'Ticker'})
                df = df[['Ticker','Date','High','Low','Open','Close','Volume','Adj Close']]
            df_recent.loc[ticker, 'Recent_price'] = yfs.get_live_price(ticker)
            etf_values[ticker] = df
        except:
            error_symbols.append(ticker)
            print('Error: ', error_symbols)
            df_recent.loc[ticker, 'Recent_price'] = yfs.get_live_price(ticker)

    if run_pdr:
        combined_value = pd.concat(etf_values)
        combined_value = combined_value.reset_index()
        combined_value= combined_value.rename(columns={'level_0': 'Ticker'})
    if run_yfs:
        combined_value = pd.concat(etf_values)
        combined_value = combined_value.reset_index()
        combined_value = combined_value.drop(['level_0','level_1'], axis=1)

    print(combined_value)
    print(df_recent)

    url_value_data = url_data+'FS_{0}_Value'.format(index_name)
    combined_value.to_json(url_value_data+'.json')
    combined_value.to_csv(url_value_data+'.csv')

    url_recent_value_data = url_data+'FS_{0}_Recent_Value'.format(index_name)
    df_recent.to_json(url_recent_value_data+'.json')
    df_recent.to_csv(url_recent_value_data+'.csv')

if __name__ == '__main__':
    with open('../config/config.json', 'r') as f:
        config = json.load(f)
    root_url = config['root_dir']

    filename= input("Choice of stock's list (dow, sp500, nasdaq, other, selected): ")

    dow_list = yfs.tickers_dow()
    if filename == 'dow':
        dow_list = yfs.tickers_dow()
    elif filename == 'sp500':
        dow_list = yfs.tickers_sp500()
    elif filename == 'nasdaq':
        dow_list = yfs.tickers_nasdaq()
    elif filename == 'other':
        dow_list = yfs.tickers_other()
    elif filename == 'selected':
        url = root_url+'/data_ForTrading/selected_ticker.json'
        temp_pd = pd.read_json(url)
        temp_pd = temp_pd['Ticker']
        dow_list = temp_pd.values.tolist()

    print(dow_list)

    ## Define time of start to end ##
    #td_1y = datetime.timedelta(weeks=52/2)
    start_day = datetime.datetime(2010,1,1)
    today = datetime.datetime.now()
    #start_day = today-td_1y

    print('Price of stcok in {0} for date series and recent price'.format(filename))
    main(url=root_url, index_list = dow_list, index_name=filename, start= start_day, end = today, run_yfs = True, run_pdr=False)

else:
    pass

원하는 인덱스(Index)에 대해 yahoo_fin API를 이용하여 각 주식(Ticker)을 리스트로 부릅니다.

각각의 Ticker에 대해 지정하 날로부터 오늘까지의 종가를 포함한 각 시간열에 대해 가격 정보를 얻어옵니다. 또한, 현재 가격만을 따로 데이터프레임으로 저장합니다. 추후 데이터 해석을 위해 미리 뽑아옵니다. Nasdaq과 other의 인덱스는 꽤 시간이 걸리므로 주의 해 주시길 바랍니다.

Result

위 코드를 진행할 경우 밑과 같은 결과가 나타납니다. yahoo_fin API에 의한 원시 데이터는 대표적으로 다우 인덱스 대해 뽑아봤습니다.

     Ticker       Date        High         Low        Open       Close       Volume   Adj Close
0       AAPL 2009-12-31    7.619643    7.520000    7.611786    7.526072  352410800.0    6.471693
1       AAPL 2010-01-04    7.660714    7.585000    7.622500    7.643214  493729600.0    6.572423
2       AAPL 2010-01-05    7.699643    7.616071    7.664286    7.656428  601904800.0    6.583786
3       AAPL 2010-01-06    7.686786    7.526786    7.656428    7.534643  552160000.0    6.479064
4       AAPL 2010-01-07    7.571429    7.466072    7.562500    7.520714  477131200.0    6.467088
...      ...        ...         ...         ...         ...         ...          ...         ...
84407    WMT 2021-06-21  136.750000  135.350006  135.660004  136.399994    6925000.0  136.399994
84408    WMT 2021-06-22  137.720001  136.229996  136.229996  137.029999    6369000.0  137.029999
84409    WMT 2021-06-23  136.990005  135.929993  136.500000  135.960007    6463500.0  135.960007
84410    WMT 2021-06-24  137.240005  136.100006  136.169998  136.910004    7814700.0  136.910004
84411    WMT 2021-06-25  138.860001  136.919998  137.130005  138.529999    9544400.0  138.529999

[84412 rows x 8 columns]
     Recent_price
AAPL    133.110001
AMGN    242.679993
AXP     169.449997
BA      248.380005
CAT     216.309998
CRM     241.869995
CSCO     53.060001
CVX     107.300003
DIS     178.350006
DOW      63.290001
GS      368.769989
HD      313.630005
HON     218.740005
IBM     146.839996
INTC     55.910000
JNJ     164.210007
JPM     154.050003
KO       54.320000
MCD     232.419998
MMM     194.750000
MRK      77.199997
MSFT    265.019989
NKE     154.350006
PG      134.919998
TRV     151.720001
UNH     404.950012
V       237.320007
VZ       56.380001
WBA      52.160000
WMT     138.529999

Conclusion

이렇게 미국 주식의 시간열에 대한 주식 가격(시세, 종가) 및 현재가를 얻어봤습니다.

만약, 실제로 이 코드를 실행하고 싶으시다면, 폴더 Url을 변경해서 사용해주세요.

이 코드는 구글 위에 다양한 사람들에게 도움을 받았습니다. 대단히 감사합니다.

만약 이 포스트가 만족스럽다면 GithubStar 부탁드립니다 :)

파이썬을 이용한 미국 주식 재무재표 얻기

Stock’s financial statements

주식은 현재 얼마의 가젹으로 살수 있는지는 사실 중요하지 않습니다. 현재가와 발행한 주식수 을 포함한 시가총액(Market Capitalization)이 중요합니다. 이외로 PER, ROA 그리고 현금 흐름등 다양한 주가 정보가 있습니다. 이러한 주식의 정보를 모아서 회사는 재무재표를 발행하고, 감사하게도 야후 파이넨셜을 포함한 주식 정보 사이트에 올려져있습니다.

저는 yahoo_fin API 를 이용해서 간단히 웹상의 재무재표를 얻을 것입니다. 구체적인 사용법은 해당 Documation를 참고해주세요.

  • yahoo_fin API

pip install yahoo_fin

Code to get stock’s financial statements

import yahoo_fin.stock_info as yfs
import pandas as pd

from tqdm import tqdm
import json

def main(url, index_list, index_name):

    ## Configuration directory url
    url_data = url+'data_origin/'

    # For check the table of one ticker like aapl
    aapl_quote = yfs.get_quote_table('aapl')
    aapl_val = yfs.get_stats_valuation('aapl')
    aapl_ext = yfs.get_stats('aapl')
    aapl_sheet = yfs.get_balance_sheet('aapl')
    aapl_income = yfs.get_income_statement('aapl')
    aapl_flow = yfs.get_cash_flow('aapl')

    print('*'*100)
    print('quote')
    print(aapl_quote)
    print('*'*100)
    print('basic')
    print(aapl_val)
    print('*'*100)
    print('additional')
    print(aapl_ext)
    print('*'*100)
    print('balance sheets')
    print(aapl_sheet)
    print(len(aapl_sheet.columns))
    print('*'*100)
    print('income statements')
    print(aapl_income)
    print('*'*100)
    print('cash flow')
    print(aapl_flow)
    print('*'*100)

    # Get data in the current  olumn for each stock's valuation table
    dow_stats = {}
    dow_addstats = {}
    dow_balsheets = {}
    dow_income = {}
    dow_flow = {}

    error_symbols = []
    for ticker in tqdm(index_list):
        try:
            # Getteing Summary
            basic = yfs.get_stats_valuation(ticker)
            basic =basic.iloc[:,:2]
            basic.columns = ['Attribute', 'Recent']
            dow_stats[ticker] = basic

            # Getting additioanl stats
            add = yfs.get_stats(ticker)
            add.columns = ['Attribute', 'Value']
            dow_addstats[ticker] = add

            # Getting balance sheets
            sheets = yfs.get_balance_sheet(ticker)
            dow_balsheets[ticker] = sheets

            # Getting income statements
            income = yfs.get_income_statement(ticker)
            dow_income[ticker] = income

            # Getting cash flow statements
            flow = yfs.get_cash_flow(ticker)
            dow_flow[ticker] = flow

        except:
            error_symbols.append(ticker)
            print('Error ticker: ', ticker)

    print('error symol: ', error_symbols)

    for ticker in dow_balsheets.keys():
        leng = len(dow_balsheets[ticker].columns)
        dow_balsheets[ticker].columns = ['Before_'+str(i) for i in range(0,leng)]
        dow_balsheets[ticker] = dow_balsheets[ticker].rename(columns={'Before_0': 'Recent'})

    for ticker in dow_income.keys():
        leng = len(dow_income[ticker].columns)
        dow_income[ticker].columns = ['Before_'+str(i) for i in range(0,leng)]
        dow_income[ticker] = dow_income[ticker].rename(columns={'Before_0': 'Recent'})

    for ticker in dow_flow.keys():
        leng = len(dow_flow[ticker].columns)
        dow_flow[ticker].columns = ['Before_'+str(i) for i in range(0,leng)]
        dow_flow[ticker] = dow_flow[ticker].rename(columns={'Before_0': 'Recent'})


    combined_stats = pd.concat(dow_stats)
    combined_stats = combined_stats.reset_index()
    combined_stats = combined_stats.rename(columns={'level_0': 'Ticker'})

    combined_addstats = pd.concat(dow_addstats)
    combined_addstats = combined_addstats.reset_index()
    combined_addstats = combined_addstats.rename(columns={'level_0': 'Ticker'})

    combined_balsheets = pd.concat(dow_balsheets)
    combined_balsheets = combined_balsheets.reset_index()
    combined_balsheets = combined_balsheets.rename(columns={'level_0': 'Ticker'})

    combined_income = pd.concat(dow_income)
    combined_income = combined_income.reset_index()
    combined_income = combined_income.rename(columns={'level_0': 'Ticker'})

    combined_flow = pd.concat(dow_flow)
    combined_flow = combined_flow.reset_index()
    combined_flow = combined_flow.rename(columns={'level_0': 'Ticker'})

    del combined_stats['level_1']
    del combined_addstats['level_1']

    print(combined_stats)
    print(combined_addstats)
    print(combined_balsheets)
    print(combined_income)
    print(combined_flow)

    list_stats = ['stats', 'addstats', 'balsheets', 'income', 'flow']
    for s in list_stats:
        url_FS = url_data+'FS_{0}_{1}'.format(index_name, s)
        if s == 'stats':
            df = combined_stats
        elif s == 'addstats':
            df = combined_addstats
        elif s == 'balsheets':
            df = combined_balsheets
        elif s == 'income':
            df = combined_income
        elif s == 'flow':
            df = combined_flow
        df.to_json(url_FS+'.json')
        df.to_csv(url_FS+'.csv')

if __name__ == '__main__':
    with open('../config/config.json', 'r') as f:
        config = json.load(f)
    root_url = config['root_dir']

    filename = input("Choice of stock's list (dow, sp500, nasdaq, other, selected): ")

    # Get list of Dow tickers
    dow_list = yfs.tickers_dow()
    if filename == 'dow':
        dow_list = yfs.tickers_dow()
    elif filename == 'sp500':
        dow_list = yfs.tickers_sp500()
    elif filename == 'nasdaq':
        dow_list = yfs.tickers_nasdaq()
    elif filename == 'other':
        dow_list = yfs.tickers_other()
    elif filename == 'selected':
        url = root_url+'/data_ForTrading/selected_ticker.json'
        temp_pd = pd.read_json(url)
        temp_pd = temp_pd['Ticker']
        dow_list = temp_pd.values.tolist()

    print(dow_list)

    main(url=root_url, index_list = dow_list, index_name = filename)

else:
    pass

먼저, API를 이용하여 대표적인 Ticker (AAPL) 에 대해 원시 데이터를 얻습니다.

그리고, balance sheets, investment sheets, cash flow sheets등 회사마다 측정하는 날짜가 다르므로, 추후의 데이터 해석을 위해 간단히 Recent와 Before_i로 지정해서 변경했습니다.

Result

애플 (AAPL) 의 원시 재무재표는 밑과 같습니다.

****************************************************************************************************
basic
                             0      1
0      Market Cap (intraday) 5  2.34T
1           Enterprise Value 3   2.3T
2                 Trailing P/E  31.46
3                Forward P/E 1  26.16
4  PEG Ratio (5 yr expected) 1   1.45
5            Price/Sales (ttm)   7.18
6             Price/Book (mrq)  33.76
7   Enterprise Value/Revenue 3   7.07
8    Enterprise Value/EBITDA 7  23.05
****************************************************************************************************
additional
                                         Attribute         Value
0                                Beta (5Y Monthly)          1.21
1                                 52-Week Change 3           NaN
2                          S&P500 52-Week Change 3           NaN
3                                   52 Week High 3        145.09
4                                    52 Week Low 3         89.14
5                          50-Day Moving Average 3         128.8
6                         200-Day Moving Average 3        129.16
7                              Avg Vol (3 month) 3        82.31M
8                               Avg Vol (10 day) 3        64.61M
9                             Shares Outstanding 5        16.69B
10                    Implied Shares Outstanding 6           NaN
11                                           Float        16.67B
12                            % Held by Insiders 1         0.07%
13                        % Held by Institutions 1        58.69%
14                   Shares Short (May 27, 2021) 4       123.12M
15                    Short Ratio (May 27, 2021) 4          1.36
16               Short % of Float (May 27, 2021) 4         0.74%
17  Short % of Shares Outstanding (May 27, 2021) 4         0.74%
18       Shares Short (prior month Apr 29, 2021) 4        82.71M
19                  Forward Annual Dividend Rate 4          0.88
20                 Forward Annual Dividend Yield 4         0.66%
21                 Trailing Annual Dividend Rate 3          0.82
22                Trailing Annual Dividend Yield 3         0.60%
23                 5 Year Average Dividend Yield 4          1.34
24                                  Payout Ratio 4        18.34%
25                                 Dividend Date 3  May 12, 2021
26                              Ex-Dividend Date 4  May 06, 2021
27                             Last Split Factor 2           4:1
28                               Last Split Date 3  Aug 30, 2020
29                                Fiscal Year Ends  Sep 25, 2020
30                       Most Recent Quarter (mrq)  Mar 26, 2021
31                                   Profit Margin        23.45%
32                          Operating Margin (ttm)        27.32%
33                          Return on Assets (ttm)        16.90%
34                          Return on Equity (ttm)       103.40%
35                                   Revenue (ttm)       325.41B
36                         Revenue Per Share (ttm)         19.14
37                  Quarterly Revenue Growth (yoy)        53.60%
38                              Gross Profit (ttm)       104.96B
39                                          EBITDA        99.82B
40                  Net Income Avi to Common (ttm)        76.31B
41                               Diluted EPS (ttm)          4.45
42                 Quarterly Earnings Growth (yoy)       110.10%
43                                Total Cash (mrq)        69.83B
44                      Total Cash Per Share (mrq)          4.18
45                                Total Debt (mrq)       134.74B
46                         Total Debt/Equity (mrq)        194.78
47                             Current Ratio (mrq)          1.14
48                      Book Value Per Share (mrq)          4.15
49                       Operating Cash Flow (ttm)        99.59B
50                    Levered Free Cash Flow (ttm)        80.12B
****************************************************************************************************
balance sheets
endDate                    2020-09-26    2019-09-28    2018-09-29    2017-09-30
Breakdown
totalLiab                258549000000  248028000000  258578000000  241272000000
totalStockholderEquity    65339000000   90488000000  107147000000  134047000000
otherCurrentLiab          47867000000   43242000000   39293000000   38099000000
totalAssets              323888000000  338516000000  365725000000  375319000000
commonStock               50779000000   45174000000   40201000000   35867000000
otherCurrentAssets        11264000000   12352000000   12087000000   13936000000
retainedEarnings          14966000000   45898000000   70400000000   98330000000
otherLiab                 46108000000   50503000000   48914000000   43251000000
treasuryStock              -406000000    -584000000   -3454000000    -150000000
otherAssets               33952000000   32978000000   22283000000   18177000000
cash                      38016000000   48844000000   25913000000   20289000000
totalCurrentLiabilities  105392000000  105718000000  115929000000  100814000000
shortLongTermDebt          8773000000   10260000000    8784000000    6496000000
otherStockholderEquity     -406000000    -584000000   -3454000000    -150000000
propertyPlantEquipment    45336000000   37378000000   41304000000   33783000000
totalCurrentAssets       143713000000  162819000000  131339000000  128645000000
longTermInvestments      100887000000  105341000000  170799000000  194714000000
netTangibleAssets         65339000000   90488000000  107147000000  134047000000
shortTermInvestments      52927000000   51713000000   40388000000   53892000000
netReceivables            37445000000   45804000000   48995000000   35673000000
longTermDebt              98667000000   91807000000   93735000000   97207000000
inventory                  4061000000    4106000000    3956000000    4855000000
accountsPayable           42296000000   46236000000   55888000000   44242000000
****************************************************************************************************
income statements
endDate                              2020-09-26    2019-09-28    2018-09-29    2017-09-30
Breakdown
researchDevelopment                 18752000000   16217000000   14236000000   11581000000
effectOfAccountingCharges                  None          None          None          None
incomeBeforeTax                     67091000000   65737000000   72903000000   64089000000
minorityInterest                           None          None          None          None
netIncome                           57411000000   55256000000   59531000000   48351000000
sellingGeneralAdministrative        19916000000   18245000000   16705000000   15261000000
grossProfit                        104956000000   98392000000  101839000000   88186000000
ebit                                66288000000   63930000000   70898000000   61344000000
operatingIncome                     66288000000   63930000000   70898000000   61344000000
otherOperatingExpenses                     None          None          None          None
interestExpense                     -2873000000   -3576000000   -3240000000   -2323000000
extraordinaryItems                         None          None          None          None
nonRecurring                               None          None          None          None
otherItems                                 None          None          None          None
incomeTaxExpense                     9680000000   10481000000   13372000000   15738000000
totalRevenue                       274515000000  260174000000  265595000000  229234000000
totalOperatingExpenses             208227000000  196244000000  194697000000  167890000000
costOfRevenue                      169559000000  161782000000  163756000000  141048000000
totalOtherIncomeExpenseNet            803000000    1807000000    2005000000    2745000000
discontinuedOperations                     None          None          None          None
netIncomeFromContinuingOps          57411000000   55256000000   59531000000   48351000000
netIncomeApplicableToCommonShares   57411000000   55256000000   59531000000   48351000000
****************************************************************************************************
cash flow
endDate                                 2020-09-26   2019-09-28   2018-09-29   2017-09-30
Breakdown
investments                             5335000000  58093000000  30845000000 -33542000000
changeToLiabilities                    -1981000000  -2548000000   9172000000   8373000000
totalCashflowsFromInvestingActivities  -4289000000  45896000000  16066000000 -46446000000
netBorrowings                           2499000000  -7819000000    432000000  29014000000
totalCashFromFinancingActivities      -86820000000 -90976000000 -87876000000 -17974000000
changeToOperatingActivities              881000000   -896000000  30016000000  -8480000000
issuanceOfStock                          880000000    781000000    669000000    555000000
netIncome                              57411000000  55256000000  59531000000  48351000000
changeInCash                          -10435000000  24311000000   5624000000   -195000000
repurchaseOfStock                     -75992000000 -69714000000 -75265000000 -34774000000
totalCashFromOperatingActivities       80674000000  69391000000  77434000000  64225000000
depreciation                           11056000000  12547000000  10903000000  10157000000
otherCashflowsFromInvestingActivities   -791000000  -1078000000   -745000000   -124000000
dividendsPaid                         -14081000000 -14119000000 -13712000000 -12769000000
changeToInventory                       -127000000   -289000000    828000000  -2723000000
changeToAccountReceivables              6917000000    245000000  -5322000000  -2093000000
otherCashflowsFromFinancingActivities   -126000000   -105000000   -105000000   -105000000
changeToNetincome                       6517000000   5076000000 -27694000000  10640000000
capitalExpenditures                    -7309000000 -10495000000 -13313000000 -12451000000
****************************************************************************************************

또한, 데이터 해석을 위해 각 인덱스의 대해 하나의 데이터 프레임화 시켜 저장했습니다.

하나의 예로서 다우 인덱스에 속하는 Ticker를 측정했습니다.

   Ticker                    Attribute Recent
0     AAPL      Market Cap (intraday) 5  2.34T
1     AAPL           Enterprise Value 3   2.3T
2     AAPL                 Trailing P/E  31.46
3     AAPL                Forward P/E 1  26.16
4     AAPL  PEG Ratio (5 yr expected) 1   1.45
..     ...                          ...    ...
265    WMT  PEG Ratio (5 yr expected) 1   3.26
266    WMT            Price/Sales (ttm)   0.70
267    WMT             Price/Book (mrq)   5.02
268    WMT   Enterprise Value/Revenue 3   0.76
269    WMT    Enterprise Value/EBITDA 7  10.78

[270 rows x 3 columns]
    Ticker                     Attribute   Value
0      AAPL             Beta (5Y Monthly)    1.21
1      AAPL              52-Week Change 3     NaN
2      AAPL       S&P500 52-Week Change 3     NaN
3      AAPL                52 Week High 3  145.09
4      AAPL                 52 Week Low 3   89.14
...     ...                           ...     ...
1525    WMT       Total Debt/Equity (mrq)   74.74
1526    WMT           Current Ratio (mrq)    0.95
1527    WMT    Book Value Per Share (mrq)   27.93
1528    WMT     Operating Cash Flow (ttm)  31.91B
1529    WMT  Levered Free Cash Flow (ttm)  17.24B

[1530 rows x 3 columns]
   Ticker               Breakdown        Recent      Before_1      Before_2      Before_3
0     AAPL               totalLiab  2.585490e+11  2.480280e+11  2.585780e+11  2.412720e+11
1     AAPL  totalStockholderEquity  6.533900e+10  9.048800e+10  1.071470e+11  1.340470e+11
2     AAPL        otherCurrentLiab  4.786700e+10  4.324200e+10  3.929300e+10  3.809900e+10
3     AAPL             totalAssets  3.238880e+11  3.385160e+11  3.657250e+11  3.753190e+11
4     AAPL             commonStock  5.077900e+10  4.517400e+10  4.020100e+10  3.586700e+10
..     ...                     ...           ...           ...           ...           ...
784    WMT       netTangibleAssets  4.704200e+10  3.839600e+10  3.551500e+10  5.962700e+10
785    WMT          netReceivables  6.516000e+09  6.284000e+09  6.283000e+09  5.614000e+09
786    WMT            longTermDebt  4.165000e+10  4.441000e+10  4.394800e+10  3.023100e+10
787    WMT               inventory  4.494900e+10  4.443500e+10  4.426900e+10  4.378300e+10
788    WMT         accountsPayable  4.914100e+10  4.697300e+10  4.706000e+10  4.609200e+10

[789 rows x 6 columns]
   Ticker                          Breakdown        Recent      Before_1      Before_2      Before_3
0     AAPL                researchDevelopment   18752000000   16217000000   14236000000   11581000000
1     AAPL          effectOfAccountingCharges          None          None          None          None
2     AAPL                    incomeBeforeTax   67091000000   65737000000   72903000000   64089000000
3     AAPL                   minorityInterest          None          None          None          None
4     AAPL                          netIncome   57411000000   55256000000   59531000000   48351000000
..     ...                                ...           ...           ...           ...           ...
655    WMT                      costOfRevenue  420315000000  394605000000  385301000000  373396000000
656    WMT         totalOtherIncomeExpenseNet   -6384000000   -1352000000  -10497000000   -5814000000
657    WMT             discontinuedOperations          None          None          None          None
658    WMT         netIncomeFromContinuingOps   13706000000   15201000000    7179000000   10523000000
659    WMT  netIncomeApplicableToCommonShares   13510000000   14881000000    6670000000    9862000000

[660 rows x 6 columns]
   Ticker                              Breakdown        Recent      Before_1      Before_2      Before_3
0     AAPL                            investments  5.335000e+09  5.809300e+10  3.084500e+10 -3.354200e+10
1     AAPL                    changeToLiabilities -1.981000e+09 -2.548000e+09  9.172000e+09  8.373000e+09
2     AAPL  totalCashflowsFromInvestingActivities -4.289000e+09  4.589600e+10  1.606600e+10 -4.644600e+10
3     AAPL                          netBorrowings  2.499000e+09 -7.819000e+09  4.320000e+08  2.901400e+10
4     AAPL       totalCashFromFinancingActivities -8.682000e+10 -9.097600e+10 -8.787600e+10 -1.797400e+10
..     ...                                    ...           ...           ...           ...           ...
539    WMT                      changeToInventory -2.395000e+09 -3.000000e+08 -1.311000e+09 -1.400000e+08
540    WMT             changeToAccountReceivables -1.086000e+09  1.540000e+08 -3.680000e+08 -1.074000e+09
541    WMT  otherCashflowsFromFinancingActivities -1.670000e+09 -1.463000e+09 -1.060000e+09 -4.018000e+09
542    WMT                      changeToNetincome  3.440000e+09 -2.860000e+08  1.011000e+10  4.703000e+09
543    WMT                    capitalExpenditures -1.026400e+10 -1.070500e+10 -1.034400e+10 -1.005100e+10

[544 rows x 6 columns]

Conclusion

이렇게 미국 주식의 시간열에 대한 재무재표를 얻어봤습니다.

만약, 실제로 이 코드를 실행하고 싶으시다면, 폴더 Url을 변경해서 사용해주세요.

이 코드는 구글 위에 다양한 사람들에게 도움을 받았습니다. 대단히 감사합니다.

만약 이 포스트가 만족스럽다면 GithubStar 부탁드립니다 :)

마크다운(Markdown) 사용법

Intro

프로젝트를 하기에 있어서, 기록은 필수적이다.

마크업 언어는(markup language)중 대표적으로 htm,latexl과 markdown이 있으며,

마크다운은 단순 텍스트 에디터에서 손쉽게 작성 및 변경이 가능하다. 필자는 macOS 위에서Typora를 이용했다. 다크모드 지원과 편집이 즉시 반영되는 장점을 가지고있다.

그중 Lightweight 언어인 markdown의 대표적인 문법을 알아볼 생각이다.

간단한 문법을 시작으로 필요에 따라 글의 수정이 있을 예정이다.

  1. 문법

    2.1 헤더(Header), 문석의 제목

    헤더

    헤더

    ### 헤더

    ## 헤더

  2. 리스트

    3.1 orded list

      1. white space

    3.2 unordered list

    *, -, + white space

    3.3 split list

    - list one - item 1
    - list one - item 2
       - sub item 1
       - sub item 2
    - list one - item 3
    ^
    - list two - item A
    - list two - item B
    ^
    - list three - item _i_
    - list three - item _ii_
    
  3. 링크

    4.1 url with hyperlink

    Google

    GIthub

    ​ [Google](https://google.com)

    ​ [Github](https:github.com/hanseopark)

    ​ (\: = : 를 이용해서 하이퍼링크 회피)

  4. 코드블럭(code blocks)

    def sum (a,b)
    	return a+b
    

    ``` {.python}

    def sum(a,b):

    return a+b

    ```

    • Examaple language
    • no-highlight

    • Bash (bash)

    • c++ (cpp)

    • JSON (json)

    • Python (python)

  5. 이미지 (image)

    ![image name](url)