{ "cells": [ { "cell_type": "markdown", "id": "93db67d4", "metadata": {}, "source": [ "## yahooquery\n", "\n", "

\n", "\n", " \n", "yahooquery is a Python api to the Yahoo! finance site.\n", " \n", "This file resides at /c/cs458/www/lectures/yquery.ipynb" ] }, { "cell_type": "markdown", "id": "dddccf83", "metadata": {}, "source": [ "## Everything you need to know about yahooquery and finance\n", "\n", "The fundamental law of finance is:\n", "\n", "> Buy low, sell high.\n", "\n", "But what do you buy? When they think of finance and investing, most people\n", "think about the Dow Jones Industrial Average, which comprises 30 large cap US stocks, traded on the New York Stock Exchange (NYSE) and the NASDAQ exchange. (A large cap stock has a market capitalization greater than $10 billion.\n", "The market cap is simply the price of a share of stock times the number of shares\n", "outstanding.)\n", "\n", "By owning a share of stock, you become an owner of the company. You have an equity stake in running the company. Major decisions by the company are ratified by a shareholder vote. If you own more than 50% of the stock in a company, you control the company. Stock is also known as equity which is just one asset class\n", "in which you might choose to invest. Others include bonds (aka, fixed income or debt), \n", "real estate, commodities (e.g., wheat, oil, gold), foreign exchance (currency, like dollars, euros, and yen), derivatives (such as mortgage back securities), and infrastructure (such as roads and airports).\n", "\n", "We are going to focus on equity, that is, stocks. The yfinance Python module provides a\n", "boatload of information about US stocks and other securities.\n", "\n" ] }, { "cell_type": "markdown", "id": "2b4aa50a", "metadata": {}, "source": [ "## Risk Management\n", "\n", "As we learned from Tversky and Kahnemann and behavioral economists, people are risk\n", "averse. They don't like losing money. In 1952, Harry Markowitz came up with \n", "Modern Portfolio Theory which, among other things, \n", "showed how you can construct a collection or portfolio of stocks to reduce or even\n", "minimize the risk of the overall investment. One of Markowitz's insights was that \n", "the volatility of a stock's price was a suitable measure of the risk of the investment. You can reduce the overall volatility of a portfolio \n", "by investing stocks that are not correlated with each other. Thus, one stock may\n", "go up with inflation and another might go down. These movements can offset each other\n", "and reduce the portfolio's volatility or risk.\n", "\n", "You can fully diversify your portfolio by holding 30 or so stocks - assuming that they\n", "are not correlated. One hundred years ago, investors thought they were diversified if they owned 20 different railroad stocks. Go figure.\n", "\n", "These days we measure volatility of the entire stock market with the volatility index or VIX. It is also\n", "known as the fear index or fear gauge. The higher the VIX, the riskier the market. A rule of thumb is if the VIX is below 14, the market is not risky.\n", "\n" ] }, { "cell_type": "markdown", "id": "fc239b01", "metadata": {}, "source": [ "## Portfolio Management: Growth and Value\n", "\n", "\n", "We assume that everyone wants to avoid losing money. However, there are many different\n", "ways to make money. Many stocks pay dividends (usually quarterly) which can provide \n", "income to the investor. Usually companies that pay dividends are older and more stable\n", "and established, such as banks and utilities. These stocks are often called value stocks.\n", "\n", "Many stocks do not pay dividends. Instead they reinvest that money in the company to \n", "help it grow and expand. These stocks are often called growth stocks.\n", "\n", "Usually, growth stocks are more volatile than value stocks, which is to say that they are more risky.\n", "\n", "These categories are not always clear cut.\n", "\n", "Another metric that relates to MPT, is beta, a measure of a stock's volatility relative to the market as a whole. A beta of 1 means that the stock has the same volatility \n", "as the entire market (usually the S and P 500). A stable stock will have a beta below 1. A\n", "risky stock will have a beta over 1." ] }, { "cell_type": "markdown", "id": "096203ac", "metadata": {}, "source": [ "## Portfolio Management: Sector\n", "\n", "To diversify the risk in a portfolio, you need to buy stocks with different volatility patterns. One common way to do this is by investing in different sectors or\n", "industries.\n", "\n", "Different sectors respond differently to market conditions. In recent years, technology has outperformed sectors like materials or real estate. However, there is no \n", "clear pattern over time.\n" ] }, { "cell_type": "markdown", "id": "d2639468", "metadata": {}, "source": [ "## Security Analysis\n", "\n", "Many Wall Street firms, like Morgan Stanley, Goldman Sachs, and Merrill Lynch, \n", "employ finance professionals who advise investors which stocks to buy and sell. For \n", "example, see a recent Merrill Lynch report on Apple (AAPL). An analysis will usually assign a recommendation of buy, sell, or hold, as\n", "well as a price target or price objective - their prediction of the price within \n", "the next 12 months. Merrill Lynch assigns Apple a BUY rating and a price objective of 215 from the current price of 172. This is pretty bullish. Note that Merrill Lynch also reports an ESGMeter score of high for Apple. ESG stands for Environmant, Social, and Governance which measures a company's commitment to climate change, diversity and related initiatives. The hope is that a company can do well by doing good.\n", "According to Merrill Lynch, Apple is one of the good guys.\n", "\n", "One focus of a security analyst is to predict future earnings. This figure becomes\n", "part of price/earnings ratio or simply p/e ratio. A low PE suggest that the stock is cheap. A high PE suggests that the stock is expensive. \n", "However, the PE ratio varies considerably across industries.\n", "\n", "Also, there are quantitative models that can value a stock based on future earnings or \n", "discounted cash\n", " flows (DCF). This approach can be used on other assets in addition to stock. A security analyst can project company earnings and then plug those numbers into a DCF model to get a valuation for the company. Using earnings per share, the valuation \n", " is the estimated current price of the company. If that price is higher than the market price, then the stock is a BUY. If the valuation price is lower than the market price, the stock is a SELL.\n", "\n", "In the homework, you are to write some code that could replace a security analyst." ] }, { "cell_type": "markdown", "id": "177c3287", "metadata": {}, "source": [ "## Model Portfolios\n", "\n", "In addition to analyzing companies, Merrill Lynch also provides sample model portfolios, namely:\n", "\n", "- Large Cap Defensive\n", "- Income\n", "- Income and Growth\n", "- Growth\n", "- Mid-Cap\n", "- International\n", "\n", "Each of these portfolios comprise 30 or so individual stocks across a dozen\n", "industrial sectors. The portfolio specifies the weightings of each holding.\n", "Every few weeks or months, Merrill Lynch will publish changes to weightings or\n", "holdings to recalibrate the portfolio. See the \n", "Research Portfolio Holdings and Primer.\n", "\n", "Merrill Lynch publishes a primer which explains the investment philosophy and \n", "process used to construct these portfolios. The basic premise is that \n", "each portfolio has its own risk profile, with Large Cap Defensive being safer\n", "than Income, and so forth.\n", "\n", "As a machine learning exercise, you could use the holdings of these portfolios \n", "as training data to learn the properties of an income stock versus a growth stock." ] }, { "cell_type": "markdown", "id": "d1f42ae2", "metadata": {}, "source": [ "## Let's go to Python already\n", "\n", "\n", "We get started by loading yfinance and some other useful modules. These are available on the zoo. If you do not have them on you personal machine, you can probably install them with\n", "\n", "> pip install\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "434fdce3", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import yahooquery as yq" ] }, { "cell_type": "code", "execution_count": 2, "id": "d648a760", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'2.3.7'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "yq.__version__" ] }, { "cell_type": "markdown", "id": "112f63be", "metadata": {}, "source": [ "The documentation for yahooquery is at https://yahooquery.dpguthrie.com/" ] }, { "cell_type": "code", "execution_count": 3, "id": "f06d5333", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'1.24.4'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import numpy\n", "numpy.version.version" ] }, { "cell_type": "code", "execution_count": 4, "id": "b62866a3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Research',\n", " 'Screener',\n", " 'Ticker',\n", " '__builtins__',\n", " '__cached__',\n", " '__doc__',\n", " '__file__',\n", " '__loader__',\n", " '__name__',\n", " '__package__',\n", " '__path__',\n", " '__spec__',\n", " '__version__',\n", " 'base',\n", " 'get_currencies',\n", " 'get_exchanges',\n", " 'get_market_summary',\n", " 'get_trending',\n", " 'headless',\n", " 'misc',\n", " 'name',\n", " 'research',\n", " 'screener',\n", " 'search',\n", " 'ticker',\n", " 'utils']" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dir(yq)" ] }, { "cell_type": "code", "execution_count": 5, "id": "434f81e1", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Research \t \n", "Screener \t \n", "Ticker \t \n", "base \t \n", "get_currencies \t \n", "get_exchanges \t \n", "get_market_summary \t \n", "get_trending \t \n", "headless \t \n", "misc \t \n", "name \t yahooquery\n", "research \t \n", "screener \t \n", "search \t \n", "ticker \t \n", "utils \t \n" ] } ], "source": [ "for x in dir(yq):\n", " if x.startswith('_'): \n", " next\n", " else:\n", " print (x, '\\t', getattr(yq,x))\n", " " ] }, { "cell_type": "code", "execution_count": 6, "id": "049499f7", "metadata": {}, "outputs": [], "source": [ "from yahooquery import Ticker" ] }, { "cell_type": "code", "execution_count": 7, "id": "b89c2b23", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['CHUNK',\n", " 'CORPORATE_EVENTS',\n", " 'FUNDAMENTALS_OPTIONS',\n", " 'FUNDAMENTALS_TIME_ARGS',\n", " 'INTERVALS',\n", " 'MODULES',\n", " 'PERIODS',\n", " '_CONFIG',\n", " '_FUND_DETAILS',\n", " '_MODULES_DICT',\n", " '_STYLE_BOX',\n", " '_VIZ_CONFIG',\n", " '__class__',\n", " '__delattr__',\n", " '__dict__',\n", " '__dir__',\n", " '__doc__',\n", " '__eq__',\n", " '__format__',\n", " '__ge__',\n", " '__getattribute__',\n", " '__getstate__',\n", " '__gt__',\n", " '__hash__',\n", " '__init__',\n", " '__init_subclass__',\n", " '__le__',\n", " '__lt__',\n", " '__module__',\n", " '__ne__',\n", " '__new__',\n", " '__reduce__',\n", " '__reduce_ex__',\n", " '__repr__',\n", " '__setattr__',\n", " '__sizeof__',\n", " '__str__',\n", " '__subclasshook__',\n", " '__weakref__',\n", " '_adjust_ohlc',\n", " '_async_requests',\n", " '_chunk_symbols',\n", " '_construct_data',\n", " '_construct_params',\n", " '_construct_urls',\n", " '_financials',\n", " '_financials_dataframes',\n", " '_format_data',\n", " '_fund_holdings',\n", " '_get_data',\n", " '_get_symbol',\n", " '_historical_data_to_dataframe',\n", " '_history_1m',\n", " '_option_dataframe',\n", " '_quote_summary',\n", " '_quote_summary_dataframe',\n", " '_sync_requests',\n", " '_to_dataframe',\n", " '_validate_response',\n", " 'all_financial_data',\n", " 'all_modules',\n", " 'asset_profile',\n", " 'balance_sheet',\n", " 'calendar_events',\n", " 'cash_flow',\n", " 'company_officers',\n", " 'corporate_events',\n", " 'corporate_guidance',\n", " 'country',\n", " 'default_query_params',\n", " 'dividend_history',\n", " 'earning_history',\n", " 'earnings',\n", " 'earnings_trend',\n", " 'esg_scores',\n", " 'financial_data',\n", " 'fund_bond_holdings',\n", " 'fund_bond_ratings',\n", " 'fund_category_holdings',\n", " 'fund_equity_holdings',\n", " 'fund_holding_info',\n", " 'fund_ownership',\n", " 'fund_performance',\n", " 'fund_profile',\n", " 'fund_sector_weightings',\n", " 'fund_top_holdings',\n", " 'get_financial_data',\n", " 'get_modules',\n", " 'grading_history',\n", " 'history',\n", " 'income_statement',\n", " 'index_trend',\n", " 'industry_trend',\n", " 'insider_holders',\n", " 'insider_transactions',\n", " 'institution_ownership',\n", " 'key_stats',\n", " 'login',\n", " 'major_holders',\n", " 'news',\n", " 'option_chain',\n", " 'p_all_financial_data',\n", " 'p_balance_sheet',\n", " 'p_cash_flow',\n", " 'p_company_360',\n", " 'p_corporate_events',\n", " 'p_fair_value',\n", " 'p_get_financial_data',\n", " 'p_ideas',\n", " 'p_income_statement',\n", " 'p_portal',\n", " 'p_reports',\n", " 'p_technical_events',\n", " 'p_technical_insights',\n", " 'p_valuation_measures',\n", " 'p_value_analyzer',\n", " 'p_value_analyzer_drilldown',\n", " 'page_views',\n", " 'price',\n", " 'quote_type',\n", " 'quotes',\n", " 'recommendation_trend',\n", " 'recommendations',\n", " 'sec_filings',\n", " 'share_purchase_activity',\n", " 'summary_detail',\n", " 'summary_profile',\n", " 'symbols',\n", " 'technical_insights',\n", " 'validation',\n", " 'valuation_measures']" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dir(Ticker)" ] }, { "cell_type": "code", "execution_count": 8, "id": "5aa28083", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CHUNK \t 1500\n", "CORPORATE_EVENTS \t ['sigdev_corporate_guidance', 'sigdev_performance', 'sigdev_corporate_deals', 'sigdev_expansion_new_markets_new_units', 'sigdev_products', 'sigdev_ownership_control', 'sigdev_financing', 'sigdev_litigation_regulatory', 'sigdev_accounting_issues', 'sigdev_restructuring_reorganization_related', 'sigdev_reference', 'sigdev_special_events', 'sigdev_environment']\n", "FUNDAMENTALS_OPTIONS \t {'income_statement': ['Amortization', 'AmortizationOfIntangiblesIncomeStatement', 'AverageDilutionEarnings', 'BasicAccountingChange', 'BasicAverageShares', 'BasicContinuousOperations', 'BasicDiscontinuousOperations', 'BasicEPS', 'BasicEPSOtherGainsLosses', 'BasicExtraordinary', 'ContinuingAndDiscontinuedBasicEPS', 'ContinuingAndDiscontinuedDilutedEPS', 'CostOfRevenue', 'DepletionIncomeStatement', 'DepreciationAmortizationDepletionIncomeStatement', 'DepreciationAndAmortizationInIncomeStatement', 'DepreciationIncomeStatement', 'DilutedAccountingChange', 'DilutedAverageShares', 'DilutedContinuousOperations', 'DilutedDiscontinuousOperations', 'DilutedEPS', 'DilutedEPSOtherGainsLosses', 'DilutedExtraordinary', 'DilutedNIAvailtoComStockholders', 'DividendPerShare', 'EBIT', 'EBITDA', 'EarningsFromEquityInterest', 'EarningsFromEquityInterestNetOfTax', 'ExciseTaxes', 'GainOnSaleOfBusiness', 'GainOnSaleOfPPE', 'GainOnSaleOfSecurity', 'GeneralAndAdministrativeExpense', 'GrossProfit', 'ImpairmentOfCapitalAssets', 'InsuranceAndClaims', 'InterestExpense', 'InterestExpenseNonOperating', 'InterestIncome', 'InterestIncomeNonOperating', 'MinorityInterests', 'NetIncome', 'NetIncomeCommonStockholders', 'NetIncomeContinuousOperations', 'NetIncomeDiscontinuousOperations', 'NetIncomeExtraordinary', 'NetIncomeFromContinuingAndDiscontinuedOperation', 'NetIncomeFromContinuingOperationNetMinorityInterest', 'NetIncomeFromTaxLossCarryforward', 'NetIncomeIncludingNoncontrollingInterests', 'NetInterestIncome', 'NetNonOperatingInterestIncomeExpense', 'NormalizedBasicEPS', 'NormalizedDilutedEPS', 'NormalizedEBITDA', 'NormalizedIncome', 'OperatingExpense', 'OperatingIncome', 'OperatingRevenue', 'OtherGandA', 'OtherIncomeExpense', 'OtherNonOperatingIncomeExpenses', 'OtherOperatingExpenses', 'OtherSpecialCharges', 'OtherTaxes', 'OtherunderPreferredStockDividend', 'PreferredStockDividends', 'PretaxIncome', 'ProvisionForDoubtfulAccounts', 'ReconciledCostOfRevenue', 'ReconciledDepreciation', 'RentAndLandingFees', 'RentExpenseSupplemental', 'ReportedNormalizedBasicEPS', 'ReportedNormalizedDilutedEPS', 'ResearchAndDevelopment', 'RestructuringAndMergernAcquisition', 'SalariesAndWages', 'SecuritiesAmortization', 'SellingAndMarketingExpense', 'SellingGeneralAndAdministration', 'SpecialIncomeCharges', 'TaxEffectOfUnusualItems', 'TaxLossCarryforwardBasicEPS', 'TaxLossCarryforwardDilutedEPS', 'TaxProvision', 'TaxRateForCalcs', 'TotalExpenses', 'TotalOperatingIncomeAsReported', 'TotalOtherFinanceCost', 'TotalRevenue', 'TotalUnusualItems', 'TotalUnusualItemsExcludingGoodwill', 'WriteOff'], 'balance_sheet': ['AccountsPayable', 'AccountsReceivable', 'AccruedInterestReceivable', 'AccumulatedDepreciation', 'AdditionalPaidInCapital', 'AllowanceForDoubtfulAccountsReceivable', 'AssetsHeldForSaleCurrent', 'AvailableForSaleSecurities', 'BuildingsAndImprovements', 'CapitalLeaseObligations', 'CapitalStock', 'CashAndCashEquivalents', 'CashCashEquivalentsAndShortTermInvestments', 'CashEquivalents', 'CashFinancial', 'CommercialPaper', 'CommonStock', 'CommonStockEquity', 'ConstructionInProgress', 'CurrentAccruedExpenses', 'CurrentAssets', 'CurrentCapitalLeaseObligation', 'CurrentDebt', 'CurrentDebtAndCapitalLeaseObligation', 'CurrentDeferredAssets', 'CurrentDeferredLiabilities', 'CurrentDeferredRevenue', 'CurrentDeferredTaxesAssets', 'CurrentDeferredTaxesLiabilities', 'CurrentLiabilities', 'CurrentNotesPayable', 'CurrentProvisions', 'DefinedPensionBenefit', 'DerivativeProductLiabilities', 'DividendsPayable', 'DuefromRelatedPartiesCurrent', 'DuefromRelatedPartiesNonCurrent', 'DuetoRelatedPartiesCurrent', 'DuetoRelatedPartiesNonCurrent', 'EmployeeBenefits', 'FinancialAssets', 'FinancialAssetsDesignatedasFairValueThroughProfitorLossTotal', 'FinishedGoods', 'FixedAssetsRevaluationReserve', 'ForeignCurrencyTranslationAdjustments', 'GainsLossesNotAffectingRetainedEarnings', 'GeneralPartnershipCapital', 'Goodwill', 'GoodwillAndOtherIntangibleAssets', 'GrossAccountsReceivable', 'GrossPPE', 'HedgingAssetsCurrent', 'HeldToMaturitySecurities', 'IncomeTaxPayable', 'InterestPayable', 'InventoriesAdjustmentsAllowances', 'Inventory', 'InvestedCapital', 'InvestmentProperties', 'InvestmentinFinancialAssets', 'InvestmentsAndAdvances', 'InvestmentsInOtherVenturesUnderEquityMethod', 'InvestmentsinAssociatesatCost', 'InvestmentsinJointVenturesatCost', 'InvestmentsinSubsidiariesatCost', 'LandAndImprovements', 'Leases', 'LiabilitiesHeldforSaleNonCurrent', 'LimitedPartnershipCapital', 'LineOfCredit', 'LoansReceivable', 'LongTermCapitalLeaseObligation', 'LongTermDebt', 'LongTermDebtAndCapitalLeaseObligation', 'LongTermEquityInvestment', 'LongTermProvisions', 'MachineryFurnitureEquipment', 'MinimumPensionLiabilities', 'MinorityInterest', 'NetDebt', 'NetPPE', 'NetTangibleAssets', 'NonCurrentAccountsReceivable', 'NonCurrentAccruedExpenses', 'NonCurrentDeferredAssets', 'NonCurrentDeferredLiabilities', 'NonCurrentDeferredRevenue', 'NonCurrentDeferredTaxesAssets', 'NonCurrentDeferredTaxesLiabilities', 'NonCurrentNoteReceivables', 'NonCurrentPensionAndOtherPostretirementBenefitPlans', 'NonCurrentPrepaidAssets', 'NotesReceivable', 'OrdinarySharesNumber', 'OtherCapitalStock', 'OtherCurrentAssets', 'OtherCurrentBorrowings', 'OtherCurrentLiabilities', 'OtherEquityAdjustments', 'OtherEquityInterest', 'OtherIntangibleAssets', 'OtherInventories', 'OtherInvestments', 'OtherNonCurrentAssets', 'OtherNonCurrentLiabilities', 'OtherPayable', 'OtherProperties', 'OtherReceivables', 'OtherShortTermInvestments', 'Payables', 'PayablesAndAccruedExpenses', 'PensionandOtherPostRetirementBenefitPlansCurrent', 'PreferredSecuritiesOutsideStockEquity', 'PreferredSharesNumber', 'PreferredStock', 'PreferredStockEquity', 'PrepaidAssets', 'Properties', 'RawMaterials', 'Receivables', 'ReceivablesAdjustmentsAllowances', 'RestrictedCash', 'RestrictedCommonStock', 'RetainedEarnings', 'ShareIssued', 'StockholdersEquity', 'TangibleBookValue', 'TaxesReceivable', 'TotalAssets', 'TotalCapitalization', 'TotalDebt', 'TotalEquityGrossMinorityInterest', 'TotalLiabilitiesNetMinorityInterest', 'TotalNonCurrentAssets', 'TotalNonCurrentLiabilitiesNetMinorityInterest', 'TotalPartnershipCapital', 'TotalTaxPayable', 'TradeandOtherPayablesNonCurrent', 'TradingSecurities', 'TreasurySharesNumber', 'TreasuryStock', 'UnrealizedGainLoss', 'WorkInProcess', 'WorkingCapital'], 'cash_flow': ['AdjustedGeographySegmentData', 'AmortizationCashFlow', 'AmortizationOfIntangibles', 'AmortizationOfSecurities', 'AssetImpairmentCharge', 'BeginningCashPosition', 'CapitalExpenditure', 'CapitalExpenditureReported', 'CashDividendsPaid', 'CashFlowFromContinuingFinancingActivities', 'CashFlowFromContinuingInvestingActivities', 'CashFlowFromContinuingOperatingActivities', 'CashFlowFromDiscontinuedOperation', 'CashFlowsfromusedinOperatingActivitiesDirect', 'CashFromDiscontinuedFinancingActivities', 'CashFromDiscontinuedInvestingActivities', 'CashFromDiscontinuedOperatingActivities', 'ChangeInAccountPayable', 'ChangeInAccruedExpense', 'ChangeInCashSupplementalAsReported', 'ChangeInDividendPayable', 'ChangeInIncomeTaxPayable', 'ChangeInInterestPayable', 'ChangeInInventory', 'ChangeInOtherCurrentAssets', 'ChangeInOtherCurrentLiabilities', 'ChangeInOtherWorkingCapital', 'ChangeInPayable', 'ChangeInPayablesAndAccruedExpense', 'ChangeInPrepaidAssets', 'ChangeInReceivables', 'ChangeInTaxPayable', 'ChangeInWorkingCapital', 'ChangesInAccountReceivables', 'ChangesInCash', 'ClassesofCashPayments', 'ClassesofCashReceiptsfromOperatingActivities', 'CommonStockDividendPaid', 'CommonStockIssuance', 'CommonStockPayments', 'DeferredIncomeTax', 'DeferredTax', 'Depletion', 'Depreciation', 'DepreciationAmortizationDepletion', 'DepreciationAndAmortization', 'DividendPaidCFO', 'DividendReceivedCFO', 'DividendsPaidDirect', 'DividendsReceivedCFI', 'DividendsReceivedDirect', 'DomesticSales', 'EarningsLossesFromEquityInvestments', 'EffectOfExchangeRateChanges', 'EndCashPosition', 'ExcessTaxBenefitFromStockBasedCompensation', 'FinancingCashFlow', 'ForeignSales', 'FreeCashFlow', 'GainLossOnInvestmentSecurities', 'GainLossOnSaleOfBusiness', 'GainLossOnSaleOfPPE', 'IncomeTaxPaidSupplementalData', 'InterestPaidCFF', 'InterestPaidCFO', 'InterestPaidDirect', 'InterestPaidSupplementalData', 'InterestReceivedCFI', 'InterestReceivedCFO', 'InterestReceivedDirect', 'InvestingCashFlow', 'IssuanceOfCapitalStock', 'IssuanceOfDebt', 'LongTermDebtIssuance', 'LongTermDebtPayments', 'NetBusinessPurchaseAndSale', 'NetCommonStockIssuance', 'NetForeignCurrencyExchangeGainLoss', 'NetIncome', 'NetIncomeFromContinuingOperations', 'NetIntangiblesPurchaseAndSale', 'NetInvestmentPropertiesPurchaseAndSale', 'NetInvestmentPurchaseAndSale', 'NetIssuancePaymentsOfDebt', 'NetLongTermDebtIssuance', 'NetOtherFinancingCharges', 'NetOtherInvestingChanges', 'NetPPEPurchaseAndSale', 'NetPreferredStockIssuance', 'NetShortTermDebtIssuance', 'OperatingCashFlow', 'OperatingGainsLosses', 'OtherCashAdjustmentInsideChangeinCash', 'OtherCashAdjustmentOutsideChangeinCash', 'OtherCashPaymentsfromOperatingActivities', 'OtherCashReceiptsfromOperatingActivities', 'OtherNonCashItems', 'PaymentsonBehalfofEmployees', 'PaymentstoSuppliersforGoodsandServices', 'PensionAndEmployeeBenefitExpense', 'PreferredStockDividendPaid', 'PreferredStockIssuance', 'PreferredStockPayments', 'ProceedsFromStockOptionExercised', 'ProvisionandWriteOffofAssets', 'PurchaseOfBusiness', 'PurchaseOfIntangibles', 'PurchaseOfInvestment', 'PurchaseOfInvestmentProperties', 'PurchaseOfPPE', 'ReceiptsfromCustomers', 'ReceiptsfromGovernmentGrants', 'RepaymentOfDebt', 'RepurchaseOfCapitalStock', 'SaleOfBusiness', 'SaleOfIntangibles', 'SaleOfInvestment', 'SaleOfInvestmentProperties', 'SaleOfPPE', 'ShortTermDebtIssuance', 'ShortTermDebtPayments', 'StockBasedCompensation', 'TaxesRefundPaid', 'TaxesRefundPaidDirect', 'UnrealizedGainLossOnInvestmentSecurities'], 'valuation': ['ForwardPeRatio', 'PsRatio', 'PbRatio', 'EnterprisesValueEBITDARatio', 'EnterprisesValueRevenueRatio', 'PeRatio', 'MarketCap', 'EnterpriseValue', 'PegRatio']}\n", "FUNDAMENTALS_TIME_ARGS \t {'a': {'prefix': 'annual', 'period_type': '12M'}, 'q': {'prefix': 'quarterly', 'period_type': '3M'}, 'm': {'prefix': 'monthly', 'period_type': '1M'}}\n", "INTERVALS \t ['1m', '2m', '5m', '15m', '30m', '60m', '90m', '1h', '1d', '5d', '1wk', '1mo', '3mo']\n", "MODULES \t ['assetProfile', 'balanceSheetHistory', 'balanceSheetHistoryQuarterly', 'calendarEvents', 'cashflowStatementHistory', 'cashflowStatementHistoryQuarterly', 'defaultKeyStatistics', 'earnings', 'earningsHistory', 'earningsTrend', 'esgScores', 'financialData', 'fundOwnership', 'fundPerformance', 'fundProfile', 'indexTrend', 'incomeStatementHistory', 'incomeStatementHistoryQuarterly', 'industryTrend', 'insiderHolders', 'insiderTransactions', 'institutionOwnership', 'majorHoldersBreakdown', 'pageViews', 'price', 'quoteType', 'recommendationTrend', 'secFilings', 'netSharePurchaseActivity', 'sectorTrend', 'summaryDetail', 'summaryProfile', 'topHoldings', 'upgradeDowngradeHistory']\n", "PERIODS \t ['1d', '5d', '7d', '60d', '1mo', '3mo', '6mo', '1y', '2y', '5y', '10y', 'ytd', 'max']\n", "all_financial_data \t \n", "all_modules \t \n", "asset_profile \t \n", "balance_sheet \t \n", "calendar_events \t \n", "cash_flow \t \n", "company_officers \t \n", "corporate_events \t \n", "corporate_guidance \t \n", "country \t \n", "default_query_params \t \n", "dividend_history \t \n", "earning_history \t \n", "earnings \t \n", "earnings_trend \t \n", "esg_scores \t \n", "financial_data \t \n", "fund_bond_holdings \t \n", "fund_bond_ratings \t \n", "fund_category_holdings \t \n", "fund_equity_holdings \t \n", "fund_holding_info \t \n", "fund_ownership \t \n", "fund_performance \t \n", "fund_profile \t \n", "fund_sector_weightings \t \n", "fund_top_holdings \t \n", "get_financial_data \t \n", "get_modules \t \n", "grading_history \t \n", "history \t \n", "income_statement \t \n", "index_trend \t \n", "industry_trend \t \n", "insider_holders \t \n", "insider_transactions \t \n", "institution_ownership \t \n", "key_stats \t \n", "login \t \n", "major_holders \t \n", "news \t \n", "option_chain \t \n", "p_all_financial_data \t \n", "p_balance_sheet \t \n", "p_cash_flow \t \n", "p_company_360 \t \n", "p_corporate_events \t \n", "p_fair_value \t \n", "p_get_financial_data \t \n", "p_ideas \t \n", "p_income_statement \t \n", "p_portal \t \n", "p_reports \t \n", "p_technical_events \t \n", "p_technical_insights \t \n", "p_valuation_measures \t \n", "p_value_analyzer \t \n", "p_value_analyzer_drilldown \t \n", "page_views \t \n", "price \t \n", "quote_type \t \n", "quotes \t \n", "recommendation_trend \t \n", "recommendations \t \n", "sec_filings \t \n", "share_purchase_activity \t \n", "summary_detail \t \n", "summary_profile \t \n", "symbols \t \n", "technical_insights \t \n", "validation \t \n", "valuation_measures \t \n" ] } ], "source": [ "for x in dir(Ticker):\n", " if x.startswith('_'):\n", " next\n", " else:\n", " print (x, '\\t', getattr(Ticker, x))" ] }, { "cell_type": "code", "execution_count": null, "id": "a41b0149", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "1f8b1310", "metadata": {}, "source": [ "## load appl Ticker" ] }, { "cell_type": "code", "execution_count": 9, "id": "71f4d42b", "metadata": {}, "outputs": [], "source": [ "aapl = Ticker('aapl')" ] }, { "cell_type": "code", "execution_count": 10, "id": "adceaa25", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['CHUNK',\n", " 'CORPORATE_EVENTS',\n", " 'FUNDAMENTALS_OPTIONS',\n", " 'FUNDAMENTALS_TIME_ARGS',\n", " 'INTERVALS',\n", " 'MODULES',\n", " 'PERIODS',\n", " '_CONFIG',\n", " '_FUND_DETAILS',\n", " '_MODULES_DICT',\n", " '_STYLE_BOX',\n", " '_VIZ_CONFIG',\n", " '__class__',\n", " '__delattr__',\n", " '__dict__',\n", " '__dir__',\n", " '__doc__',\n", " '__eq__',\n", " '__format__',\n", " '__ge__',\n", " '__getattribute__',\n", " '__getstate__',\n", " '__gt__',\n", " '__hash__',\n", " '__init__',\n", " '__init_subclass__',\n", " '__le__',\n", " '__lt__',\n", " '__module__',\n", " '__ne__',\n", " '__new__',\n", " '__reduce__',\n", " '__reduce_ex__',\n", " '__repr__',\n", " '__setattr__',\n", " '__sizeof__',\n", " '__str__',\n", " '__subclasshook__',\n", " '__weakref__',\n", " '_adjust_ohlc',\n", " '_async_requests',\n", " '_chunk_symbols',\n", " '_construct_data',\n", " '_construct_params',\n", " '_construct_urls',\n", " '_country',\n", " '_country_params',\n", " '_financials',\n", " '_financials_dataframes',\n", " '_format_data',\n", " '_fund_holdings',\n", " '_get_data',\n", " '_get_symbol',\n", " '_historical_data_to_dataframe',\n", " '_history_1m',\n", " '_option_dataframe',\n", " '_quote_summary',\n", " '_quote_summary_dataframe',\n", " '_setup_url',\n", " '_symbols',\n", " '_sync_requests',\n", " '_to_dataframe',\n", " '_validate_response',\n", " 'all_financial_data',\n", " 'all_modules',\n", " 'asset_profile',\n", " 'balance_sheet',\n", " 'calendar_events',\n", " 'cash_flow',\n", " 'company_officers',\n", " 'corporate_events',\n", " 'corporate_guidance',\n", " 'country',\n", " 'crumb',\n", " 'default_query_params',\n", " 'dividend_history',\n", " 'earning_history',\n", " 'earnings',\n", " 'earnings_trend',\n", " 'esg_scores',\n", " 'financial_data',\n", " 'formatted',\n", " 'fund_bond_holdings',\n", " 'fund_bond_ratings',\n", " 'fund_category_holdings',\n", " 'fund_equity_holdings',\n", " 'fund_holding_info',\n", " 'fund_ownership',\n", " 'fund_performance',\n", " 'fund_profile',\n", " 'fund_sector_weightings',\n", " 'fund_top_holdings',\n", " 'get_financial_data',\n", " 'get_modules',\n", " 'grading_history',\n", " 'history',\n", " 'income_statement',\n", " 'index_trend',\n", " 'industry_trend',\n", " 'insider_holders',\n", " 'insider_transactions',\n", " 'institution_ownership',\n", " 'invalid_symbols',\n", " 'key_stats',\n", " 'login',\n", " 'major_holders',\n", " 'news',\n", " 'option_chain',\n", " 'p_all_financial_data',\n", " 'p_balance_sheet',\n", " 'p_cash_flow',\n", " 'p_company_360',\n", " 'p_corporate_events',\n", " 'p_fair_value',\n", " 'p_get_financial_data',\n", " 'p_ideas',\n", " 'p_income_statement',\n", " 'p_portal',\n", " 'p_reports',\n", " 'p_technical_events',\n", " 'p_technical_insights',\n", " 'p_valuation_measures',\n", " 'p_value_analyzer',\n", " 'p_value_analyzer_drilldown',\n", " 'page_views',\n", " 'password',\n", " 'price',\n", " 'progress',\n", " 'quote_type',\n", " 'quotes',\n", " 'recommendation_trend',\n", " 'recommendations',\n", " 'sec_filings',\n", " 'session',\n", " 'share_purchase_activity',\n", " 'summary_detail',\n", " 'summary_profile',\n", " 'symbols',\n", " 'technical_insights',\n", " 'username',\n", " 'validation',\n", " 'valuation_measures']" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dir(aapl)" ] }, { "cell_type": "code", "execution_count": 15, "id": "b284ee4f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'aapl': {'maxAge': 1,\n", " 'priceHint': 2,\n", " 'previousClose': 191.73,\n", " 'open': 190.94,\n", " 'dayLow': 187.47,\n", " 'dayHigh': 191.8,\n", " 'regularMarketPreviousClose': 191.73,\n", " 'regularMarketOpen': 190.94,\n", " 'regularMarketDayLow': 187.47,\n", " 'regularMarketDayHigh': 191.8,\n", " 'dividendRate': 0.96,\n", " 'dividendYield': 0.005,\n", " 'exDividendDate': '2023-11-09 19:00:00',\n", " 'payoutRatio': 0.1533,\n", " 'fiveYearAvgDividendYield': 0.8,\n", " 'beta': 1.29,\n", " 'trailingPE': 30.630407,\n", " 'forwardPE': 28.409472,\n", " 'volume': 39137973,\n", " 'regularMarketVolume': 39137973,\n", " 'averageVolume': 53818939,\n", " 'averageVolume10days': 56220600,\n", " 'averageDailyVolume10Day': 56220600,\n", " 'bid': 187.81,\n", " 'ask': 187.81,\n", " 'bidSize': 1300,\n", " 'askSize': 1200,\n", " 'marketCap': 2907930361856,\n", " 'fiftyTwoWeekLow': 141.32,\n", " 'fiftyTwoWeekHigh': 199.62,\n", " 'priceToSalesTrailing12Months': 7.586862,\n", " 'fiftyDayAverage': 190.9246,\n", " 'twoHundredDayAverage': 182.0785,\n", " 'trailingAnnualDividendRate': 0.94,\n", " 'trailingAnnualDividendYield': 0.004902728,\n", " 'currency': 'USD',\n", " 'fromCurrency': None,\n", " 'toCurrency': None,\n", " 'lastMarket': None,\n", " 'coinMarketCapLink': None,\n", " 'algorithm': None,\n", " 'tradeable': False}}" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aapl.summary_detail" ] }, { "cell_type": "code", "execution_count": 16, "id": "31b14f27", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'aapl': {'address1': 'One Apple Park Way',\n", " 'city': 'Cupertino',\n", " 'state': 'CA',\n", " 'zip': '95014',\n", " 'country': 'United States',\n", " 'phone': '408 996 1010',\n", " 'website': 'https://www.apple.com',\n", " 'industry': 'Consumer Electronics',\n", " 'industryKey': 'consumer-electronics',\n", " 'industryDisp': 'Consumer Electronics',\n", " 'sector': 'Technology',\n", " 'sectorKey': 'technology',\n", " 'sectorDisp': 'Technology',\n", " 'longBusinessSummary': 'Apple Inc. designs, manufactures, and markets smartphones, personal computers, tablets, wearables, and accessories worldwide. The company offers iPhone, a line of smartphones; Mac, a line of personal computers; iPad, a line of multi-purpose tablets; and wearables, home, and accessories comprising AirPods, Apple TV, Apple Watch, Beats products, and HomePod. It also provides AppleCare support and cloud services; and operates various platforms, including the App Store that allow customers to discover and download applications and digital content, such as books, music, video, games, and podcasts. In addition, the company offers various services, such as Apple Arcade, a game subscription service; Apple Fitness+, a personalized fitness service; Apple Music, which offers users a curated listening experience with on-demand radio stations; Apple News+, a subscription news and magazine service; Apple TV+, which offers exclusive original content; Apple Card, a co-branded credit card; and Apple Pay, a cashless payment service, as well as licenses its intellectual property. The company serves consumers, and small and mid-sized businesses; and the education, enterprise, and government markets. It distributes third-party applications for its products through the App Store. The company also sells its products through its retail and online stores, and direct sales force; and third-party cellular network carriers, wholesalers, retailers, and resellers. Apple Inc. was founded in 1976 and is headquartered in Cupertino, California.',\n", " 'fullTimeEmployees': 161000,\n", " 'companyOfficers': [{'maxAge': 1,\n", " 'name': 'Mr. Timothy D. Cook',\n", " 'age': 62,\n", " 'title': 'CEO & Director',\n", " 'yearBorn': 1961,\n", " 'fiscalYear': 2023,\n", " 'totalPay': 16239562,\n", " 'exercisedValue': 0,\n", " 'unexercisedValue': 0},\n", " {'maxAge': 1,\n", " 'name': 'Mr. Luca Maestri',\n", " 'age': 60,\n", " 'title': 'CFO & Senior VP',\n", " 'yearBorn': 1963,\n", " 'fiscalYear': 2023,\n", " 'totalPay': 4612242,\n", " 'exercisedValue': 0,\n", " 'unexercisedValue': 0},\n", " {'maxAge': 1,\n", " 'name': 'Mr. Jeffrey E. Williams',\n", " 'age': 59,\n", " 'title': 'Chief Operating Officer',\n", " 'yearBorn': 1964,\n", " 'fiscalYear': 2023,\n", " 'totalPay': 4637585,\n", " 'exercisedValue': 0,\n", " 'unexercisedValue': 0},\n", " {'maxAge': 1,\n", " 'name': 'Ms. Katherine L. Adams',\n", " 'age': 59,\n", " 'title': 'Senior VP, General Counsel & Secretary',\n", " 'yearBorn': 1964,\n", " 'fiscalYear': 2023,\n", " 'totalPay': 4618064,\n", " 'exercisedValue': 0,\n", " 'unexercisedValue': 0},\n", " {'maxAge': 1,\n", " 'name': \"Ms. Deirdre O'Brien\",\n", " 'age': 56,\n", " 'title': 'Senior Vice President of Retail',\n", " 'yearBorn': 1967,\n", " 'fiscalYear': 2023,\n", " 'totalPay': 4613369,\n", " 'exercisedValue': 0,\n", " 'unexercisedValue': 0},\n", " {'maxAge': 1,\n", " 'name': 'Mr. Chris Kondo',\n", " 'title': 'Senior Director of Corporate Accounting',\n", " 'fiscalYear': 2023,\n", " 'exercisedValue': 0,\n", " 'unexercisedValue': 0},\n", " {'maxAge': 1,\n", " 'name': 'Mr. James Wilson',\n", " 'title': 'Chief Technology Officer',\n", " 'fiscalYear': 2023,\n", " 'exercisedValue': 0,\n", " 'unexercisedValue': 0},\n", " {'maxAge': 1,\n", " 'name': 'Suhasini Chandramouli',\n", " 'title': 'Director of Investor Relations',\n", " 'fiscalYear': 2023,\n", " 'exercisedValue': 0,\n", " 'unexercisedValue': 0},\n", " {'maxAge': 1,\n", " 'name': 'Mr. Greg Joswiak',\n", " 'title': 'Senior Vice President of Worldwide Marketing',\n", " 'fiscalYear': 2023,\n", " 'exercisedValue': 0,\n", " 'unexercisedValue': 0},\n", " {'maxAge': 1,\n", " 'name': 'Mr. Adrian Perica',\n", " 'age': 49,\n", " 'title': 'Head of Corporate Development',\n", " 'yearBorn': 1974,\n", " 'fiscalYear': 2023,\n", " 'exercisedValue': 0,\n", " 'unexercisedValue': 0}],\n", " 'auditRisk': 4,\n", " 'boardRisk': 1,\n", " 'compensationRisk': 5,\n", " 'shareHolderRightsRisk': 1,\n", " 'overallRisk': 1,\n", " 'governanceEpochDate': '2024-01-27 19:00:00',\n", " 'compensationAsOfEpochDate': '2023-12-30 19:00:00',\n", " 'maxAge': 86400}}" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aapl.asset_profile" ] }, { "cell_type": "code", "execution_count": 17, "id": "73209ab7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'aapl': {'maxAge': 1,\n", " 'earnings': {'earningsDate': ['2024-01-31 05:59:S', '2024-02-05 07:00:S'],\n", " 'earningsAverage': 1.93,\n", " 'earningsLow': 1.86,\n", " 'earningsHigh': 1.99,\n", " 'revenueAverage': 108768000000,\n", " 'revenueLow': 107508000000,\n", " 'revenueHigh': 114394000000},\n", " 'exDividendDate': '2023-11-09 19:00:00',\n", " 'dividendDate': '2023-11-15 19:00:00'}}" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aapl.calendar_events" ] }, { "cell_type": "code", "execution_count": 18, "id": "f73183ee", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'aapl': {'maxAge': 86400,\n", " 'totalEsg': 17.22,\n", " 'environmentScore': 0.46,\n", " 'socialScore': 7.39,\n", " 'governanceScore': 9.37,\n", " 'ratingYear': 2023,\n", " 'ratingMonth': 9,\n", " 'highestControversy': 3.0,\n", " 'peerCount': 55,\n", " 'esgPerformance': 'UNDER_PERF',\n", " 'peerGroup': 'Technology Hardware',\n", " 'relatedControversy': ['Social Supply Chain Incidents',\n", " 'Customer Incidents',\n", " 'Business Ethics Incidents'],\n", " 'peerEsgScorePerformance': {'min': 6.37,\n", " 'avg': 15.565636363636367,\n", " 'max': 27.47},\n", " 'peerGovernancePerformance': {'min': 3.44,\n", " 'avg': 6.928431372549018,\n", " 'max': 11.13},\n", " 'peerSocialPerformance': {'min': 1.75,\n", " 'avg': 5.536862745098038,\n", " 'max': 9.76},\n", " 'peerEnvironmentPerformance': {'min': 0.11,\n", " 'avg': 3.0588235294117636,\n", " 'max': 9.54},\n", " 'peerHighestControversyPerformance': {'min': 0.0,\n", " 'avg': 1.5454545454545454,\n", " 'max': 4.0},\n", " 'percentile': 17.82,\n", " 'environmentPercentile': None,\n", " 'socialPercentile': None,\n", " 'governancePercentile': None,\n", " 'adult': False,\n", " 'alcoholic': False,\n", " 'animalTesting': False,\n", " 'catholic': False,\n", " 'controversialWeapons': False,\n", " 'smallArms': False,\n", " 'furLeather': False,\n", " 'gambling': False,\n", " 'gmo': False,\n", " 'militaryContract': False,\n", " 'nuclear': False,\n", " 'pesticides': False,\n", " 'palmOil': False,\n", " 'coal': False,\n", " 'tobacco': False}}" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aapl.esg_scores" ] }, { "cell_type": "code", "execution_count": 19, "id": "cbca3e17", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'aapl': {'maxAge': 1,\n", " 'priceHint': 2,\n", " 'enterpriseValue': 3044304224256,\n", " 'forwardPE': 28.4358,\n", " 'profitMargins': 0.25305998,\n", " 'floatShares': 15535332918,\n", " 'sharesOutstanding': 15461900288,\n", " 'sharesShort': 101263039,\n", " 'sharesShortPriorMonth': 120233720,\n", " 'sharesShortPreviousMonthDate': '2023-12-14 19:00:00',\n", " 'dateShortInterest': '2024-01-11 19:00:00',\n", " 'sharesPercentSharesOut': 0.0064999997,\n", " 'heldPercentInsiders': 0.00072999997,\n", " 'heldPercentInstitutions': 0.61806,\n", " 'shortRatio': 1.83,\n", " 'shortPercentOfFloat': 0.0066000004,\n", " 'beta': 1.29,\n", " 'impliedSharesOutstanding': 15552799744,\n", " 'category': None,\n", " 'bookValue': 3.997,\n", " 'priceToBook': 47.096573,\n", " 'fundFamily': None,\n", " 'legalType': None,\n", " 'lastFiscalYearEnd': '2023-09-29 20:00:00',\n", " 'nextFiscalYearEnd': '2024-09-29 20:00:00',\n", " 'mostRecentQuarter': '2023-09-29 20:00:00',\n", " 'earningsQuarterlyGrowth': 0.108,\n", " 'netIncomeToCommon': 96995000320,\n", " 'trailingEps': 6.14,\n", " 'forwardEps': 6.62,\n", " 'pegRatio': 5.58,\n", " 'lastSplitFactor': '4:1',\n", " 'lastSplitDate': '2020-08-30 20:00:00',\n", " 'enterpriseToRevenue': 7.943,\n", " 'enterpriseToEbitda': 24.196,\n", " '52WeekChange': 0.32878232,\n", " 'SandP52WeekChange': 0.20883334,\n", " 'lastDividendValue': 0.24,\n", " 'lastDividendDate': 1699574400}}" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aapl.key_stats" ] }, { "cell_type": "code", "execution_count": 20, "id": "01d9e585", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'aapl': {'maxAge': 1,\n", " 'preMarketChangePercent': -0.00412034,\n", " 'preMarketChange': -0.789993,\n", " 'preMarketTime': '2024-01-30 09:29:58',\n", " 'preMarketPrice': 190.94,\n", " 'preMarketSource': 'FREE_REALTIME',\n", " 'regularMarketChangePercent': -0.018359093,\n", " 'regularMarketChange': -3.519989,\n", " 'regularMarketTime': '2024-01-30 15:01:26',\n", " 'priceHint': 2,\n", " 'regularMarketPrice': 188.21,\n", " 'regularMarketDayHigh': 191.8,\n", " 'regularMarketDayLow': 187.47,\n", " 'regularMarketVolume': 39837931,\n", " 'regularMarketPreviousClose': 191.73,\n", " 'regularMarketSource': 'FREE_REALTIME',\n", " 'regularMarketOpen': 190.94,\n", " 'exchange': 'NMS',\n", " 'exchangeName': 'NasdaqGS',\n", " 'exchangeDataDelayedBy': 0,\n", " 'marketState': 'REGULAR',\n", " 'quoteType': 'EQUITY',\n", " 'symbol': 'AAPL',\n", " 'underlyingSymbol': None,\n", " 'shortName': 'Apple Inc.',\n", " 'longName': 'Apple Inc.',\n", " 'currency': 'USD',\n", " 'quoteSourceName': 'Nasdaq Real Time Price',\n", " 'currencySymbol': '$',\n", " 'fromCurrency': None,\n", " 'toCurrency': None,\n", " 'lastMarket': None,\n", " 'marketCap': 2910084399104}}" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aapl.price" ] }, { "cell_type": "markdown", "id": "d08e1b9e", "metadata": {}, "source": [ "The recommendation trend shows the change in analyst calls in the past 3 months." ] }, { "cell_type": "code", "execution_count": 21, "id": "50e728b1", "metadata": {}, "outputs": [ { "data": { "text/html": [ "

\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
periodstrongBuybuyholdsellstrongSell
symbolrow
aapl00m1121600
1-1m10201210
2-2m10211210
3-3m1024710
\n", "
" ], "text/plain": [ " period strongBuy buy hold sell strongSell\n", "symbol row \n", "aapl 0 0m 11 21 6 0 0\n", " 1 -1m 10 20 12 1 0\n", " 2 -2m 10 21 12 1 0\n", " 3 -3m 10 24 7 1 0" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aapl.recommendation_trend" ] }, { "cell_type": "code", "execution_count": 22, "id": "7d2fed8e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idsignificanceheadlinedescriptionparentTopics
symboldate
aapl2014-04-2329724291Apple announces share repurchase and increase ...Apple Inc:Increased its share repurchase autho...Ownership/Control
2014-07-2230341753Apple Inc declares cash dividendApple Inc:Declares a cash dividend of $.47 per...Performance
2014-10-2030887953Apple Inc declares cash dividendApple Inc:Declares cash dividend of $.47 per s...Performance
2015-01-2731426763Apple Inc declares cash dividendApple Inc:Declared cash dividend of $.47 per s...Performance
2015-04-2732007251Apple expands capital return program to $200 b...Apple:AuthorizeS an increase of more than 50 p...Ownership/Control
..................
2022-10-2746134611Apple Inc Reports Q4 Earnings Per Share Of $1.29Oct 27 (Reuters) - Apple Inc <AAPL.O>::QTRLY E...Corporate Guidance
2023-06-3047290981Nokia And Apple Sign Long-Term Patent License ...June 30 (Reuters) - Nokia Oyj <NOKIA.HE>::NOKI...Corporate Deals
2023-06-3047291081Nokia And Apple Sign Long-Term Patent License ...Nokia Oyj <NOKIA.HE>::NOKIA AND APPLE SIGN LON...Corporate Guidance
2023-07-2647383091LG Display expects to turn to profit in Q4July 26 (Reuters) - LG Display Co Ltd <034220....Corporate Guidance
2023-08-1447506251Ford Hires Apple Veteran Peter Stern As Presid...Aug 14 (Reuters) - Ford Motor Co <F.N>::FORD H...Restructuring/Reorganization/Related
\n", "

179 rows × 5 columns

\n", "
" ], "text/plain": [ " id significance \\\n", "symbol date \n", "aapl 2014-04-23 2972429 1 \n", " 2014-07-22 3034175 3 \n", " 2014-10-20 3088795 3 \n", " 2015-01-27 3142676 3 \n", " 2015-04-27 3200725 1 \n", "... ... ... \n", " 2022-10-27 4613461 1 \n", " 2023-06-30 4729098 1 \n", " 2023-06-30 4729108 1 \n", " 2023-07-26 4738309 1 \n", " 2023-08-14 4750625 1 \n", "\n", " headline \\\n", "symbol date \n", "aapl 2014-04-23 Apple announces share repurchase and increase ... \n", " 2014-07-22 Apple Inc declares cash dividend \n", " 2014-10-20 Apple Inc declares cash dividend \n", " 2015-01-27 Apple Inc declares cash dividend \n", " 2015-04-27 Apple expands capital return program to $200 b... \n", "... ... \n", " 2022-10-27 Apple Inc Reports Q4 Earnings Per Share Of $1.29 \n", " 2023-06-30 Nokia And Apple Sign Long-Term Patent License ... \n", " 2023-06-30 Nokia And Apple Sign Long-Term Patent License ... \n", " 2023-07-26 LG Display expects to turn to profit in Q4 \n", " 2023-08-14 Ford Hires Apple Veteran Peter Stern As Presid... \n", "\n", " description \\\n", "symbol date \n", "aapl 2014-04-23 Apple Inc:Increased its share repurchase autho... \n", " 2014-07-22 Apple Inc:Declares a cash dividend of $.47 per... \n", " 2014-10-20 Apple Inc:Declares cash dividend of $.47 per s... \n", " 2015-01-27 Apple Inc:Declared cash dividend of $.47 per s... \n", " 2015-04-27 Apple:AuthorizeS an increase of more than 50 p... \n", "... ... \n", " 2022-10-27 Oct 27 (Reuters) - Apple Inc ::QTRLY E... \n", " 2023-06-30 June 30 (Reuters) - Nokia Oyj ::NOKI... \n", " 2023-06-30 Nokia Oyj ::NOKIA AND APPLE SIGN LON... \n", " 2023-07-26 July 26 (Reuters) - LG Display Co Ltd <034220.... \n", " 2023-08-14 Aug 14 (Reuters) - Ford Motor Co ::FORD H... \n", "\n", " parentTopics \n", "symbol date \n", "aapl 2014-04-23 Ownership/Control \n", " 2014-07-22 Performance \n", " 2014-10-20 Performance \n", " 2015-01-27 Performance \n", " 2015-04-27 Ownership/Control \n", "... ... \n", " 2022-10-27 Corporate Guidance \n", " 2023-06-30 Corporate Deals \n", " 2023-06-30 Corporate Guidance \n", " 2023-07-26 Corporate Guidance \n", " 2023-08-14 Restructuring/Reorganization/Related \n", "\n", "[179 rows x 5 columns]" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aapl.corporate_events" ] }, { "cell_type": "code", "execution_count": null, "id": "0c599bad", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "a36a7f9c", "metadata": {}, "source": [ "### load S and P stock prices for year to date as a data frame" ] }, { "cell_type": "code", "execution_count": 24, "id": "1be99e08", "metadata": {}, "outputs": [], "source": [ "tables = pd.read_html(\"https://en.wikipedia.org/wiki/List_of_S%26P_500_companies\")\n", "sp500 = tables[0]['Symbol'].tolist()\n", "sp500 = [symbol.replace(\".\", \"-\") for symbol in sp500]" ] }, { "cell_type": "code", "execution_count": 26, "id": "0ecc4b7f", "metadata": {}, "outputs": [ { "ename": "TypeError", "evalue": "'Ticker' object is not iterable", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "File \u001b[0;32m:2\u001b[0m\n", "File \u001b[0;32m~/.local/lib/python3.11/site-packages/yahooquery/ticker.py:1293\u001b[0m, in \u001b[0;36mTicker.history\u001b[0;34m(self, period, interval, start, end, adj_timezone, adj_ohlc)\u001b[0m\n\u001b[1;32m 1291\u001b[0m df \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_history_1m(adj_timezone, adj_ohlc)\n\u001b[1;32m 1292\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m-> 1293\u001b[0m data \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_get_data\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mchart\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mparams\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1294\u001b[0m df \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_historical_data_to_dataframe(data, params, adj_timezone)\n\u001b[1;32m 1295\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m adj_ohlc \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124madjclose\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m df:\n", "File \u001b[0;32m~/.local/lib/python3.11/site-packages/yahooquery/base.py:1096\u001b[0m, in \u001b[0;36m_YahooFinance._get_data\u001b[0;34m(self, key, params, **kwargs)\u001b[0m\n\u001b[1;32m 1094\u001b[0m config \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_CONFIG[key]\n\u001b[1;32m 1095\u001b[0m params \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_construct_params(config, params)\n\u001b[0;32m-> 1096\u001b[0m urls \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_construct_urls\u001b[49m\u001b[43m(\u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mparams\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1097\u001b[0m response_field \u001b[38;5;241m=\u001b[39m config[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mresponse_field\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[1;32m 1098\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n", "File \u001b[0;32m~/.local/lib/python3.11/site-packages/yahooquery/base.py:1169\u001b[0m, in \u001b[0;36m_YahooFinance._construct_urls\u001b[0;34m(self, config, params, **kwargs)\u001b[0m\n\u001b[1;32m 1163\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1164\u001b[0m ls \u001b[38;5;241m=\u001b[39m (\n\u001b[1;32m 1165\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_symbols\n\u001b[1;32m 1166\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msession, FuturesSession)\n\u001b[1;32m 1167\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m tqdm(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_symbols, disable\u001b[38;5;241m=\u001b[39m\u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprogress)\n\u001b[1;32m 1168\u001b[0m )\n\u001b[0;32m-> 1169\u001b[0m urls \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 1170\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msession\u001b[38;5;241m.\u001b[39mget(\n\u001b[1;32m 1171\u001b[0m url\u001b[38;5;241m=\u001b[39mconfig[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpath\u001b[39m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;241m.\u001b[39mformat(\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m{\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msymbol\u001b[39m\u001b[38;5;124m\"\u001b[39m: symbol}), params\u001b[38;5;241m=\u001b[39mparams\n\u001b[1;32m 1172\u001b[0m )\n\u001b[1;32m 1173\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m symbol \u001b[38;5;129;01min\u001b[39;00m ls\n\u001b[1;32m 1174\u001b[0m ]\n\u001b[1;32m 1175\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m urls\n", "\u001b[0;31mTypeError\u001b[0m: 'Ticker' object is not iterable" ] } ], "source": [ "%%time\n", "tickers = Ticker(aapl, asynchronous=True)\n", "yq_data = tickers.history(period='ytd', interval='1d')" ] }, { "cell_type": "code", "execution_count": 51, "id": "db607821", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
highlowopenclosevolumeadjclose
formatted_date
2019-11-2667.06250065.62500066.73500166.04000131154800064.338287
2019-12-0367.75000064.07250264.57749966.73000349015440065.010506
2019-12-1070.19750266.46499667.15000269.96499656826120068.162148
2019-12-1771.06250069.63999969.89250271.00000070310600069.170471
2019-12-2473.49250070.73000371.17250172.87999743198040071.002037
\n", "
" ], "text/plain": [ " high low open close volume \\\n", "formatted_date \n", "2019-11-26 67.062500 65.625000 66.735001 66.040001 311548000 \n", "2019-12-03 67.750000 64.072502 64.577499 66.730003 490154400 \n", "2019-12-10 70.197502 66.464996 67.150002 69.964996 568261200 \n", "2019-12-17 71.062500 69.639999 69.892502 71.000000 703106000 \n", "2019-12-24 73.492500 70.730003 71.172501 72.879997 431980400 \n", "\n", " adjclose \n", "formatted_date \n", "2019-11-26 64.338287 \n", "2019-12-03 65.010506 \n", "2019-12-10 68.162148 \n", "2019-12-17 69.170471 \n", "2019-12-24 71.002037 " ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aapl_df.tail()" ] }, { "cell_type": "markdown", "id": "0757b18b", "metadata": {}, "source": [ "### plot Apple stock price for the past 5 years" ] }, { "cell_type": "code", "execution_count": 27, "id": "6151cc6f", "metadata": {}, "outputs": [], "source": [ "import matplotlib" ] }, { "cell_type": "code", "execution_count": 28, "id": "cb830b5c", "metadata": { "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/accts/sbs5/.local/lib/python3.11/site-packages/yahooquery/utils/__init__.py:1470: FutureWarning: 'S' is deprecated and will be removed in a future version. Please use 's' instead of 'S'.\n", " has_live_indice = index_utc[-1] >= last_trade - pd.Timedelta(2, \"S\")\n", "/home/accts/sbs5/.local/lib/python3.11/site-packages/yahooquery/ticker.py:1333: FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method.\n", "The behavior will change in pandas 3.0. This inplace method will never work because the intermediate object on which we are setting values always behaves as a copy.\n", "\n", "For example, when doing 'df[col].method(value, inplace=True)', try using 'df.method({col: value}, inplace=True)' or df[col] = df[col].method(value) instead, to perform the operation inplace on the original object.\n", "\n", "\n", " df[\"dividends\"].fillna(0, inplace=True)\n", "/home/accts/sbs5/.local/lib/python3.11/site-packages/yahooquery/ticker.py:1335: FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method.\n", "The behavior will change in pandas 3.0. This inplace method will never work because the intermediate object on which we are setting values always behaves as a copy.\n", "\n", "For example, when doing 'df[col].method(value, inplace=True)', try using 'df.method({col: value}, inplace=True)' or df[col] = df[col].method(value) instead, to perform the operation inplace on the original object.\n", "\n", "\n", " df[\"splits\"].fillna(0, inplace=True)\n" ] }, { "ename": "KeyError", "evalue": "'Close'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", "File \u001b[0;32m~/.local/lib/python3.11/site-packages/pandas/core/indexes/base.py:3802\u001b[0m, in \u001b[0;36mIndex.get_loc\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 3801\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m-> 3802\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_engine\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_loc\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcasted_key\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3803\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n", "File \u001b[0;32mindex.pyx:153\u001b[0m, in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n", "File \u001b[0;32mindex.pyx:182\u001b[0m, in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n", "File \u001b[0;32mpandas/_libs/hashtable_class_helper.pxi:7081\u001b[0m, in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[0;34m()\u001b[0m\n", "File \u001b[0;32mpandas/_libs/hashtable_class_helper.pxi:7089\u001b[0m, in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[0;34m()\u001b[0m\n", "\u001b[0;31mKeyError\u001b[0m: 'Close'", "\nThe above exception was the direct cause of the following exception:\n", "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[28], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m ticker \u001b[38;5;241m=\u001b[39m Ticker(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mAAPL\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 2\u001b[0m aapl_df \u001b[38;5;241m=\u001b[39m ticker\u001b[38;5;241m.\u001b[39mhistory(period\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m5y\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m----> 3\u001b[0m \u001b[43maapl_df\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mClose\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[38;5;241m.\u001b[39mplot(title\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAPPLE\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124ms stock price\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", "File \u001b[0;32m~/.local/lib/python3.11/site-packages/pandas/core/frame.py:4090\u001b[0m, in \u001b[0;36mDataFrame.__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 4088\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcolumns\u001b[38;5;241m.\u001b[39mnlevels \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m 4089\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_getitem_multilevel(key)\n\u001b[0;32m-> 4090\u001b[0m indexer \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcolumns\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_loc\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 4091\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m is_integer(indexer):\n\u001b[1;32m 4092\u001b[0m indexer \u001b[38;5;241m=\u001b[39m [indexer]\n", "File \u001b[0;32m~/.local/lib/python3.11/site-packages/pandas/core/indexes/base.py:3809\u001b[0m, in \u001b[0;36mIndex.get_loc\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 3804\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(casted_key, \u001b[38;5;28mslice\u001b[39m) \u001b[38;5;129;01mor\u001b[39;00m (\n\u001b[1;32m 3805\u001b[0m \u001b[38;5;28misinstance\u001b[39m(casted_key, abc\u001b[38;5;241m.\u001b[39mIterable)\n\u001b[1;32m 3806\u001b[0m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28many\u001b[39m(\u001b[38;5;28misinstance\u001b[39m(x, \u001b[38;5;28mslice\u001b[39m) \u001b[38;5;28;01mfor\u001b[39;00m x \u001b[38;5;129;01min\u001b[39;00m casted_key)\n\u001b[1;32m 3807\u001b[0m ):\n\u001b[1;32m 3808\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m InvalidIndexError(key)\n\u001b[0;32m-> 3809\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01merr\u001b[39;00m\n\u001b[1;32m 3810\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m:\n\u001b[1;32m 3811\u001b[0m \u001b[38;5;66;03m# If we have a listlike key, _check_indexing_error will raise\u001b[39;00m\n\u001b[1;32m 3812\u001b[0m \u001b[38;5;66;03m# InvalidIndexError. Otherwise we fall through and re-raise\u001b[39;00m\n\u001b[1;32m 3813\u001b[0m \u001b[38;5;66;03m# the TypeError.\u001b[39;00m\n\u001b[1;32m 3814\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_check_indexing_error(key)\n", "\u001b[0;31mKeyError\u001b[0m: 'Close'" ] } ], "source": [ "ticker = Ticker('AAPL')\n", "aapl_df = ticker.history(period=\"5y\")\n", "aapl_df['Close'].plot(title=\"APPLE's stock price\")" ] }, { "cell_type": "markdown", "id": "62ff4426", "metadata": {}, "source": [ "## YahooFinancials - Apple\n", "\n" ] }, { "cell_type": "code", "execution_count": 32, "id": "4604f41a", "metadata": {}, "outputs": [], "source": [ "from yahoofinancials import YahooFinancials" ] }, { "cell_type": "code", "execution_count": 33, "id": "81d2bf4d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
highlowopenclosevolumeadjclose
formatted_date
2019-01-0139.71250235.50000038.72250036.98249896694720035.496208
2019-01-0838.63250037.13000137.38999937.50000072547000035.992908
2019-01-1539.47000137.51250137.56750139.20500249141120037.629391
2019-01-2239.53250137.92499939.10250139.07500155477480037.504620
2019-01-2942.91500138.52750039.06250042.81250083040080041.091908
\n", "
" ], "text/plain": [ " high low open close volume \\\n", "formatted_date \n", "2019-01-01 39.712502 35.500000 38.722500 36.982498 966947200 \n", "2019-01-08 38.632500 37.130001 37.389999 37.500000 725470000 \n", "2019-01-15 39.470001 37.512501 37.567501 39.205002 491411200 \n", "2019-01-22 39.532501 37.924999 39.102501 39.075001 554774800 \n", "2019-01-29 42.915001 38.527500 39.062500 42.812500 830400800 \n", "\n", " adjclose \n", "formatted_date \n", "2019-01-01 35.496208 \n", "2019-01-08 35.992908 \n", "2019-01-15 37.629391 \n", "2019-01-22 37.504620 \n", "2019-01-29 41.091908 " ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "yahoo_financials = YahooFinancials('AAPL')\n", "data = yahoo_financials.get_historical_price_data(start_date='2019-01-01', \n", " end_date='2019-12-31', \n", " time_interval='weekly')\n", "aapl_df = pd.DataFrame(data['AAPL']['prices'])\n", "aapl_df = aapl_df.drop('date', axis=1).set_index('formatted_date')\n", "aapl_df.head()" ] }, { "cell_type": "code", "execution_count": 34, "id": "f436506d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['YAHOO_FINANCIAL_TYPES',\n", " '_BASE_YAHOO_URL',\n", " '_INTERVAL_DICT',\n", " '_MIN_INTERVAL',\n", " '__class__',\n", " '__delattr__',\n", " '__dict__',\n", " '__dir__',\n", " '__doc__',\n", " '__eq__',\n", " '__format__',\n", " '__ge__',\n", " '__getattribute__',\n", " '__getstate__',\n", " '__gt__',\n", " '__hash__',\n", " '__init__',\n", " '__init_subclass__',\n", " '__le__',\n", " '__lt__',\n", " '__module__',\n", " '__ne__',\n", " '__new__',\n", " '__reduce__',\n", " '__reduce_ex__',\n", " '__repr__',\n", " '__setattr__',\n", " '__sizeof__',\n", " '__str__',\n", " '__subclasshook__',\n", " '__weakref__',\n", " '_build_api_url',\n", " '_build_historical_url',\n", " '_cache',\n", " '_clean_api_data',\n", " '_clean_data_process',\n", " '_clean_earnings_data',\n", " '_clean_historical_data',\n", " '_clean_reports',\n", " '_convert_to_utc',\n", " '_create_dict_ent',\n", " '_determine_numeric_value',\n", " '_encode_ticker',\n", " '_financial_statement_data',\n", " '_format_time',\n", " '_get_api_data',\n", " '_get_cleaned_sub_dict_ent',\n", " '_get_proxy',\n", " '_get_stmt_id',\n", " '_get_sub_dict_ent',\n", " '_get_worker_count',\n", " '_handle_api_dividend_request',\n", " '_recursive_api_request',\n", " '_reformat_stmt_data_process',\n", " '_request_handler',\n", " '_run_financial_stmt',\n", " '_scrape_data',\n", " '_stock_price_data',\n", " '_stock_summary_data',\n", " 'concurrent',\n", " 'country',\n", " 'format_date',\n", " 'get_200day_moving_avg',\n", " 'get_50day_moving_avg',\n", " 'get_annual_avg_div_rate',\n", " 'get_annual_avg_div_yield',\n", " 'get_beta',\n", " 'get_book_value',\n", " 'get_clean_data',\n", " 'get_cost_of_revenue',\n", " 'get_currency',\n", " 'get_current_change',\n", " 'get_current_percent_change',\n", " 'get_current_price',\n", " 'get_current_volume',\n", " 'get_daily_dividend_data',\n", " 'get_daily_high',\n", " 'get_daily_low',\n", " 'get_dividend_rate',\n", " 'get_dividend_yield',\n", " 'get_earnings_per_share',\n", " 'get_ebit',\n", " 'get_exdividend_date',\n", " 'get_financial_data',\n", " 'get_financial_stmts',\n", " 'get_five_yr_avg_div_yield',\n", " 'get_gross_profit',\n", " 'get_historical_price_data',\n", " 'get_income_before_tax',\n", " 'get_income_tax_expense',\n", " 'get_interest_expense',\n", " 'get_key_statistics_data',\n", " 'get_market_cap',\n", " 'get_net_income',\n", " 'get_net_income_from_continuing_ops',\n", " 'get_num_shares_outstanding',\n", " 'get_open_price',\n", " 'get_operating_income',\n", " 'get_payout_ratio',\n", " 'get_pe_ratio',\n", " 'get_prev_close_price',\n", " 'get_price_to_sales',\n", " 'get_reformatted_stmt_data',\n", " 'get_report_type',\n", " 'get_research_and_development',\n", " 'get_stock_data',\n", " 'get_stock_dividend_data',\n", " 'get_stock_earnings_data',\n", " 'get_stock_exchange',\n", " 'get_stock_price_data',\n", " 'get_stock_profile_data',\n", " 'get_stock_quote_type_data',\n", " 'get_stock_summary_url',\n", " 'get_stock_tech_data',\n", " 'get_summary_data',\n", " 'get_ten_day_avg_daily_volume',\n", " 'get_three_month_avg_daily_volume',\n", " 'get_time_code',\n", " 'get_total_operating_expense',\n", " 'get_total_revenue',\n", " 'get_yearly_high',\n", " 'get_yearly_low',\n", " 'max_workers',\n", " 'proxies',\n", " 'ticker',\n", " 'timeout']" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dir(yahoo_financials)" ] }, { "cell_type": "code", "execution_count": 36, "id": "45bc62ee", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['__annotations__',\n", " '__builtins__',\n", " '__call__',\n", " '__class__',\n", " '__closure__',\n", " '__code__',\n", " '__defaults__',\n", " '__delattr__',\n", " '__dict__',\n", " '__dir__',\n", " '__doc__',\n", " '__eq__',\n", " '__format__',\n", " '__ge__',\n", " '__get__',\n", " '__getattribute__',\n", " '__getstate__',\n", " '__globals__',\n", " '__gt__',\n", " '__hash__',\n", " '__init__',\n", " '__init_subclass__',\n", " '__kwdefaults__',\n", " '__le__',\n", " '__lt__',\n", " '__module__',\n", " '__name__',\n", " '__ne__',\n", " '__new__',\n", " '__qualname__',\n", " '__reduce__',\n", " '__reduce_ex__',\n", " '__repr__',\n", " '__setattr__',\n", " '__sizeof__',\n", " '__str__',\n", " '__subclasshook__']" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dir(yahoo_financials.get_clean_data.__func__)" ] }, { "cell_type": "code", "execution_count": 37, "id": "c808abf1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hasattr(yahoo_financials.get_beta, '__call__')" ] }, { "cell_type": "code", "execution_count": 38, "id": "aa424d7d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "YAHOO_FINANCIAL_TYPES \t {'income': ['financials', 'incomeStatementHistory', 'incomeStatementHistoryQuarterly'], 'balance': ['balance-sheet', 'balanceSheetHistory', 'balanceSheetHistoryQuarterly', 'balanceSheetStatements'], 'cash': ['cash-flow', 'cashflowStatementHistory', 'cashflowStatementHistoryQuarterly', 'cashflowStatements'], 'keystats': ['key-statistics'], 'history': ['history'], 'profile': ['profile']} \n", "\n", "_BASE_YAHOO_URL \t https://finance.yahoo.com/quote/ \n", "\n", "_INTERVAL_DICT \t {'daily': '1d', 'weekly': '1wk', 'monthly': '1mo'} \n", "\n", "_MIN_INTERVAL \t 7 \n", "\n", "__class__ \t \n", "\n", "__delattr__ \t \n", "\n", "__dict__ \t {'ticker': 'AAPL', 'country': 'US', 'concurrent': False, 'max_workers': 8, 'timeout': 30, 'proxies': None, '_cache': {}} \n", "\n", "__dir__ \t \n", "\n", "__doc__ \t \n", " Arguments\n", " ----------\n", " tickers: str or list\n", " Ticker or listed collection of tickers\n", " Keyword Arguments\n", " -----------------\n", " concurrent: bool, default False, optional\n", " Defines whether the requests are made synchronously or asynchronously.\n", " country: str, default 'US', optional\n", " This allows you to alter the region, lang, corsDomain parameter sent with each request based on selected country\n", " max_workers: int, default 8, optional\n", " Defines the number of workers used to make concurrent requests.\n", " Only relevant if concurrent=True\n", " timeout: int, default 30, optional\n", " Defines how long a request will stay open.\n", " proxies: str or list, default None, optional\n", " Defines any proxies to use during this instantiation.\n", " \n", "\n", "__eq__ \t \n", "\n", "__format__ \t \n", "\n", "__ge__ \t \n", "\n", "__getattribute__ \t \n", "\n", "__getstate__ \t \n", "\n", "__gt__ \t \n", "\n", "__hash__ \t \n", "\n", "__init__ \t > \n", "\n", "__init_subclass__ \t \n", "\n", "__le__ \t \n", "\n", "__lt__ \t \n", "\n", "__module__ \t yahoofinancials.yf \n", "\n", "__ne__ \t \n", "\n", "__new__ \t \n", "\n", "__reduce__ \t \n", "\n", "__reduce_ex__ \t \n", "\n", "__repr__ \t \n", "\n", "__setattr__ \t \n", "\n", "__sizeof__ \t \n", "\n", "__str__ \t \n", "\n", "__subclasshook__ \t \n", "\n", "__weakref__ \t None \n", "\n", "_build_api_url \t > \n", "\n", "_build_historical_url \t > \n", "\n", "_cache \t {} \n", "\n", "_clean_api_data \t > \n", "\n", "_clean_data_process \t > \n", "\n", "_clean_earnings_data \t > \n", "\n", "_clean_historical_data \t > \n", "\n", "_clean_reports \t > \n", "\n", "_convert_to_utc \t \n", "\n", "_create_dict_ent \t > \n", "\n", "_determine_numeric_value \t \n", "\n", "_encode_ticker \t \n", "\n", "_financial_statement_data \t > \n", "\n", "_format_time \t > \n", "\n", "_get_api_data \t > \n", "\n", "_get_cleaned_sub_dict_ent \t > \n", "\n", "_get_proxy \t > \n", "\n", "_get_stmt_id \t > \n", "\n", "_get_sub_dict_ent \t > \n", "\n", "_get_worker_count \t > \n", "\n", "_handle_api_dividend_request \t > \n", "\n", "_recursive_api_request \t > \n", "\n", "_reformat_stmt_data_process \t > \n", "\n", "_request_handler \t > \n", "\n", "_run_financial_stmt \t > \n", "\n", "_scrape_data \t > \n", "\n", "_stock_price_data \t > \n", "\n", "_stock_summary_data \t > \n", "\n", "concurrent \t False \n", "\n", "country \t US \n", "\n", "format_date \t \n", "\n", "get_200day_moving_avg \t > \n", "\n", "get_50day_moving_avg \t > \n", "\n", "get_annual_avg_div_rate \t > \n", "\n", "get_annual_avg_div_yield \t > \n", "\n", "get_beta \t > \n", "\n", "get_book_value \t > \n", "\n", "get_clean_data \t > \n", "\n", "get_cost_of_revenue \t > \n", "\n", "get_currency \t > \n", "\n", "get_current_change \t > \n", "\n", "get_current_percent_change \t > \n", "\n", "get_current_price \t > \n", "\n", "get_current_volume \t > \n", "\n", "get_daily_dividend_data \t > \n", "\n", "get_daily_high \t > \n", "\n", "get_daily_low \t > \n", "\n", "get_dividend_rate \t > \n", "\n", "get_dividend_yield \t > \n", "\n", "get_earnings_per_share \t > \n", "\n", "get_ebit \t > \n", "\n", "get_exdividend_date \t > \n", "\n", "get_financial_data \t > \n", "\n", "get_financial_stmts \t > \n", "\n", "get_five_yr_avg_div_yield \t > \n", "\n", "get_gross_profit \t > \n", "\n", "get_historical_price_data \t > \n", "\n", "get_income_before_tax \t > \n", "\n", "get_income_tax_expense \t > \n", "\n", "get_interest_expense \t > \n", "\n", "get_key_statistics_data \t > \n", "\n", "get_market_cap \t > \n", "\n", "get_net_income \t > \n", "\n", "get_net_income_from_continuing_ops \t > \n", "\n", "get_num_shares_outstanding \t > \n", "\n", "get_open_price \t > \n", "\n", "get_operating_income \t > \n", "\n", "get_payout_ratio \t > \n", "\n", "get_pe_ratio \t > \n", "\n", "get_prev_close_price \t > \n", "\n", "get_price_to_sales \t > \n", "\n", "get_reformatted_stmt_data \t > \n", "\n", "get_report_type \t \n", "\n", "get_research_and_development \t > \n", "\n", "get_stock_data \t > \n", "\n", "get_stock_dividend_data \t > \n", "\n", "get_stock_earnings_data \t > \n", "\n", "get_stock_exchange \t > \n", "\n", "get_stock_price_data \t > \n", "\n", "get_stock_profile_data \t > \n", "\n", "get_stock_quote_type_data \t > \n", "\n", "get_stock_summary_url \t > \n", "\n", "get_stock_tech_data \t > \n", "\n", "get_summary_data \t > \n", "\n", "get_ten_day_avg_daily_volume \t > \n", "\n", "get_three_month_avg_daily_volume \t > \n", "\n", "get_time_code \t > \n", "\n", "get_total_operating_expense \t > \n", "\n", "get_total_revenue \t > \n", "\n", "get_yearly_high \t > \n", "\n", "get_yearly_low \t > \n", "\n", "max_workers \t 8 \n", "\n", "proxies \t None \n", "\n", "ticker \t AAPL \n", "\n", "timeout \t 30 \n", "\n" ] } ], "source": [ "for p in dir(yahoo_financials):\n", " print (p, '\\t', getattr(yahoo_financials, p), '\\n')" ] }, { "cell_type": "markdown", "id": "fa9e808b", "metadata": {}, "source": [ "## YahooFinancials - Bitcoin" ] }, { "cell_type": "code", "execution_count": 41, "id": "503452af", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
highlowopenclosevolumeadjclose
formatted_date
2019-08-0112273.8212899421.62988310077.4423839630.6640625339849717349630.664062
2019-09-0110898.7617197830.7587899630.5927738293.8681644805449632308293.868164
2019-10-0110021.7441417446.9887708299.7207039199.5849615952051347489199.584961
2019-11-019505.0517586617.1669929193.9921887569.6298836769195236507569.629883
2019-12-017743.4316416540.0493167571.6162117193.5991216337903734167193.599121
\n", "
" ], "text/plain": [ " high low open close \\\n", "formatted_date \n", "2019-08-01 12273.821289 9421.629883 10077.442383 9630.664062 \n", "2019-09-01 10898.761719 7830.758789 9630.592773 8293.868164 \n", "2019-10-01 10021.744141 7446.988770 8299.720703 9199.584961 \n", "2019-11-01 9505.051758 6617.166992 9193.992188 7569.629883 \n", "2019-12-01 7743.431641 6540.049316 7571.616211 7193.599121 \n", "\n", " volume adjclose \n", "formatted_date \n", "2019-08-01 533984971734 9630.664062 \n", "2019-09-01 480544963230 8293.868164 \n", "2019-10-01 595205134748 9199.584961 \n", "2019-11-01 676919523650 7569.629883 \n", "2019-12-01 633790373416 7193.599121 " ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "yahoo_financials = YahooFinancials('BTC-USD')\n", "data=yahoo_financials.get_historical_price_data(\"2019-07-10\", \"2022-01-31\", \"monthly\")\n", "btc_df = pd.DataFrame(data['BTC-USD']['prices'])\n", "btc_df = btc_df.drop('date', axis=1).set_index('formatted_date')\n", "btc_df.head()" ] }, { "cell_type": "code", "execution_count": 42, "id": "a381b608", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
highlowopenclosevolumeadjclose
formatted_date
2021-09-0152853.76562539787.60937547099.77343843790.894531110213967882443790.894531
2021-10-0166930.39062543320.02343843816.74218861318.957031115307790353461318.957031
2021-11-0168789.62500053569.76562561320.44921957005.425781105327027138357005.425781
2021-12-0159041.68359442874.61718856907.96484446306.44531295704718472246306.445312
2022-01-0147881.40625033184.05859446311.74609438483.12500092397903768138483.125000
\n", "
" ], "text/plain": [ " high low open close \\\n", "formatted_date \n", "2021-09-01 52853.765625 39787.609375 47099.773438 43790.894531 \n", "2021-10-01 66930.390625 43320.023438 43816.742188 61318.957031 \n", "2021-11-01 68789.625000 53569.765625 61320.449219 57005.425781 \n", "2021-12-01 59041.683594 42874.617188 56907.964844 46306.445312 \n", "2022-01-01 47881.406250 33184.058594 46311.746094 38483.125000 \n", "\n", " volume adjclose \n", "formatted_date \n", "2021-09-01 1102139678824 43790.894531 \n", "2021-10-01 1153077903534 61318.957031 \n", "2021-11-01 1053270271383 57005.425781 \n", "2021-12-01 957047184722 46306.445312 \n", "2022-01-01 923979037681 38483.125000 " ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "btc_df.tail()" ] }, { "cell_type": "code", "execution_count": null, "id": "1fdbf163", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.7" } }, "nbformat": 4, "nbformat_minor": 5 }