This repository has been archived on 2023-06-18. You can view files and clone it, but cannot push or open issues or pull requests.
va-project/indexer/balance_sheet.ipynb

106 lines
52 KiB
Text
Raw Normal View History

{
"cells": [
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "This method only works with the ScalarFormatter",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"File \u001b[0;32m~/opt/anaconda3/envs/visual-analytics/lib/python3.11/site-packages/matplotlib/axes/_base.py:3262\u001b[0m, in \u001b[0;36m_AxesBase.ticklabel_format\u001b[0;34m(self, axis, style, scilimits, useOffset, useLocale, useMathText)\u001b[0m\n\u001b[1;32m 3261\u001b[0m \u001b[39mif\u001b[39;00m is_sci_style \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m-> 3262\u001b[0m axis\u001b[39m.\u001b[39;49mmajor\u001b[39m.\u001b[39;49mformatter\u001b[39m.\u001b[39;49mset_scientific(is_sci_style)\n\u001b[1;32m 3263\u001b[0m \u001b[39mif\u001b[39;00m scilimits \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n",
"\u001b[0;31mAttributeError\u001b[0m: 'FuncFormatter' object has no attribute 'set_scientific'",
"\nThe above exception was the direct cause of the following exception:\n",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[22], line 42\u001b[0m\n\u001b[1;32m 39\u001b[0m plt\u001b[39m.\u001b[39mshow()\n\u001b[1;32m 41\u001b[0m ticker_list \u001b[39m=\u001b[39m [\u001b[39m'\u001b[39m\u001b[39mMETA\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39mAAPL\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39mKO\u001b[39m\u001b[39m'\u001b[39m]\n\u001b[0;32m---> 42\u001b[0m compare_balance_sheets(ticker_list)\n",
"Cell \u001b[0;32mIn[22], line 36\u001b[0m, in \u001b[0;36mcompare_balance_sheets\u001b[0;34m(ticker_list)\u001b[0m\n\u001b[1;32m 33\u001b[0m ax\u001b[39m.\u001b[39mgrid(\u001b[39mFalse\u001b[39;00m)\n\u001b[1;32m 35\u001b[0m \u001b[39m# Remove scientific notation\u001b[39;00m\n\u001b[0;32m---> 36\u001b[0m ax\u001b[39m.\u001b[39;49mticklabel_format(style\u001b[39m=\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39mplain\u001b[39;49m\u001b[39m'\u001b[39;49m)\n\u001b[1;32m 38\u001b[0m plt\u001b[39m.\u001b[39mtight_layout() \u001b[39m# Adjust subplot spacing\u001b[39;00m\n\u001b[1;32m 39\u001b[0m plt\u001b[39m.\u001b[39mshow()\n",
"File \u001b[0;32m~/opt/anaconda3/envs/visual-analytics/lib/python3.11/site-packages/matplotlib/axes/_base.py:3272\u001b[0m, in \u001b[0;36m_AxesBase.ticklabel_format\u001b[0;34m(self, axis, style, scilimits, useOffset, useLocale, useMathText)\u001b[0m\n\u001b[1;32m 3270\u001b[0m axis\u001b[39m.\u001b[39mmajor\u001b[39m.\u001b[39mformatter\u001b[39m.\u001b[39mset_useMathText(useMathText)\n\u001b[1;32m 3271\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mAttributeError\u001b[39;00m \u001b[39mas\u001b[39;00m err:\n\u001b[0;32m-> 3272\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mAttributeError\u001b[39;00m(\n\u001b[1;32m 3273\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mThis method only works with the ScalarFormatter\u001b[39m\u001b[39m\"\u001b[39m) \u001b[39mfrom\u001b[39;00m \u001b[39merr\u001b[39;00m\n",
"\u001b[0;31mAttributeError\u001b[0m: This method only works with the ScalarFormatter"
]
},
{
"data": {
"image/png": "iVBORw0KGgoA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ePT01NTf21rl27NurZl1xyScaNG9c0gzbCkiVLMnXq1AZr48ePzymnnJKqqvL+3dMNN9yQyy+/vKXHAAAAAAAAAAAACiB2BiBJsv3222f+/Pl5+OGH62PnmTNn5s0330yS9O7dO6+88so73t+5c+f06NHjXd9jq622ahAxd+7ceZPuf/upxDvuuGPmzZuXmTNn5rnnnsvOO+/83r9cI/xtwNyxY8f6n2tqat7zd3w3dXV17/veD2LSpEn1AfdfP7/58+fngQceyGc/+9kWmendtNTnBAAAAAAAAAAAlKe84xwBaBEDBgxIkjz44IP1aw8//HCSt0LnXr16tchctbW1mTRpUpK3Qt2vfe1r9dfGjh3bIjO9XV1dXcaOHZtjjjkmn/rUp7L33nvnyCOPzA033NDghOjhw4c3iLaHDBmSXXfdtf710qVLc9FFF+WQQw7J3nvvnb333juHHHJIRo0alWXLln2gGf/6vltttVV+9KMf1a+/0+c3e/bsnHLKKRk4cGD69u2bfffdN1/4whcyYcKEDfbed999GTFiRPr375++ffumX79+GTZsWKZNm7bB3mXLlmXUqFE58MAD8/GPfzyf/exn8/3vfz+vvvpq/Z5zzjknV1xxRf3rY489Nrvuumt9aP/cc8/lG9/4RgYNGpQ99tgje++9d4444ohcd911ImkAAAAAAAAAAPg75GRnAJIk/fv3z8SJE/PUU0/ljTfeSJcuXTJ9+vT6a+92qnPyVsi6cOHCjV7r1KlTttxyy/c119SpU7NkyZIkyeGHH54hQ4Zkyy23zMqVK3PLLbfkW9/6Vqqrq9/Xsz+odevW5bTTTsu9997bYP3pp5/O008/nXvuuSe/+MUvssUWW7znc0444YT813/9V4P1F198MTfeeGPmzp2bX/7yl+9rxieffDJ/+tOfkiQHH3xwBgwYkB122CEvvvhi7r333ixevDg1NTUN9g8fPrz+RO8kWblyZZ588sk8+eSTWbZsWY477rgkyZQpU3L66ac3iIyXLVuWRx99NI899lguv/zyfO5zn0uSvPHGGznmmGPy/PPP1+9dtGhRxowZk/vuuy9jxoxJz5493/V3mT9/fr74xS9m+fLl9Wtr167N3LlzM3fu3CxcuDDnn3/++/qcAAAAAAAAAACAMjnZGYAk/3uy8/r16zN9+vQsXbo0Tz/9dINr72bkyJE54IADNvpn3Lhx73uut5+GfPjhh6dDhw455JBDkrx1GvLdd9/9vp/9QV1//fX1ofOnP/3p/Pa3v83EiRNz+OGHJ0lmzZqViy66KElyxRVX1K8nyZgxY3L//fcnSR555JE888wzSZLTTjstkydPzvjx47PHHnskSWbMmJGVK1e+rxn/9vNLkqFDhyZ5KxT+29Oab7311rz55pvZYost8rOf/SxTpkzJzTffnI997GNp27Zt7rrrrqxfv77+2XV1denevXtGjx6dKVOm5Prrr892222XNm3a5Pbbb69/7uWXX57nn38+VVVVOffcc3PXXXflpz/9aWpqarJo0aL83//7f5Mk5557bk444YQG991///3p2bNn7r777vrQ+dJLL82UKVMyYcKE9O/fP1VVVfnjH/+YFStWvK/PCQAAAAAAAAAAKJPY+R1cc801GT58eLPc/8ILL2Tvvfd+z1NSATanXr16pXfv3kmSBx98MDNmzKiPWjcldm4Of/7zn/PQQw8lSfbYY4/stNNOSZLPf/7z9XvGjh37ns9ZvHhxFi5c2ODPqlWrPvB8v/71r5MkNTU1+clPfpJ99tkne+yxRy655JLstttuSZKJEydm5cqV6dq1azp06FB/b7du3dKjR48kycCBAzN79uzcfvvtOeOMM/KRj3wk22yzTbbffvskSV1dXZYtW9bo+VatWpU77rgjSbLttttm4MCBSRp+fuPGjWtwMvPWW2+dJFmzZk0eeeSRLFq0KB//+Mfzm9/8JrNnz86YMWNSVVXVYO/y5cvz6KOPZunSpRkwYEBuv/32PPHEE7nqqqvq57/zzjuTJPvuu28OPfTQdOzYMX379s0///M/J3nrBO9ly5alS5cu2Wqrrern6dq1a3r06JE2bdrUv1/yVgD+0ksvZaeddsp//Md/ZPbs2bn77rsb3AsAAAAAAAAAAHz4tW3pAUp044035sorr0y/fv2a/P5nnnkmJ598cpNEdgBNrX///nnllVfy8MMP1wetffr0Sc+ePd/z3osvvjhHHHFEk84zceLE+uD6ox/9aP7whz8keSue7dixY1atWpVHHnkkzz//fD760Y++43O++MUvZv78+Q3WRo0alaOOOup9z7ZkyZIsXLgwSbL33ntniy22qL9WVVWV/fbbL3Pnzs2bb76Z559/Pp/4xCfe9XlvvPFG7r///lx88cX5r//6r7z++usNrq9bt67RM9511131Jx3vuuuuefDBB+uv9erVK3/+85/zyiuv5MEHH8ygQYOSJMOHD8+0adPy1FNP5brrrst1112Xdu3a5ROf+EQOPvjg/Mu//Et9UHzaaafl0UcfzSuvvJIrr7wyV155ZTp27Jh99tknn/vc53LUUUeluro6S5YsydKlS5MkM2fOzAEHHLDBrOvWrcvcuXPTv3//d/x9Dj/88Nxxxx154IEHMnbs2IwdOzZt2rTJbrvtlsGDB+eYY45Jt27dGv05AQAAAAAAAAAA5RI7v82iRYty3nnn5bHHHqs/PbQp7//pT3+aa6+9NjvvvHMWLFjQFCMDNKkBAwZk4sSJeemll7J8+fIkedf4tDnV1dVl4sSJ9a9vu+223HbbbRvdO27cuJx99tmba7QkSdu2//u/0EqlssH1t5+WvLHrb/ff//3f+cpXvpI33ngjvXr1ytChQ7P33nvnkUceyW9+85v3PeP48ePrf37ooYfqT8n+W2PHjq2PnbfeeuuMHz8+999/f+6999488sgjmTdvXmbNmpVZs2ZlzJgxGT9+fDp16pQ
"text/plain": [
"<Figure size 3600x1200 with 3 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import sys\n",
"sys.path.append('../group-1')\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"import matplotlib.font_manager as font_manager\n",
"\n",
"def compare_balance_sheets(ticker_list: list):\n",
" num_charts = len(ticker_list)\n",
"\n",
" # Create a single figure object and subplots\n",
" fig, axes = plt.subplots(1, num_charts, figsize=(12*num_charts, 12), sharey=True)\n",
"\n",
" # Set font properties\n",
" font = font_manager.FontProperties(weight='bold', size=12)\n",
"\n",
" for i, ticker in enumerate(ticker_list):\n",
" assets_debt = pd.read_csv(r'../Companies_Data/'+ticker+'_Data/'+ticker+'_balance_sheet_4Y+4Q.csv')\n",
" selected_data = assets_debt[['TotalAssets', 'TotalDebt', 'CurrentAssets', 'CurrentDebt']]\n",
"\n",
" sns.set(style=\"whitegrid\") # Set seaborn style\n",
"\n",
" # Create bar plot for Total Assets\n",
" ax = axes[i]\n",
" ax.bar(range(len(selected_data.columns)), selected_data.iloc[0], color='green')\n",
" ax.set_title(f'{ticker} - Total Assets', fontproperties=font, fontsize=14, weight='bold')\n",
" ax.set_xlabel(ticker, fontproperties=font)\n",
" ax.set_ylabel('Amount in $', fontproperties=font)\n",
" ax.set_xticks(range(len(selected_data.columns)))\n",
" ax.set_xticklabels(selected_data.columns, fontproperties=font)\n",
"\n",
" # Remove background grid\n",
" ax.grid(False)\n",
"\n",
" # Remove scientific notation\n",
" ax.ticklabel_format(style='plain')\n",
"\n",
" plt.tight_layout() # Adjust subplot spacing\n",
" plt.show()\n",
"\n",
"ticker_list = ['META', 'AAPL', 'KO']\n",
"compare_balance_sheets(ticker_list)\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".env",
"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.0"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}