{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "89287518",
   "metadata": {},
   "outputs": [],
   "source": [
    "import datetime\n",
    "import pandas as pd\n",
    "import time\n",
    "import numpy as np\n",
    "import math"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ffc15a64",
   "metadata": {},
   "outputs": [],
   "source": [
    "name='%5ENSEI'\n",
    "days= 6000\n",
    "future_period=5\n",
    "input_period=60\n",
    "minimum_change=1.004\n",
    "validation_size=0.2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "51f00d62",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "t2=int(time.mktime((datetime.date.today() - datetime.timedelta(1)).timetuple())+19800)\n",
    "t1=int(time.mktime((datetime.date.today() - datetime.timedelta(days)).timetuple())+19800)\n",
    "url='https://query1.finance.yahoo.com/v7/finance/download/' \\\n",
    "                +name+'?period1='+str(t1)+'&period2='+str(t2)+'&interval=1d&events=history&includeAdjustedClose=true'\n",
    "\n",
    "df=  pd.read_csv(url).dropna(axis=0)\n",
    "df.Date=pd.to_datetime(df.Date)\n",
    "df.set_index('Date',inplace=True)\n",
    "df.drop(columns='Volume', inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e02a5f7e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "425b7d2b",
   "metadata": {},
   "outputs": [],
   "source": [
    "df['future']=(df['Adj Close'].shift(-future_period).div(df['Adj Close'])-1)*100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a553a133",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.iloc[:,:-1]=df.iloc[:,:-1].pct_change()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7ee05964",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.dropna(axis=0, inplace= True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "22612f42",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bc61fea6",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import MinMaxScaler\n",
    "scale=MinMaxScaler()\n",
    "x= df.iloc[:,:-1].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d4dbaed3",
   "metadata": {},
   "outputs": [],
   "source": [
    "x=[x[i:i+input_period] for i,j in enumerate(x) if len(x[i:i+input_period])==input_period]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1a3608ba",
   "metadata": {},
   "outputs": [],
   "source": [
    "X= np.array([1])\n",
    "for i in x:\n",
    "    X=np.append(X,i)\n",
    "x=X[1:]\n",
    "del X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "04832c85",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "104cc642",
   "metadata": {},
   "outputs": [],
   "source": [
    "x=x.reshape(-1,input_period, len(df.iloc[:,:-1].columns))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "db1826c7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bbef5acc",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c40b993a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f7bf8711",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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
}
