-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
1 addition
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"cells":[{"cell_type":"markdown","metadata":{"id":"cEGf_vPrhNa6"},"source":["### This is a Tutorial Notebook to get started with CTO as soon as possible, without any frills\n","- We will be attempting to view stock price slopes\n","- Prequisites:\n"," - pip install all requirements as in the requirements.txt\n"," - Navigate to https://zenodo.org/doi/10.5281/zenodo.11535960 (this link always resolves to the latest version), and download the latest version of CTO!\n"," I downloaded the v0.3 supplementary.zip, and unzipped it in the parent directory.\n"," ```bash\n"," wget https://zenodo.org/records/11608615/files/supplementary.zip -P ../\n"," unzip ../supplementary.zip -d ../\n"," ```\n"," - Follow the setup instructions in stock_price\n","\n","- Slope calculation in stock_price/slope_calculation.ipynb"]},{"cell_type":"code","execution_count":2,"metadata":{"id":"hQBfgx63hNa_","outputId":"3b102a3d-b274-403b-e614-12147e4d5ca4"},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n"," .dataframe tbody tr th:only-of-type {\n"," vertical-align: middle;\n"," }\n","\n"," .dataframe tbody tr th {\n"," vertical-align: top;\n"," }\n","\n"," .dataframe thead th {\n"," text-align: right;\n"," }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n"," <thead>\n"," <tr style=\"text-align: right;\">\n"," <th></th>\n"," <th>nct_id</th>\n"," <th>Ticker</th>\n"," <th>name</th>\n"," <th>Slope</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n"," <td>NCT04023084</td>\n"," <td>PFE</td>\n"," <td>Pfizer</td>\n"," <td>-0.275547</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>NCT01656278</td>\n"," <td>ABT</td>\n"," <td>Abbott</td>\n"," <td>0.108502</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>NCT03267732</td>\n"," <td>LLY</td>\n"," <td>Eli Lilly and Company</td>\n"," <td>0.256033</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n"," <td>NCT02456844</td>\n"," <td>BMY</td>\n"," <td>Bristol-Myers Squibb</td>\n"," <td>-0.252119</td>\n"," </tr>\n"," <tr>\n"," <th>4</th>\n"," <td>NCT03259542</td>\n"," <td>CORT</td>\n"," <td>Corcept Therapeutics</td>\n"," <td>-0.152000</td>\n"," </tr>\n"," <tr>\n"," <th>...</th>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," </tr>\n"," <tr>\n"," <th>19879</th>\n"," <td>NCT01431898</td>\n"," <td>GILD</td>\n"," <td>Gilead Sciences</td>\n"," <td>0.037673</td>\n"," </tr>\n"," <tr>\n"," <th>19880</th>\n"," <td>NCT01445119</td>\n"," <td>LLY</td>\n"," <td>Eli Lilly and Company</td>\n"," <td>0.033443</td>\n"," </tr>\n"," <tr>\n"," <th>19881</th>\n"," <td>NCT01730339</td>\n"," <td>PFE</td>\n"," <td>Pfizer</td>\n"," <td>0.023169</td>\n"," </tr>\n"," <tr>\n"," <th>19882</th>\n"," <td>NCT01509755</td>\n"," <td>NVO</td>\n"," <td>Novo Nordisk A/S</td>\n"," <td>-0.009617</td>\n"," </tr>\n"," <tr>\n"," <th>19883</th>\n"," <td>NCT01630746</td>\n"," <td>TAK</td>\n"," <td>Takeda</td>\n"," <td>-0.034800</td>\n"," </tr>\n"," </tbody>\n","</table>\n","<p>19884 rows × 4 columns</p>\n","</div>"],"text/plain":[" nct_id Ticker name Slope\n","0 NCT04023084 PFE Pfizer -0.275547\n","1 NCT01656278 ABT Abbott 0.108502\n","2 NCT03267732 LLY Eli Lilly and Company 0.256033\n","3 NCT02456844 BMY Bristol-Myers Squibb -0.252119\n","4 NCT03259542 CORT Corcept Therapeutics -0.152000\n","... ... ... ... ...\n","19879 NCT01431898 GILD Gilead Sciences 0.037673\n","19880 NCT01445119 LLY Eli Lilly and Company 0.033443\n","19881 NCT01730339 PFE Pfizer 0.023169\n","19882 NCT01509755 NVO Novo Nordisk A/S -0.009617\n","19883 NCT01630746 TAK Takeda -0.034800\n","\n","[19884 rows x 4 columns]"]},"execution_count":2,"metadata":{},"output_type":"execute_result"}],"source":["# ============ loading the zipped data, viewing all collected tickers, company names and slopes at completion date ============\n","import numpy as np\n","import pandas as pd\n","import os\n","import glob\n","import yfinance as yf\n","\n","slope_df = pd.read_csv('../supplementary/stock_price/labels_and_tickers.csv', index_col=0)\n","slope_df[['nct_id', 'Ticker', 'name', 'Slope']]"]},{"cell_type":"markdown","metadata":{},"source":["looking at the stock price records of a specific company"]},{"cell_type":"code","execution_count":6,"metadata":{},"outputs":[{"data":{"text/html":["<div>\n","<style scoped>\n"," .dataframe tbody tr th:only-of-type {\n"," vertical-align: middle;\n"," }\n","\n"," .dataframe tbody tr th {\n"," vertical-align: top;\n"," }\n","\n"," .dataframe thead th {\n"," text-align: right;\n"," }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n"," <thead>\n"," <tr style=\"text-align: right;\">\n"," <th></th>\n"," <th>Open</th>\n"," <th>High</th>\n"," <th>Low</th>\n"," <th>Close</th>\n"," <th>Volume</th>\n"," <th>Dividends</th>\n"," <th>Stock Splits</th>\n"," </tr>\n"," <tr>\n"," <th>Date</th>\n"," <th></th>\n"," <th></th>\n"," <th></th>\n"," <th></th>\n"," <th></th>\n"," <th></th>\n"," <th></th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>1972-06-01 00:00:00-04:00</th>\n"," <td>0.000000</td>\n"," <td>0.163931</td>\n"," <td>0.161448</td>\n"," <td>0.163931</td>\n"," <td>2458771</td>\n"," <td>0.0</td>\n"," <td>0.0</td>\n"," </tr>\n"," <tr>\n"," <th>1972-06-02 00:00:00-04:00</th>\n"," <td>0.163931</td>\n"," <td>0.164428</td>\n"," <td>0.161448</td>\n"," <td>0.161944</td>\n"," <td>1613885</td>\n"," <td>0.0</td>\n"," <td>0.0</td>\n"," </tr>\n"," <tr>\n"," <th>1972-06-05 00:00:00-04:00</th>\n"," <td>0.161944</td>\n"," <td>0.162441</td>\n"," <td>0.160454</td>\n"," <td>0.161448</td>\n"," <td>2585251</td>\n"," <td>0.0</td>\n"," <td>0.0</td>\n"," </tr>\n"," <tr>\n"," <th>1972-06-06 00:00:00-04:00</th>\n"," <td>0.161448</td>\n"," <td>0.165918</td>\n"," <td>0.160951</td>\n"," <td>0.164925</td>\n"," <td>2347469</td>\n"," <td>0.0</td>\n"," <td>0.0</td>\n"," </tr>\n"," <tr>\n"," <th>1972-06-07 00:00:00-04:00</th>\n"," <td>0.164925</td>\n"," <td>0.164925</td>\n"," <td>0.162441</td>\n"," <td>0.164925</td>\n"," <td>1032077</td>\n"," <td>0.0</td>\n"," <td>0.0</td>\n"," </tr>\n"," <tr>\n"," <th>...</th>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," </tr>\n"," <tr>\n"," <th>2024-06-28 00:00:00-04:00</th>\n"," <td>27.780001</td>\n"," <td>28.120001</td>\n"," <td>27.639999</td>\n"," <td>27.980000</td>\n"," <td>33189200</td>\n"," <td>0.0</td>\n"," <td>0.0</td>\n"," </tr>\n"," <tr>\n"," <th>2024-07-01 00:00:00-04:00</th>\n"," <td>27.950001</td>\n"," <td>28.629999</td>\n"," <td>27.940001</td>\n"," <td>28.219999</td>\n"," <td>26209000</td>\n"," <td>0.0</td>\n"," <td>0.0</td>\n"," </tr>\n"," <tr>\n"," <th>2024-07-02 00:00:00-04:00</th>\n"," <td>28.219999</td>\n"," <td>28.280001</td>\n"," <td>27.690001</td>\n"," <td>27.830000</td>\n"," <td>21989800</td>\n"," <td>0.0</td>\n"," <td>0.0</td>\n"," </tr>\n"," <tr>\n"," <th>2024-07-03 00:00:00-04:00</th>\n"," <td>27.920000</td>\n"," <td>28.049999</td>\n"," <td>27.620001</td>\n"," <td>27.700001</td>\n"," <td>15180100</td>\n"," <td>0.0</td>\n"," <td>0.0</td>\n"," </tr>\n"," <tr>\n"," <th>2024-07-05 00:00:00-04:00</th>\n"," <td>27.760000</td>\n"," <td>28.090000</td>\n"," <td>27.670000</td>\n"," <td>28.049999</td>\n"," <td>17259500</td>\n"," <td>0.0</td>\n"," <td>0.0</td>\n"," </tr>\n"," </tbody>\n","</table>\n","<p>13135 rows × 7 columns</p>\n","</div>"],"text/plain":[" Open High Low Close \\\n","Date \n","1972-06-01 00:00:00-04:00 0.000000 0.163931 0.161448 0.163931 \n","1972-06-02 00:00:00-04:00 0.163931 0.164428 0.161448 0.161944 \n","1972-06-05 00:00:00-04:00 0.161944 0.162441 0.160454 0.161448 \n","1972-06-06 00:00:00-04:00 0.161448 0.165918 0.160951 0.164925 \n","1972-06-07 00:00:00-04:00 0.164925 0.164925 0.162441 0.164925 \n","... ... ... ... ... \n","2024-06-28 00:00:00-04:00 27.780001 28.120001 27.639999 27.980000 \n","2024-07-01 00:00:00-04:00 27.950001 28.629999 27.940001 28.219999 \n","2024-07-02 00:00:00-04:00 28.219999 28.280001 27.690001 27.830000 \n","2024-07-03 00:00:00-04:00 27.920000 28.049999 27.620001 27.700001 \n","2024-07-05 00:00:00-04:00 27.760000 28.090000 27.670000 28.049999 \n","\n"," Volume Dividends Stock Splits \n","Date \n","1972-06-01 00:00:00-04:00 2458771 0.0 0.0 \n","1972-06-02 00:00:00-04:00 1613885 0.0 0.0 \n","1972-06-05 00:00:00-04:00 2585251 0.0 0.0 \n","1972-06-06 00:00:00-04:00 2347469 0.0 0.0 \n","1972-06-07 00:00:00-04:00 1032077 0.0 0.0 \n","... ... ... ... \n","2024-06-28 00:00:00-04:00 33189200 0.0 0.0 \n","2024-07-01 00:00:00-04:00 26209000 0.0 0.0 \n","2024-07-02 00:00:00-04:00 21989800 0.0 0.0 \n","2024-07-03 00:00:00-04:00 15180100 0.0 0.0 \n","2024-07-05 00:00:00-04:00 17259500 0.0 0.0 \n","\n","[13135 rows x 7 columns]"]},"execution_count":6,"metadata":{},"output_type":"execute_result"}],"source":["#example ticker to get historical data. We used PFE (Pfizer Inc.) for the analysis\n","ticker = 'PFE'\n","\n","stock = yf.Ticker(ticker)\n","\n","# Retrieve historical market data\n","hist = stock.history(period=\"max\")\n","\n","#print(hist)\n","hist\n"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["#we used 'Close' price for the analysis in the paper"]}],"metadata":{"colab":{"provenance":[]},"kernelspec":{"display_name":"dp","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.9.7"}},"nbformat":4,"nbformat_minor":0} |