2023-05-23 20:54:46 +00:00
{
"cells": [
2023-05-23 20:55:18 +00:00
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"<h4>Claudio, questo notebook genera la chart relativa alla salute finanziaria. Essenzialmente ci sono quattro colonne che sono stackate a coppie di due: Total Assets/Current Assets e Total Debt/Current Debt. Sostanzialmente asset e debiti a breve termine e lungo termine (quelli a lungo termine saranno sempre superiori in quanto incorporano quelli a breve termine in entrambi i casi). Come vedi il colore degli asset e debiti a breve è molto più marcato perché questi sono nettamente più rilevanti. Se hai qualche idea su come mostrarlo diversamente sono bene accette, io penso che questa soluzione faccia il suo, penso che le stacked bar siano molto efficaci in questo contesto. \n",
"</h4>\n",
"\n",
"<h4>*Nota: ho scelto proprio APPL e MSFT per mostrare che secondo me anche questo garfico ha bisogno di una versione \"relativa\". Quello che vedi sotto compara i valori assoluti, però anche averne uno in cui le altezze delle colonne sono determinate rispetto alle dimensioni dell'azienda non sarebbe male. Domani vediamo comunque.</h4>"
]
},
2023-05-23 20:54:46 +00:00
{
"cell_type": "code",
2023-05-23 20:55:18 +00:00
"execution_count": 42,
2023-05-23 20:54:46 +00:00
"metadata": {},
"outputs": [
{
"data": {
2023-05-23 20:55:18 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAACVAAAASgCAYAAAAUgfEiAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy88F64QAAAACXBIWXMAAA9hAAAPYQGoP6dpAACn30lEQVR4nOzdedyWc94//tfVpi60KUUlFHFTyRq6ddu3MT+MMYRBxp5BMRiikWVmzGDEMLbbvmtEtgkzmSHCNJgyWabsUqm0r9fvj76dd9dUiOqsjufz8Tgfj+s8js/nPN7HefXH9Xj3Oj6fiqqqqqoAAAAAAAAAAAAUUI1yFwAAAAAAAAAAAFAuAlQAAAAAAAAAAEBhCVABAAAAAAAAAACFJUAFAAAAAAAAAAAUlgAVAAAAAAAAAABQWAJUAAAAAAAAAABAYQlQAQAAAAAAAAAAhSVABQAAAAAAAAAAFJYAFQAAAAAAAAAAUFi1yl0AALD6OeywwzJs2LAkyeGHH54+ffos03nnnntu/vjHP1Y7VqNGjdSuXTuNGjVK586d06NHj7Rq1WqxcwYPHpzmzZsv5V0tvXbt2i32eO3atdOwYcO0b98+PXr0yBZbbPGtPv+jjz7K7rvvniQ55JBDcumll37rWldW48ePz80335znn38+n3zySWbPnp2mTZtm6623ztFHH50OHTpUG7/gO99xxx1z2223laHi/zN16tRMmDAhLVu2LGsdAAAAsDL7zz5Ply5dcsstt1Qbc+2116Zfv36l9y1atMhzzz1XbcygQYPy4IMP5p///GcmTZqUunXrZuONN87ee++do446KmussUZpbL9+/XLttdd+bW2vvPJKLrvsskX6UEty+eWX5+CDD/5GY7/O4vpfSVKrVq3Uq1cvG2ywQX7wgx+kW7duqaio+FbXOOqoozJ06NDUrFkzI0aM+K4lr3TmzZuX/v37Z8CAAXnnnXcyefLkrLnmmtlkk03y/e9/P4ccckhq1qxZGl+O/uFXefvtt7PpppuWtQYAKBIrUAEAy9R7771XCkElyWOPPZZp06Ytt3kLzJs3LzNnzsxnn32WRx55JN26dcunn366dMWvILNnz87YsWPz3HPP5fDDD88bb7xR7pJWSu+//34OOOCA3HrrrXn33Xczbdq0zJ49O5988kkGDhyYH/3oRxk4cGC5y1zEnDlzcu+992avvfbK0KFDy10OAAAArFJeffXVzJo1q9qxl1566SvnXHbZZenRo0cGDx6c8ePHZ86cOZkyZUreeOONXHHFFenWrdtS9ZlWZnPmzMnkyZMzfPjwXHzxxfnlL39Z7pJWSvPmzcsZZ5yR888/P0OHDs2ECRMyZ86cTJo0Ka+++mouvPDCnHLKKZk3b165S13EG2+8kaOOOip9+/YtdykAUCgCVADAMvXQQw9Vez9lypQ88cQTy3Xe4MGD8+yzz+aee+7JtttumyT5/PPP8/vf/34pKl9+ttlmmwwePDiDBw/On//85zz55JM544wzkiQzZ87Mb3/72/IWuJL65S9/mfHjx6dWrVo5++yz8+ijj+aJJ55I7969U7t27cybNy8XXXTRStcAfeKJJ9KnT5+MGzeu3KUAAADAKmfGjBl57bXXSu+nT5+ef/zjH0scP2LEiNx+++1Jkk6dOuXWW2/NoEGDcvfdd2f77bdPkvzzn/9c4krV1157balv85+vtddeO+edd161Y8ccc8wS5+67777f+f4XZ0H/6y9/+UueeeaZ3HTTTWnWrFmS5I477shHH320XK67Knv22Wfz9NNPJ0l23XXX3H333Rk0aFBuueWW0qpOf/nLX/LYY4+Vs8zFOvzwwz2UBwBlIEAFACwzs2fPzoABA5IkLVu2LC2B/cADDyyXeUnStGnTNG/ePC1btsw222yTq6++ujT/hRde+Nb3sizVqVMnzZs3T/PmzbP++utn4403zsknn5w2bdokSd58880yV7hyevnll5Mkm2++eX7yk5+kXbt2adOmTY488sj88Ic/TDI/aLeyfX9VVVXlLgEAAABWSS1atEiSDBkypHTs1VdfzezZs5PM7xv9pwX9gyQ5+eSTs/POO2eDDTbItttum6uuuio1atRY5DMX1qhRo1Lf5j9fFRUVadCgQbVja6211hLn1qtX77t/CYuxoP+13nrrpVWrVtlll11y1FFHJZm/0tLquP3ed7Xwv4uzzjor2267bTbYYIN06dIll156aenckv5dlJPeEgCUhwAVALDM/PnPf8748eOTJIceemh23HHHJMnrr7+ef/3rX8t83uI0bdo0jRo1SpKMHTt2qe9hRVrQwGvcuHG14zNnzsy1116b/fffP1tvvXU6dOiQ3XbbLRdccEHGjBnzjT77L3/5S44++ujstNNO2XLLLbPDDjvk2GOPzeDBg6uNO+qoo9KuXbscfPDBGTNmTM4+++zssMMO6dixY44++ujFhpPeeOON9OjRIzvuuGPat2+fPfbYI3369Fmktnnz5uWOO+7IAQcckPbt22eHHXbISSed9I0DT3Xq1Eky/ynRq666Kp999lnp3LnnnpshQ4ZkyJAh6dSp02LnjxgxIscee2y22mqrdO7cOeeff34mTJjwrWtc8HvZe++9s+WWW2annXZKr169MmrUqNKYfv365Wc/+1np/XnnnZd27dpVa9oBAAAAi7fDDjskqf5Q3IKAS8uWLbP++usvMmdB/yBJfvOb3+T555/PnDlzkiRNmjQp9Q+uu+665Vn6Cregr5Qs2lv6pn2hJfnkk0/Su3fv7LbbbunQoUO23nrrfO9738u1116bmTNnlsb1798/7dq1S7t27fKvf/0rt912W6lvsvfeey921a8vv/wyV1xxRfbee++0b98+O+20U4499tj87W9/W2Ts66+/nhNOOCHbbrttOnTokAMPPDB33333N9p2r3bt2qWf+/Tpk1dffbUUTOrQoUPp38UFF1yw2PlTp07N5Zdfnp133jkdO3Zc4qpQS1Pj888/n6OOOiqdOnVKp06dcthhh2XgwIGl8x999FHatWuXuXPnJkmGDh2adu3a5dxzz/3a+wUAvrta5S4AAFh9LLwN33777ZfmzZuXmh8PPPBALrzwwmU6b3HGjBlTCsmss846S30Py1tVVVWmTJmS/v3755133kmSHHLIIdXG9OrVK4MGDap27OOPP86DDz6YV155JU888URpla3FeeaZZ3LaaadVa9RMnDgxL774YoYMGZI777wz2223XbU5EydOzI9+9KN8+umnpWMvvfRSunfvnueeey5rr712kmTQoEE588wzS09+JsmHH36Ye++9N88//3zuvffe0hLyZ511Vh5//PHSuFmzZuXPf/5z/va3v+X3v/99dtlll6/8rr73ve/lzjvvTFVVVW644YbccMMN2WSTTdK5c+fsuuuu2XHHHas1Cxc2evTodOvWLdOnT08yf7n/hx56KGPHjs2NN95YGvdNa5w1a1a6d++eV199tTR2/PjxGThwYAYPHpw77rgj//Vf//WV9wMAAAB8te233z79+/fPiBEjMmnSpDRo0CAvvfRS6dzitqrbY489csUVV2T69Ol5++23c/zxx2ettdbKdtttl5122il77713qVexOpg1a1ZGjBiRu+66K0my8cYbZ+utty6d/zZ9oYVNnjw5Rx11VLXveubMmXnnnXfyzjvv5JNPPslll122yLy+fftW65uMHj06l19+eRo2bJgDDzwwSTJhwoQcdthhGT16dGnc+PHjS7X96le/yv/3//1/SeZvwXf66adX60G99dZbufjii/P666/n17/+9Vd+T/vvv3/+93//N1VVVXnllVdyxBFHpFGjRtl+++3z3//939lzzz3TsGHDJc4/9dRTqz009/e//z3HHXdcBg0alObNmy91jffcc08uvvjiaqtLDRs2LMOGDct7772X008//SvvBwBY/qxABQAsE2PGjCmFnjp16pRWrVplzz33TGVlZZLk0UcfLYVZlsW8BcaOHZvPPvssH374YV588cWceuqppae0dtttt2V6j9/WkCFDSk/jbbbZZtl2221Ljab
2023-05-23 20:54:46 +00:00
"text/plain": [
2023-05-23 20:55:18 +00:00
"<Figure size 2400x1200 with 2 Axes>"
2023-05-23 20:54:46 +00:00
]
},
"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",
" fig, axes = plt.subplots(1, num_charts, figsize=(12*num_charts, 12), sharey=True)\n",
"\n",
2023-05-23 20:55:18 +00:00
" \n",
2023-05-23 20:54:46 +00:00
" 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",
2023-05-23 20:55:18 +00:00
" sns.set(style=\"whitegrid\") \n",
2023-05-23 20:54:46 +00:00
"\n",
" ax = axes[i]\n",
2023-05-23 20:55:18 +00:00
" asset_labels = ['Total Assets & Current Assets', ' Total Debt & Current Debt']\n",
" asset_values = [selected_data.iloc[0]['TotalAssets'], selected_data.iloc[0]['CurrentAssets']]\n",
" current_asset_values = [0, selected_data.iloc[0]['CurrentAssets']]\n",
" ax.bar(range(len(asset_labels)), asset_values, color=['green', 'red'], label='Assets', alpha=0.5)\n",
" ax.bar(range(len(asset_labels)), current_asset_values, color=['white', 'red'], alpha=0.5)\n",
"\n",
" \n",
" debt_labels = ['Total Debt/ Current Debt', '']\n",
" debt_values = [selected_data.iloc[0]['TotalDebt'], selected_data.iloc[0]['CurrentDebt']]\n",
" current_debt_values = [0, selected_data.iloc[0]['CurrentDebt']]\n",
" ax.bar(range(len(debt_labels)), debt_values, color=['darkgreen', 'darkred'], label='Debts')\n",
" ax.bar(range(len(debt_labels)), current_debt_values, color=['white', 'darkred'])\n",
"\n",
" ax.set_title(f'{ticker} - Balance Sheet', fontproperties=font, fontsize=14, weight='bold')\n",
2023-05-23 20:54:46 +00:00
" ax.set_xlabel(ticker, fontproperties=font)\n",
" ax.set_ylabel('Amount in $', fontproperties=font)\n",
2023-05-23 20:55:18 +00:00
" ax.set_xticks(range(len(asset_labels))) \n",
" ax.set_xticklabels(asset_labels, fontproperties=font)\n",
2023-05-23 20:54:46 +00:00
"\n",
"\n",
2023-05-23 20:55:18 +00:00
" ax.xaxis.grid(False)\n",
" ax.yaxis.grid(False)\n",
2023-05-23 20:54:46 +00:00
"\n",
2023-05-23 20:55:18 +00:00
" \n",
" green_patch = plt.Line2D([0], [0], color='green', alpha=0.5, linewidth=0, marker='s')\n",
" red_patch = plt.Line2D([0], [0], color='red', alpha=0.5, linewidth=0, marker='s')\n",
" ax.legend([green_patch, red_patch], ['Assets', 'Debts'], loc='best')\n",
"\n",
"\n",
" plt.tight_layout() \n",
2023-05-23 20:54:46 +00:00
" plt.show()\n",
"\n",
2023-05-23 20:55:18 +00:00
"ticker_list = ['AAPL', 'MSFT']\n",
2023-05-23 20:54:46 +00:00
"compare_balance_sheets(ticker_list)\n",
2023-05-23 20:55:18 +00:00
"\n",
2023-05-23 20:54:46 +00:00
"\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
}