Skip to content

Instantly share code, notes, and snippets.

@virattt
Created November 10, 2024 19:49
Show Gist options
  • Save virattt/146751c0d7dcea13f369a2efaffd4c25 to your computer and use it in GitHub Desktop.
Save virattt/146751c0d7dcea13f369a2efaffd4c25 to your computer and use it in GitHub Desktop.
financial-metrics-snapshot.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyPjRMfSelrWfq3w8hIj1hvC",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/virattt/146751c0d7dcea13f369a2efaffd4c25/financial-metrics-snapshot.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"Hi there 👋 - [financialdatasets.ai](https://www.financialdatasets.ai) is a stock market API that provides:\n",
"\n",
"\n",
"* income statements\n",
"* balance sheets\n",
"* cash flow statements\n",
"* options chains\n",
"* insider transactions\n",
"* sec filings\n",
"* stock prices\n",
"\n",
"This is a quick start guide on how to get **financial metrics** with the API.\n",
"\n",
"We currently provide prices for 10,000+ stocks.\n",
"\n",
"**Questions?**\n",
"\n",
"The full API documentation is available [here](https://docs.financialdatasets.ai/api-reference/endpoint/financial-metrics).\n",
"\n",
"You can also DM me on [twitter](https://www.x.com/virattt)."
],
"metadata": {
"id": "a53EMYsewzwX"
}
},
{
"cell_type": "markdown",
"source": [
"# 1. Get financial metrics snapshot"
],
"metadata": {
"id": "nbjI1k1FxUbg"
}
},
{
"cell_type": "code",
"source": [
"# In the free tier, you can access financials for 6 companies:\n",
"free_tier_companies = ['AAPL', 'MSFT', 'BRK.B', 'NVDA', 'TSLA', 'GOOGL']"
],
"metadata": {
"id": "dki375cQxhH8"
},
"execution_count": 1,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import requests\n",
"\n",
"ticker = 'AAPL'\n",
"url = (\n",
" f'https://api.financialdatasets.ai/financial-metrics/snapshot'\n",
" f'?ticker={ticker}'\n",
")\n",
"\n",
"response = requests.get(url)"
],
"metadata": {
"id": "a80F53L4xY_y"
},
"execution_count": 2,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# 2. Parse response"
],
"metadata": {
"id": "CwdTTd4Rn2xV"
}
},
{
"cell_type": "code",
"source": [
"# Grab the snapshot\n",
"snapshot = response.json().get('snapshot', {})\n",
"\n",
"# Render snapshot\n",
"snapshot"
],
"metadata": {
"id": "0PNrc5W6x6rO",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "1d14becb-c676-432d-fb4b-afe422b765a5"
},
"execution_count": 3,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"{'ticker': 'AAPL',\n",
" 'market_cap': 3450730933520.0,\n",
" 'enterprise_value': 3527416933520.0,\n",
" 'pe_ratio': 36.813294076128706,\n",
" 'pb_ratio': 60.59229031641791,\n",
" 'ps_ratio': 8.824608880330405,\n",
" 'ev_ebitda_ratio': 28.56554993335223,\n",
" 'ev_revenue_ratio': 9.0207192029358,\n",
" 'gross_margin': 0.4620634981523393,\n",
" 'operating_margin': 0.3157901466620635,\n",
" 'net_margin': 0.23971255769943867,\n",
" 'return_on_equity': 1.6459350307287095,\n",
" 'return_on_assets': 0.25682503150857583,\n",
" 'return_on_invested_capital': 0.729991544194678,\n",
" 'asset_turnover': 1.0713874732862074,\n",
" 'inventory_turnover': 53.66936590721932,\n",
" 'current_ratio': 0.8673125765340832,\n",
" 'quick_ratio': 0.8260068483831466,\n",
" 'cash_ratio': 0.16975259648963673,\n",
" 'debt_to_equity': 1.872326602282704,\n",
" 'debt_to_assets': 0.29215025480848267,\n",
" 'interest_coverage': None,\n",
" 'revenue_growth': 0.014087027331218896,\n",
" 'earnings_growth': -0.08062301384911139,\n",
" 'book_value_growth': -0.14627930682976553,\n",
" 'payout_ratio': 0.16252026969360758,\n",
" 'earnings_per_share': 6.165164126053323,\n",
" 'book_value_per_share': 3.7456910576377993,\n",
" 'free_cash_flow_per_share': 7.156407496196595}"
]
},
"metadata": {},
"execution_count": 3
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment