Format: application/octet-stream
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": null,
6 "id": "89287518",
7 "metadata": {},
8 "outputs": [],
9 "source": [
10 "import datetime\n",
11 "import pandas as pd\n",
12 "import time\n",
13 "import numpy as np\n",
14 "import math"
15 ]
16 },
17 {
18 "cell_type": "code",
19 "execution_count": null,
20 "id": "ffc15a64",
21 "metadata": {},
22 "outputs": [],
23 "source": [
24 "name='%5ENSEI'\n",
25 "days= 6000\n",
26 "future_period=5\n",
27 "input_period=60\n",
28 "minimum_change=1.004\n",
29 "validation_size=0.2"
30 ]
31 },
32 {
33 "cell_type": "code",
34 "execution_count": null,
35 "id": "51f00d62",
36 "metadata": {
37 "scrolled": true
38 },
39 "outputs": [],
40 "source": [
41 "t2=int(time.mktime((datetime.date.today() - datetime.timedelta(1)).timetuple())+19800)\n",
42 "t1=int(time.mktime((datetime.date.today() - datetime.timedelta(days)).timetuple())+19800)\n",
43 "url='https://query1.finance.yahoo.com/v7/finance/download/' \\\n",
44 " +name+'?period1='+str(t1)+'&period2='+str(t2)+'&interval=1d&events=history&includeAdjustedClose=true'\n",
45 "\n",
46 "df= pd.read_csv(url).dropna(axis=0)\n",
47 "df.Date=pd.to_datetime(df.Date)\n",
48 "df.set_index('Date',inplace=True)\n",
49 "df.drop(columns='Volume', inplace=True)"
50 ]
51 },
52 {
53 "cell_type": "code",
54 "execution_count": null,
55 "id": "e02a5f7e",
56 "metadata": {},
57 "outputs": [],
58 "source": []
59 },
60 {
61 "cell_type": "code",
62 "execution_count": null,
63 "id": "425b7d2b",
64 "metadata": {},
65 "outputs": [],
66 "source": [
67 "df['future']=(df['Adj Close'].shift(-future_period).div(df['Adj Close'])-1)*100"
68 ]
69 },
70 {
71 "cell_type": "code",
72 "execution_count": null,
73 "id": "a553a133",
74 "metadata": {},
75 "outputs": [],
76 "source": [
77 "df.iloc[:,:-1]=df.iloc[:,:-1].pct_change()"
78 ]
79 },
80 {
81 "cell_type": "code",
82 "execution_count": null,
83 "id": "7ee05964",
84 "metadata": {},
85 "outputs": [],
86 "source": [
87 "df.dropna(axis=0, inplace= True)"
88 ]
89 },
90 {
91 "cell_type": "code",
92 "execution_count": null,
93 "id": "22612f42",
94 "metadata": {
95 "scrolled": true
96 },
97 "outputs": [],
98 "source": [
99 "df"
100 ]
101 },
102 {
103 "cell_type": "code",
104 "execution_count": null,
105 "id": "bc61fea6",
106 "metadata": {},
107 "outputs": [],
108 "source": [
109 "from sklearn.preprocessing import MinMaxScaler\n",
110 "scale=MinMaxScaler()\n",
111 "x= df.iloc[:,:-1].values"
112 ]
113 },
114 {
115 "cell_type": "code",
116 "execution_count": null,
117 "id": "d4dbaed3",
118 "metadata": {},
119 "outputs": [],
120 "source": [
121 "x=[x[i:i+input_period] for i,j in enumerate(x) if len(x[i:i+input_period])==input_period]"
122 ]
123 },
124 {
125 "cell_type": "code",
126 "execution_count": null,
127 "id": "1a3608ba",
128 "metadata": {},
129 "outputs": [],
130 "source": [
131 "X= np.array([1])\n",
132 "for i in x:\n",
133 " X=np.append(X,i)\n",
134 "x=X[1:]\n",
135 "del X"
136 ]
137 },
138 {
139 "cell_type": "code",
140 "execution_count": null,
141 "id": "04832c85",
142 "metadata": {},
143 "outputs": [],
144 "source": []
145 },
146 {
147 "cell_type": "code",
148 "execution_count": null,
149 "id": "104cc642",
150 "metadata": {},
151 "outputs": [],
152 "source": [
153 "x=x.reshape(-1,input_period, len(df.iloc[:,:-1].columns))"
154 ]
155 },
156 {
157 "cell_type": "code",
158 "execution_count": null,
159 "id": "db1826c7",
160 "metadata": {},
161 "outputs": [],
162 "source": []
163 },
164 {
165 "cell_type": "code",
166 "execution_count": null,
167 "id": "bbef5acc",
168 "metadata": {},
169 "outputs": [],
170 "source": []
171 },
172 {
173 "cell_type": "code",
174 "execution_count": null,
175 "id": "c40b993a",
176 "metadata": {},
177 "outputs": [],
178 "source": []
179 },
180 {
181 "cell_type": "code",
182 "execution_count": null,
183 "id": "f7bf8711",
184 "metadata": {},
185 "outputs": [],
186 "source": []
187 }
188 ],
189 "metadata": {
190 "kernelspec": {
191 "display_name": "Python 3",
192 "language": "python",
193 "name": "python3"
194 },
195 "language_info": {
196 "codemirror_mode": {
197 "name": "ipython",
198 "version": 3
199 },
200 "file_extension": ".py",
201 "mimetype": "text/x-python",
202 "name": "python",
203 "nbconvert_exporter": "python",
204 "pygments_lexer": "ipython3",
205 "version": "3.8.8"
206 }
207 },
208 "nbformat": 4,
209 "nbformat_minor": 5
210 }
211