Files
OpenBB/gamestonk_terminal/reports/due_diligence.ipynb
2022-01-01 17:24:32 +00:00

279 lines
7.0 KiB
Plaintext
Vendored

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "phantom-facility",
"metadata": {},
"outputs": [],
"source": [
"# Import most generic modules\n",
"import importlib\n",
"import pathlib\n",
"import os\n",
"import sys\n",
"from datetime import datetime, timedelta\n",
"import pandas as pd\n",
"from IPython.display import display, Markdown\n",
"import warnings\n",
"warnings.filterwarnings('ignore')\n",
"module_path = os.path.abspath(os.path.join('../..'))\n",
"\n",
"if module_path not in sys.path:\n",
" sys.path.append(module_path)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "compact-count",
"metadata": {
"tags": [
"parameters"
]
},
"outputs": [],
"source": [
"# Parameters that will be replaced when calling this notebook\n",
"ticker=\"GME\"\n",
"\n",
"report_name=f\"{datetime.now().strftime('%Y%m%d_%H%M%S')}_due_diligence_{ticker.upper()}\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "possible-constraint",
"metadata": {},
"outputs": [],
"source": [
"display(Markdown(f\"# {ticker.upper()} - Due Diligence - {datetime.now().strftime('%Y/%m/%d %H:%M:%S')}\"))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3a473d25",
"metadata": {},
"outputs": [],
"source": [
"base_path=os.path.abspath(os.path.join('.'))\n",
"report_cache_dir = pathlib.Path(base_path, \"gamestonk_terminal\", \"reports\", \"stored\")\n",
" \n",
"if not os.path.isdir(report_cache_dir):\n",
" print(\"Reports data directory not found.\")\n",
" print(f\"Creating {report_cache_dir}\")\n",
" os.mkdir(report_cache_dir);\n",
"else:\n",
" print(f\"Found reports directory {report_cache_dir}\")"
]
},
{
"cell_type": "markdown",
"id": "temporal-clerk",
"metadata": {},
"source": [
"## Candle View"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d783ed59-1fb2-44f2-b4b0-bfdfee9afcb6",
"metadata": {},
"outputs": [],
"source": [
"from gamestonk_terminal.stocks import stocks_helper\n",
"\n",
"df_stock_cache = pathlib.Path(report_cache_dir, f\"{ticker}_stock_data.pkl\")\n",
"if os.path.isfile(df_stock_cache):\n",
" print(f\"Found a cache file. Loading {df_stock_cache}\")\n",
" df_stock = pd.read_pickle(df_stock_cache)\n",
"else:\n",
" print(\"Cache file not found. Getting data.\")\n",
" df_stock = stocks_helper.load_ticker(ticker, (datetime.now() - timedelta(days=180)).strftime(\"%Y-%m-%d\"))\n",
" df_stock = stocks_helper.find_trendline(df_stock, \"OC_High\", \"high\")\n",
" df_stock = stocks_helper.find_trendline(df_stock, \"OC_Low\", \"low\")\n",
" print(f\"Saving cache file {ticker}_stock_data.pkl\")\n",
" df_stock.to_pickle(df_stock_cache)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "transsexual-trance",
"metadata": {},
"outputs": [],
"source": [
"import mplfinance as mpf\n",
"\n",
"mc = mpf.make_marketcolors(up='green',down='red',\n",
" edge='black',\n",
" wick='black',\n",
" volume='in',\n",
" ohlc='i')\n",
"s = mpf.make_mpf_style(marketcolors=mc, gridstyle=\":\", y_on_right=True)\n",
"\n",
"ap0 = []\n",
"\n",
"if \"OC_High_trend\" in df_stock.columns:\n",
" ap0.append(\n",
" mpf.make_addplot(df_stock[\"OC_High_trend\"], color=\"g\"),\n",
" )\n",
"\n",
"if \"OC_Low_trend\" in df_stock.columns:\n",
" ap0.append(\n",
" mpf.make_addplot(df_stock[\"OC_Low_trend\"], color=\"b\"),\n",
" )\n",
" \n",
"mpf.plot(df_stock,type='candle',mav=(20,50,200),volume=True, addplot=ap0,\n",
" xrotation=0, style=s, figratio=(10,7), figscale=2.00, \n",
" update_width_config=dict(candle_linewidth=1.0,candle_width=0.8, volume_linewidth=1.0))"
]
},
{
"cell_type": "markdown",
"id": "political-intake",
"metadata": {},
"source": [
"## Analyst Targets"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "numerous-begin",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"from gamestonk_terminal.stocks.due_diligence import finviz_view\n",
"\n",
"try:\n",
" finviz_view.analyst(ticker=ticker, export='')\n",
"except Exception as e:\n",
" print(e)"
]
},
{
"cell_type": "markdown",
"id": "3cfd302c",
"metadata": {},
"source": [
"## Fundamentals"
]
},
{
"cell_type": "markdown",
"id": "written-lease",
"metadata": {},
"source": [
"### Annual Income Statement"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "played-vancouver",
"metadata": {},
"outputs": [],
"source": [
"from gamestonk_terminal.stocks.fundamental_analysis import av_view\n",
"\n",
"av_view.display_income_statement(ticker, limit=1)"
]
},
{
"cell_type": "markdown",
"id": "smooth-forge",
"metadata": {},
"source": [
"### Quarterly Income Statement"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "juvenile-throw",
"metadata": {},
"outputs": [],
"source": [
"from gamestonk_terminal.stocks.fundamental_analysis import av_view\n",
"\n",
"av_view.display_income_statement(ticker, limit=1, quarterly=True)"
]
},
{
"cell_type": "markdown",
"id": "passive-nerve",
"metadata": {},
"source": [
"### Annual Balance Sheet"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "nominated-empire",
"metadata": {},
"outputs": [],
"source": [
"from gamestonk_terminal.stocks.fundamental_analysis import av_view\n",
"av_view.display_balance_sheet(ticker, limit=1)"
]
},
{
"cell_type": "markdown",
"id": "special-bargain",
"metadata": {},
"source": [
"### Annual Cash Flow"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "focused-thanks",
"metadata": {},
"outputs": [],
"source": [
"from gamestonk_terminal.stocks.fundamental_analysis import av_view\n",
"av_view.display_cash_flow(ticker, limit=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "sought-phase",
"metadata": {},
"outputs": [],
"source": [
"!jupyter nbconvert {report_name + \".ipynb\"} --to html --no-input"
]
}
],
"metadata": {
"celltoolbar": "Tags",
"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.8.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}