Getting stock key statistics for trading.
To guarantee stable profits and successful trading in addition to main technical indicators used in scope of Technical analysis described in previous section,
we may need to look at key stock statistics data provided from live market.
We will use these data from Yahoo Finance, which is a commonly known as golden source of information for
stocks, options, ETFs, mutual funds and news.
Python Knowledge Base: Make coding great again.
- Updated:
2024-11-20 by Andrey BRATUS, Senior Data Analyst.
Python code to stock key statistics:
Stock key statistics output:
To use necessary API you need to get "your-api-key" directly from Yahoo Finance, or using rapidapi.com, the way I recommend. Output data is in JSON format which can be easily converted to any suitable form for further visualisation and analysis, stock key statistics data will definetely help you to gain stable profitable market profits.
Hint: you should specify a symbol in a script below to get a key data for it.
import requests
symbol = "AAPL"
url = f"https://yahoo-finance15.p.rapidapi.com/api/yahoo/qu/quote/{symbol}/default-key-statistics"
headers = {
"X-RapidAPI-Key": "your-api-key",
"X-RapidAPI-Host": "yahoo-finance15.p.rapidapi.com"
}
response = requests.request("GET", url, headers=headers)
print(response.text)
{
"defaultKeyStatistics": {
"maxAge": 1,
"priceHint": {
"raw": 2,
"fmt": "2",
"longFmt": "2"
},
"enterpriseValue": {
"raw": 2369416855552,
"fmt": "2.37T",
"longFmt": "2,369,416,855,552"
},
"forwardPE": {
"raw": 21.387945,
"fmt": "21.39"
},
"profitMargins": {
"raw": 0.25709,
"fmt": "25.71%"
},
"floatShares": {
"raw": 16053717003,
"fmt": "16.05B",
"longFmt": "16,053,717,003"
},
"sharesOutstanding": {
"raw": 16070800384,
"fmt": "16.07B",
"longFmt": "16,070,800,384"
},
"sharesShort": {
"raw": 103251184,
"fmt": "103.25M",
"longFmt": "103,251,184"
},
"sharesShortPriorMonth": {
"raw": 113066596,
"fmt": "113.07M",
"longFmt": "113,066,596"
},
"sharesShortPreviousMonthDate": {
"raw": 1661904000,
"fmt": "2022-08-31"
},
"dateShortInterest": {
"raw": 1664496000,
"fmt": "2022-09-30"
},
"sharesPercentSharesOut": {
"raw": 0.0064,
"fmt": "0.64%"
},
"heldPercentInsiders": {
"raw": 0.00071000005,
"fmt": "0.07%"
},
"heldPercentInstitutions": {
"raw": 0.59577,
"fmt": "59.58%"
},
"shortRatio": {
"raw": 1.06,
"fmt": "1.06"
},
"shortPercentOfFloat": {
"raw": 0.0064,
"fmt": "0.64%"
},
"beta": {
"raw": 1.249815,
"fmt": "1.25"
},
"impliedSharesOutstanding": {
"raw": 0,
"fmt": null,
"longFmt": "0"
},
"morningStarOverallRating": [],
"morningStarRiskRating": [],
"category": null,
"bookValue": {
"raw": 3.61,
"fmt": "3.61"
},
"priceToBook": {
"raw": 38.332413,
"fmt": "38.33"
},
"annualReportExpenseRatio": [],
"ytdReturn": [],
"beta3Year": [],
"totalAssets": [],
"yield": [],
"fundFamily": null,
"fundInceptionDate": [],
"legalType": null,
"threeYearAverageReturn": [],
"fiveYearAverageReturn": [],
"priceToSalesTrailing12Months": [],
"lastFiscalYearEnd": {
"raw": 1632528000,
"fmt": "2021-09-25"
},
"nextFiscalYearEnd": {
"raw": 1695600000,
"fmt": "2023-09-25"
},
"mostRecentQuarter": {
"raw": 1656115200,
"fmt": "2022-06-25"
},
"earningsQuarterlyGrowth": {
"raw": -0.106,
"fmt": "-10.60%"
},
"revenueQuarterlyGrowth": [],
"netIncomeToCommon": {
"raw": 99632996352,
"fmt": "99.63B",
"longFmt": "99,632,996,352"
},
"trailingEps": {
"raw": 6.05,
"fmt": "6.05"
},
"forwardEps": {
"raw": 6.47,
"fmt": "6.47"
},
"pegRatio": {
"raw": 2.47,
"fmt": "2.47"
},
"lastSplitFactor": "4:1",
"lastSplitDate": {
"raw": 1598832000,
"fmt": "2020-08-31"
},
"enterpriseToRevenue": {
"raw": 6.114,
"fmt": "6.11"
},
"enterpriseToEbitda": {
"raw": 18.289,
"fmt": "18.29"
},
"52WeekChange": {
"raw": -0.05574888,
"fmt": "-5.57%"
},
"SandP52WeekChange": {
"raw": -0.20135921,
"fmt": "-20.14%"
},
"lastDividendValue": {
"raw": 0.23,
"fmt": "0.23"
},
"lastDividendDate": {
"raw": 1659657600,
"fmt": "2022-08-05"
},
"lastCapGain": [],
"annualHoldingsTurnover": []
}
}