Skip to content

Commit 4543999

Browse files
authored
Merge pull request #106 from NVombat/nv/backend
🗑️ Cleanup
2 parents 95ec473 + 7395ab7 commit 4543999

9 files changed

+188
-5535
lines changed

analysis/Dynamic Analysis.ipynb

-832
This file was deleted.

analysis/dynamic_analysis.ipynb

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"# Imports\n",
10+
"import yfinance as yf\n",
11+
"import datetime as dt\n",
12+
"import pandas as pd\n",
13+
"import requests\n",
14+
"import time\n",
15+
"import io\n",
16+
"\n",
17+
"# Read data from URL containing NASDAQ listings\n",
18+
"url = \"https://pkgstore.datahub.io/core/nasdaq-listings/nasdaq-listed_csv/data/7665719fb51081ba0bd834fde71ce822/nasdaq-listed_csv.csv\"\n",
19+
"data = requests.get(url).content\n",
20+
"df = pd.read_csv(io.StringIO(data.decode(\"utf-8\")))\n",
21+
"df.head()"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": null,
27+
"metadata": {},
28+
"outputs": [],
29+
"source": [
30+
"symbols = df[\"Symbol\"].to_list()"
31+
]
32+
},
33+
{
34+
"cell_type": "code",
35+
"execution_count": null,
36+
"metadata": {},
37+
"outputs": [],
38+
"source": [
39+
"stock_id = input(\"Enter Stock ID:\")\n",
40+
"stock_id = stock_id.upper()\n",
41+
"\n",
42+
"if stock_id in symbols:\n",
43+
" df_stock = yf.download(stock_id, start=\"1950-01-01\", period=\"1d\")\n",
44+
" print(df_stock)\n",
45+
"else:\n",
46+
" print(\"Incorrect Stock Symbol. Please Enter Valid Symbols\")"
47+
]
48+
},
49+
{
50+
"cell_type": "code",
51+
"execution_count": null,
52+
"metadata": {},
53+
"outputs": [],
54+
"source": [
55+
"df_stock.drop(\"Adj Close\", axis=\"columns\", inplace=True)\n",
56+
"df_stock.head()"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": null,
62+
"metadata": {},
63+
"outputs": [],
64+
"source": [
65+
"# Reset index makes sure the dataframe has indexing of its own and converts the date index to a column\n",
66+
"df_stock.reset_index(inplace=True)\n",
67+
"df_stock.head()"
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": null,
73+
"metadata": {},
74+
"outputs": [],
75+
"source": [
76+
"# Convert the date to a datetime object (gets converted to a specialised type of datetime object)\n",
77+
"df_stock[\"Date\"] = pd.to_datetime(df_stock[\"Date\"])\n",
78+
"df_stock.Date.dtype"
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": null,
84+
"metadata": {},
85+
"outputs": [],
86+
"source": [
87+
"# Convert date to epoch datetime format\n",
88+
"df_stock[\"Date\"] = (df_stock[\"Date\"] - dt.datetime(1970, 1, 1)).dt.total_seconds()\n",
89+
"df_stock.head()"
90+
]
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": null,
95+
"metadata": {},
96+
"outputs": [],
97+
"source": [
98+
"df_stock.Date.dtype"
99+
]
100+
},
101+
{
102+
"cell_type": "code",
103+
"execution_count": null,
104+
"metadata": {},
105+
"outputs": [],
106+
"source": [
107+
"# Format for plotting requires specific size for date so multiply by 1000\n",
108+
"df_stock[\"Date\"] = df_stock[\"Date\"] * 1000\n",
109+
"df_stock.head()"
110+
]
111+
},
112+
{
113+
"cell_type": "code",
114+
"execution_count": null,
115+
"metadata": {},
116+
"outputs": [],
117+
"source": [
118+
"# Convert to json format and make sure its converted as json with arrays thus orient = values\n",
119+
"df_stock.to_json(\"data/\" + stock_id + \"_mod.json\", orient=\"values\")"
120+
]
121+
}
122+
],
123+
"metadata": {
124+
"kernelspec": {
125+
"display_name": "Python 3",
126+
"language": "python",
127+
"name": "python3"
128+
},
129+
"language_info": {
130+
"codemirror_mode": {
131+
"name": "ipython",
132+
"version": 3
133+
},
134+
"file_extension": ".py",
135+
"mimetype": "text/x-python",
136+
"name": "python",
137+
"nbconvert_exporter": "python",
138+
"pygments_lexer": "ipython3",
139+
"version": "3.8.5"
140+
}
141+
},
142+
"nbformat": 4,
143+
"nbformat_minor": 4
144+
}

analysis/Formatting.ipynb renamed to analysis/formatting.ipynb

-16
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@
227227
}
228228
],
229229
"source": [
230-
"# Drop the 'Adj Close' column\n",
231230
"df.drop(\"Adj Close\", axis=\"columns\", inplace=True)\n",
232231
"df.head()"
233232
]
@@ -254,21 +253,6 @@
254253
"df.Date.dtype"
255254
]
256255
},
257-
{
258-
"cell_type": "code",
259-
"execution_count": 7,
260-
"metadata": {},
261-
"outputs": [],
262-
"source": [
263-
"# Select Data from a specific date range\n",
264-
"# from pytz import utc\n",
265-
"# df_2020 = df[df['Date'] > dt.datetime(2019, 12, 31)]\n",
266-
"\n",
267-
"# Reset Indexing so index starts from 0 and it not duplicated\n",
268-
"# df_2020.reset_index(inplace=True, drop=True)\n",
269-
"# df_2020"
270-
]
271-
},
272256
{
273257
"cell_type": "code",
274258
"execution_count": 8,

analysis/Stock Price Substitute.ipynb renamed to analysis/stockprice_substitute.ipynb

-40
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,5 @@
11
{
22
"cells": [
3-
{
4-
"cell_type": "code",
5-
"execution_count": 3,
6-
"metadata": {},
7-
"outputs": [],
8-
"source": [
9-
"import yfinance as yf\n",
10-
"import json"
11-
]
12-
},
13-
{
14-
"cell_type": "code",
15-
"execution_count": 4,
16-
"metadata": {},
17-
"outputs": [],
18-
"source": [
19-
"symbol = \"GOOGL\"\n",
20-
"ticker = yf.Ticker(symbol)"
21-
]
22-
},
23-
{
24-
"cell_type": "code",
25-
"execution_count": 5,
26-
"metadata": {},
27-
"outputs": [
28-
{
29-
"data": {
30-
"text/plain": [
31-
"yfinance.Ticker object <GOOGL>"
32-
]
33-
},
34-
"execution_count": 5,
35-
"metadata": {},
36-
"output_type": "execute_result"
37-
}
38-
],
39-
"source": [
40-
"ticker"
41-
]
42-
},
433
{
444
"cell_type": "code",
455
"execution_count": 7,

0 commit comments

Comments
 (0)