Skip to content

Commit

Permalink
2023/08/20
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave4272-Office committed Aug 20, 2023
1 parent 972f076 commit 1dfb28c
Show file tree
Hide file tree
Showing 11 changed files with 472 additions and 1,050 deletions.
32 changes: 0 additions & 32 deletions .ipynb_checkpoints/Linux-checkpoint.ipynb

This file was deleted.

174 changes: 174 additions & 0 deletions Investing & Trading/CompanyAnalysis.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "fc7f7b82-7485-4a42-8b61-d49e8b596032",
"metadata": {},
"source": [
"# Company Fundamentals Analysis"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "12fad49b",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import yfinance as yf\n",
"import yahooquery as yq\n",
"import math"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "0a07214e",
"metadata": {},
"outputs": [],
"source": [
"hold = pd.read_csv(\"holdtyped.csv\", index_col=0)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "030a1ad2",
"metadata": {},
"outputs": [],
"source": [
"holdings = hold.loc[hold[\"Type\"] == \"EQ\"]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "882f712b",
"metadata": {},
"outputs": [],
"source": [
"holdings.columns = pd.MultiIndex.from_tuples([(x,\"\") for x in holdings.columns], names=[\"Header\", \"Sub-Header\"])"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "b881d60d",
"metadata": {},
"outputs": [],
"source": [
"fin = pd.DataFrame(yq.Ticker(\"TCS.NS\").income_statement('a',False))[\"asOfDate\"]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "e872825a",
"metadata": {},
"outputs": [],
"source": [
"cols = [ x for x in fin ]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "5cd098b3",
"metadata": {},
"outputs": [],
"source": [
"holdings = holdings.set_index(\"Symbol\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "4c2630e2",
"metadata": {},
"outputs": [],
"source": [
"sym = holdings.index"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "55a40ac5",
"metadata": {},
"outputs": [],
"source": [
"financials = pd.DataFrame(yq.Ticker(list(sym)).income_statement('a',False))\n",
"financials = financials.swapaxes(\"columns\",\"index\")"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "1a6f8a11",
"metadata": {},
"outputs": [],
"source": [
"financials.columns = pd.MultiIndex.from_arrays([financials.columns, financials.loc[\"asOfDate\"].values])"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "d927f4c7",
"metadata": {},
"outputs": [],
"source": [
"for i in holdings.index:\n",
" basicEPS = financials.loc[\"BasicEPS\", i]\n",
" for j in cols:\n",
" try:\n",
" if math.isnan(basicEPS[j]):\n",
" raise Exception(\"NA\")\n",
" holdings.loc[i, (\"Basic EPS\",j)] = basicEPS[j]\n",
" except:\n",
" holdings.loc[i, (\"Basic EPS\",j)] = None"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "edcf114b",
"metadata": {},
"outputs": [],
"source": [
"holdings = holdings.reset_index()\n",
"holdings.to_csv(\"eqholdweps.csv\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e0bd6546",
"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.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 1dfb28c

Please sign in to comment.