diff --git a/.ipynb_checkpoints/stock_market(complete)-checkpoint.ipynb b/.ipynb_checkpoints/stock_market(complete)-checkpoint.ipynb new file mode 100644 index 0000000..0cc81a2 --- /dev/null +++ b/.ipynb_checkpoints/stock_market(complete)-checkpoint.ipynb @@ -0,0 +1,2811 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "id": "Rqr4Dq5vWXmV" + }, + "outputs": [], + "source": [ + "# importing modules\n", + "import numpy as np\n", + "import pandas as pd\n", + "import matplotlib.pyplot as plt\n", + "import seaborn as sns\n", + "\n", + "from sklearn.model_selection import train_test_split\n", + "from sklearn.impute import SimpleImputer\n", + "from sklearn.preprocessing import MinMaxScaler, StandardScaler\n", + "from sklearn.linear_model import LinearRegression\n", + "from sklearn.metrics import mean_squared_error, mean_absolute_error, mean_absolute_percentage_error, accuracy_score, precision_score, confusion_matrix, recall_score, f1_score\n", + "\n", + "from sklearn.model_selection import GridSearchCV\n", + "\n", + "from sklearn.svm import SVR\n", + "from sklearn.ensemble import RandomForestRegressor, AdaBoostRegressor, GradientBoostingRegressor\n", + "from sklearn.tree import DecisionTreeRegressor\n", + "from sklearn.neighbors import KNeighborsRegressor\n", + "from tensorflow.keras.models import Sequential\n", + "from tensorflow.keras.layers import Dense,LSTM\n" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "id": "BigUM4vtWZdc" + }, + "outputs": [], + "source": [ + "# Load data\n", + "df = pd.read_csv(\"SBIN.csv\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "RqOe6KPNWs8Q" + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "vAcMar5WXELR" + }, + "source": [ + "## Data Analysis and Visualization" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 206 + }, + "id": "vkDxEavVXHqv", + "outputId": "279f15e7-d2d2-442a-c162-e7db9780f2c7" + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + " | Date | \n", + "Open | \n", + "High | \n", + "Low | \n", + "Close | \n", + "Adj Close | \n", + "Volume | \n", + "
---|---|---|---|---|---|---|---|
0 | \n", + "01-01-1996 | \n", + "18.691147 | \n", + "18.978922 | \n", + "18.540184 | \n", + "18.823240 | \n", + "12.409931 | \n", + "43733533.0 | \n", + "
1 | \n", + "02-01-1996 | \n", + "18.894005 | \n", + "18.964767 | \n", + "17.738192 | \n", + "18.224106 | \n", + "12.014931 | \n", + "56167280.0 | \n", + "
2 | \n", + "03-01-1996 | \n", + "18.327892 | \n", + "18.568489 | \n", + "17.643839 | \n", + "17.738192 | \n", + "11.694577 | \n", + "68296318.0 | \n", + "
3 | \n", + "04-01-1996 | \n", + "17.502312 | \n", + "17.832542 | \n", + "17.223972 | \n", + "17.676863 | \n", + "11.654142 | \n", + "86073880.0 | \n", + "
4 | \n", + "05-01-1996 | \n", + "17.738192 | \n", + "17.785366 | \n", + "17.459852 | \n", + "17.577793 | \n", + "11.588827 | \n", + "76613039.0 | \n", + "
\n", + " | Open | \n", + "High | \n", + "Low | \n", + "Close | \n", + "Adj Close | \n", + "Volume | \n", + "
---|---|---|---|---|---|---|
count | \n", + "7065.000000 | \n", + "7065.000000 | \n", + "7065.000000 | \n", + "7065.000000 | \n", + "7065.000000 | \n", + "7.065000e+03 | \n", + "
mean | \n", + "180.682841 | \n", + "183.085167 | \n", + "177.998209 | \n", + "180.448294 | \n", + "166.021712 | \n", + "3.130217e+07 | \n", + "
std | \n", + "154.773229 | \n", + "156.345078 | \n", + "152.980516 | \n", + "154.630549 | \n", + "152.903249 | \n", + "3.462744e+07 | \n", + "
min | \n", + "13.478195 | \n", + "13.935802 | \n", + "13.214009 | \n", + "13.346102 | \n", + "9.531410 | \n", + "0.000000e+00 | \n", + "
25% | \n", + "28.423565 | \n", + "28.824560 | \n", + "28.022570 | \n", + "28.456589 | \n", + "19.854374 | \n", + "1.299123e+07 | \n", + "
50% | \n", + "173.100006 | \n", + "176.500000 | \n", + "170.250000 | \n", + "172.925003 | \n", + "152.411270 | \n", + "2.064292e+07 | \n", + "
75% | \n", + "265.500000 | \n", + "268.899994 | \n", + "261.299988 | \n", + "265.174988 | \n", + "245.764954 | \n", + "3.651478e+07 | \n", + "
max | \n", + "703.650024 | \n", + "728.349976 | \n", + "694.200012 | \n", + "725.250000 | \n", + "725.250000 | \n", + "4.469483e+08 | \n", + "
\n", + " | Date | \n", + "Open | \n", + "High | \n", + "Low | \n", + "Close | \n", + "Adj Close | \n", + "Volume | \n", + "
---|---|---|---|---|---|---|---|
0 | \n", + "01-01-1996 | \n", + "18.691147 | \n", + "18.978922 | \n", + "18.540184 | \n", + "18.823240 | \n", + "12.409931 | \n", + "43733533.0 | \n", + "
1 | \n", + "02-01-1996 | \n", + "18.894005 | \n", + "18.964767 | \n", + "17.738192 | \n", + "18.224106 | \n", + "12.014931 | \n", + "56167280.0 | \n", + "
2 | \n", + "03-01-1996 | \n", + "18.327892 | \n", + "18.568489 | \n", + "17.643839 | \n", + "17.738192 | \n", + "11.694577 | \n", + "68296318.0 | \n", + "
3 | \n", + "04-01-1996 | \n", + "17.502312 | \n", + "17.832542 | \n", + "17.223972 | \n", + "17.676863 | \n", + "11.654142 | \n", + "86073880.0 | \n", + "
4 | \n", + "05-01-1996 | \n", + "17.738192 | \n", + "17.785366 | \n", + "17.459852 | \n", + "17.577793 | \n", + "11.588827 | \n", + "76613039.0 | \n", + "
\n", + " | Open | \n", + "High | \n", + "Low | \n", + "Close | \n", + "Adj Close | \n", + "Volume | \n", + "
---|---|---|---|---|---|---|
count | \n", + "7065.000000 | \n", + "7065.000000 | \n", + "7065.000000 | \n", + "7065.000000 | \n", + "7065.000000 | \n", + "7.065000e+03 | \n", + "
mean | \n", + "180.682841 | \n", + "183.085167 | \n", + "177.998209 | \n", + "180.448294 | \n", + "166.021712 | \n", + "3.130217e+07 | \n", + "
std | \n", + "154.773229 | \n", + "156.345078 | \n", + "152.980516 | \n", + "154.630549 | \n", + "152.903249 | \n", + "3.462744e+07 | \n", + "
min | \n", + "13.478195 | \n", + "13.935802 | \n", + "13.214009 | \n", + "13.346102 | \n", + "9.531410 | \n", + "0.000000e+00 | \n", + "
25% | \n", + "28.423565 | \n", + "28.824560 | \n", + "28.022570 | \n", + "28.456589 | \n", + "19.854374 | \n", + "1.299123e+07 | \n", + "
50% | \n", + "173.100006 | \n", + "176.500000 | \n", + "170.250000 | \n", + "172.925003 | \n", + "152.411270 | \n", + "2.064292e+07 | \n", + "
75% | \n", + "265.500000 | \n", + "268.899994 | \n", + "261.299988 | \n", + "265.174988 | \n", + "245.764954 | \n", + "3.651478e+07 | \n", + "
max | \n", + "703.650024 | \n", + "728.349976 | \n", + "694.200012 | \n", + "725.250000 | \n", + "725.250000 | \n", + "4.469483e+08 | \n", + "
\n", + " | Open | \n", + "High | \n", + "Low | \n", + "Close | \n", + "Adj Close | \n", + "Volume | \n", + "Date | \n", + "
---|---|---|---|---|---|---|---|
0 | \n", + "18.691147 | \n", + "18.978922 | \n", + "18.540184 | \n", + "18.823240 | \n", + "12.409931 | \n", + "43733533.0 | \n", + "0 | \n", + "
1 | \n", + "18.894005 | \n", + "18.964767 | \n", + "17.738192 | \n", + "18.224106 | \n", + "12.014931 | \n", + "56167280.0 | \n", + "222 | \n", + "
2 | \n", + "18.327892 | \n", + "18.568489 | \n", + "17.643839 | \n", + "17.738192 | \n", + "11.694577 | \n", + "68296318.0 | \n", + "442 | \n", + "
3 | \n", + "17.502312 | \n", + "17.832542 | \n", + "17.223972 | \n", + "17.676863 | \n", + "11.654142 | \n", + "86073880.0 | \n", + "678 | \n", + "
4 | \n", + "17.738192 | \n", + "17.785366 | \n", + "17.459852 | \n", + "17.577793 | \n", + "11.588827 | \n", + "76613039.0 | \n", + "914 | \n", + "
\n", + " | Open | \n", + "High | \n", + "Low | \n", + "Close | \n", + "Volume | \n", + "MA_50 | \n", + "MA_200 | \n", + "MA_20 | \n", + "Upper_BB | \n", + "Lower_BB | \n", + "SMA_10 | \n", + "SMA_50 | \n", + "RSI | \n", + "EMA_12 | \n", + "EMA_26 | \n", + "MACD | \n", + "Signal_Line | \n", + "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Open | \n", + "1.000000 | \n", + "0.999812 | \n", + "0.999793 | \n", + "0.999613 | \n", + "-0.246129 | \n", + "0.985126 | \n", + "0.936083 | \n", + "0.994502 | \n", + "0.993450 | \n", + "0.992257 | \n", + "0.998788 | \n", + "0.992463 | \n", + "0.060667 | \n", + "0.998913 | \n", + "0.997290 | \n", + "0.201107 | \n", + "0.211920 | \n", + "
High | \n", + "0.999812 | \n", + "1.000000 | \n", + "0.999717 | \n", + "0.999829 | \n", + "-0.243362 | \n", + "0.985031 | \n", + "0.935987 | \n", + "0.994398 | \n", + "0.993568 | \n", + "0.991903 | \n", + "0.998675 | \n", + "0.992366 | \n", + "0.063160 | \n", + "0.998821 | \n", + "0.997184 | \n", + "0.201486 | \n", + "0.211589 | \n", + "
Low | \n", + "0.999793 | \n", + "0.999717 | \n", + "1.000000 | \n", + "0.999819 | \n", + "-0.247681 | \n", + "0.984818 | \n", + "0.936005 | \n", + "0.994254 | \n", + "0.992972 | \n", + "0.992266 | \n", + "0.998567 | \n", + "0.992135 | \n", + "0.064062 | \n", + "0.998719 | \n", + "0.997029 | \n", + "0.202962 | \n", + "0.212715 | \n", + "
Close | \n", + "0.999613 | \n", + "0.999829 | \n", + "0.999819 | \n", + "1.000000 | \n", + "-0.244964 | \n", + "0.984837 | \n", + "0.935956 | \n", + "0.994232 | \n", + "0.993180 | \n", + "0.991986 | \n", + "0.998513 | \n", + "0.992144 | \n", + "0.065853 | \n", + "0.998676 | \n", + "0.996998 | \n", + "0.202614 | \n", + "0.212016 | \n", + "
Volume | \n", + "-0.246129 | \n", + "-0.243362 | \n", + "-0.247681 | \n", + "-0.244964 | \n", + "1.000000 | \n", + "-0.241808 | \n", + "-0.156613 | \n", + "-0.247522 | \n", + "-0.241989 | \n", + "-0.252852 | \n", + "-0.247841 | \n", + "-0.247594 | \n", + "0.051904 | \n", + "-0.247778 | \n", + "-0.248238 | \n", + "-0.025686 | \n", + "-0.041019 | \n", + "
MA_50 | \n", + "0.985126 | \n", + "0.985031 | \n", + "0.984818 | \n", + "0.984837 | \n", + "-0.241808 | \n", + "1.000000 | \n", + "0.954341 | \n", + "0.992381 | \n", + "0.991173 | \n", + "0.990316 | \n", + "0.987473 | \n", + "0.992357 | \n", + "-0.008551 | \n", + "0.988224 | \n", + "0.990678 | \n", + "0.085060 | \n", + "0.103564 | \n", + "
MA_200 | \n", + "0.936083 | \n", + "0.935987 | \n", + "0.936005 | \n", + "0.935956 | \n", + "-0.156613 | \n", + "0.954341 | \n", + "1.000000 | \n", + "0.943263 | \n", + "0.942357 | \n", + "0.941031 | \n", + "0.938292 | \n", + "0.947045 | \n", + "-0.005434 | \n", + "0.939204 | \n", + "0.942774 | \n", + "0.046120 | \n", + "0.050529 | \n", + "
MA_20 | \n", + "0.994502 | \n", + "0.994398 | \n", + "0.994254 | \n", + "0.994232 | \n", + "-0.247522 | \n", + "0.992381 | \n", + "0.943263 | \n", + "1.000000 | \n", + "0.998546 | \n", + "0.998185 | \n", + "0.996501 | \n", + "0.993994 | \n", + "0.010021 | \n", + "0.996732 | \n", + "0.996960 | \n", + "0.148834 | \n", + "0.176405 | \n", + "
Upper_BB | \n", + "0.993450 | \n", + "0.993568 | \n", + "0.992972 | \n", + "0.993180 | \n", + "-0.241989 | \n", + "0.991173 | \n", + "0.942357 | \n", + "0.998546 | \n", + "1.000000 | \n", + "0.993487 | \n", + "0.995246 | \n", + "0.992805 | \n", + "0.013123 | \n", + "0.995469 | \n", + "0.995654 | \n", + "0.149849 | \n", + "0.175100 | \n", + "
Lower_BB | \n", + "0.992257 | \n", + "0.991903 | \n", + "0.992266 | \n", + "0.991986 | \n", + "-0.252852 | \n", + "0.990316 | \n", + "0.941031 | \n", + "0.998185 | \n", + "0.993487 | \n", + "1.000000 | \n", + "0.994474 | \n", + "0.991904 | \n", + "0.006521 | \n", + "0.994714 | \n", + "0.994990 | \n", + "0.147187 | \n", + "0.177256 | \n", + "
SMA_10 | \n", + "0.998788 | \n", + "0.998675 | \n", + "0.998567 | \n", + "0.998513 | \n", + "-0.247841 | \n", + "0.987473 | \n", + "0.938292 | \n", + "0.996501 | \n", + "0.995246 | \n", + "0.994474 | \n", + "1.000000 | \n", + "0.994842 | \n", + "0.036431 | \n", + "0.999915 | \n", + "0.999055 | \n", + "0.179858 | \n", + "0.201548 | \n", + "
SMA_50 | \n", + "0.992463 | \n", + "0.992366 | \n", + "0.992135 | \n", + "0.992144 | \n", + "-0.247594 | \n", + "0.992357 | \n", + "0.947045 | \n", + "0.993994 | \n", + "0.992805 | \n", + "0.991904 | \n", + "0.994842 | \n", + "1.000000 | \n", + "-0.009370 | \n", + "0.995598 | \n", + "0.998145 | \n", + "0.083592 | \n", + "0.101745 | \n", + "
RSI | \n", + "0.060667 | \n", + "0.063160 | \n", + "0.064062 | \n", + "0.065853 | \n", + "0.051904 | \n", + "-0.008551 | \n", + "-0.005434 | \n", + "0.010021 | \n", + "0.013123 | \n", + "0.006521 | \n", + "0.036431 | \n", + "-0.009370 | \n", + "1.000000 | \n", + "0.033634 | \n", + "0.013165 | \n", + "0.579522 | \n", + "0.425595 | \n", + "
EMA_12 | \n", + "0.998913 | \n", + "0.998821 | \n", + "0.998719 | \n", + "0.998676 | \n", + "-0.247778 | \n", + "0.988224 | \n", + "0.939204 | \n", + "0.996732 | \n", + "0.995469 | \n", + "0.994714 | \n", + "0.999915 | \n", + "0.995598 | \n", + "0.033634 | \n", + "1.000000 | \n", + "0.999384 | \n", + "0.173035 | \n", + "0.193561 | \n", + "
EMA_26 | \n", + "0.997290 | \n", + "0.997184 | \n", + "0.997029 | \n", + "0.996998 | \n", + "-0.248238 | \n", + "0.990678 | \n", + "0.942774 | \n", + "0.996960 | \n", + "0.995654 | \n", + "0.994990 | \n", + "0.999055 | \n", + "0.998145 | \n", + "0.013165 | \n", + "0.999384 | \n", + "1.000000 | \n", + "0.138353 | \n", + "0.160681 | \n", + "
MACD | \n", + "0.201107 | \n", + "0.201486 | \n", + "0.202962 | \n", + "0.202614 | \n", + "-0.025686 | \n", + "0.085060 | \n", + "0.046120 | \n", + "0.148834 | \n", + "0.149849 | \n", + "0.147187 | \n", + "0.179858 | \n", + "0.083592 | \n", + "0.579522 | \n", + "0.173035 | \n", + "0.138353 | \n", + "1.000000 | \n", + "0.952623 | \n", + "
Signal_Line | \n", + "0.211920 | \n", + "0.211589 | \n", + "0.212715 | \n", + "0.212016 | \n", + "-0.041019 | \n", + "0.103564 | \n", + "0.050529 | \n", + "0.176405 | \n", + "0.175100 | \n", + "0.177256 | \n", + "0.201548 | \n", + "0.101745 | \n", + "0.425595 | \n", + "0.193561 | \n", + "0.160681 | \n", + "0.952623 | \n", + "1.000000 | \n", + "