mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-14 13:21:05 +00:00
218 lines
5.5 KiB
Plaintext
218 lines
5.5 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "blank-couple",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import importlib\n",
|
|
"import pathlib\n",
|
|
"import os\n",
|
|
"import sys\n",
|
|
"from datetime import datetime, timedelta\n",
|
|
"import pandas as pd\n",
|
|
"module_path = os.path.abspath(os.path.join('../..'))\n",
|
|
"if module_path not in sys.path:\n",
|
|
" sys.path.append(module_path)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "exact-price",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"datetime.now()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "naked-shower",
|
|
"metadata": {
|
|
"tags": [
|
|
"parameters"
|
|
]
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"ticker=\"GME\"\n",
|
|
"report_name=f\"{ticker}_{datetime.now().strftime('%Y%m%d_%H%M%S')}_due_diligence\"\n",
|
|
"base_path=os.path.abspath(os.path.join('.'))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "moderate-cheat",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"report_cache_dir = pathlib.Path(base_path, \"notebooks\", \"reports\", report_name)\n",
|
|
"if not os.path.isdir(report_cache_dir):\n",
|
|
" print(f\"Reports data directory not found. Creating {report_cache_dir}\")\n",
|
|
" os.mkdir(report_cache_dir)\n",
|
|
"else:\n",
|
|
" print(f\"Found reports directory {report_cache_dir}\")\n",
|
|
" print(os.listdir(report_cache_dir))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "southern-gnome",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from gamestonk_terminal.technical_analysis import trendline_api as trend\n",
|
|
"from gamestonk_terminal.due_diligence import finviz_view as finviz"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "impressive-pleasure",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"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 = trend.load_ticker(ticker, (datetime.now() - timedelta(days=180)).strftime(\"%Y-%m-%d\"))\n",
|
|
" df_stock = trend.find_trendline(df_stock, \"OC_High\", \"high\")\n",
|
|
" df_stock = trend.find_trendline(df_stock, \"OC_Low\", \"how\")\n",
|
|
" print(\"Savind cache file\")\n",
|
|
" df_stock.to_pickle(df_stock_cache)\n",
|
|
" print(os.listdir(report_cache_dir))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "jewish-birthday",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import mplfinance as mpf\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",
|
|
" )"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "separated-oasis",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"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": "code",
|
|
"execution_count": null,
|
|
"id": "danish-stadium",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"df_fa = finviz.analyst_df(ticker)\n",
|
|
"df_fa"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "israeli-eugene",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from gamestonk_terminal.fundamental_analysis import market_watch_api as mw"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "tough-percentage",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"mw.prepare_df_financials(ticker, \"income\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "critical-electronics",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"mw.prepare_df_financials(ticker, \"income\", quarter=True)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "clear-expense",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"mw.prepare_df_financials(ticker, \"balance\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "agreed-topic",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"mw.prepare_df_financials(ticker, \"cashflow\")"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"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.8"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
} |