Stock Price Technical Analysis
A case study on Stock Price Technical Analysis
1:Loading Stock data
1.1:Importing libraries and data
import investpy
from datetime import datetime
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import confusion_matrix
from sklearn import metrics
from scipy import stats
import numpy as np
import pandas as pd
import seaborn as sn
import matplotlib.pyplot as plt
import talib
import quandl
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import accuracy_score
from sklearn.preprocessing import MinMaxScaler
import math
from sklearn.metrics import mean_squared_error
import investpy
from pandas_datareader import data as pdr
import yfinance as yfin
from pandas_datareader import data
pd.core.common.is_list_like = pd.api.types.is_list_like
yfin.pdr_override()
1.2:Fetching the data
To fetch the stock data we use investpy
library. This library fetchs data from investing for example:
##
[*********************100%***********************] 1 of 1 completed
1.2.1: Determining position based on volume and close
## Open High Low Close Volume Pos
## Date
## 2022-08-10 20.450001 20.600000 20.309999 20.379999 5828.1 Long
## 2022-08-11 20.290001 20.420000 20.100000 20.150000 7446.9 Short
## 2022-08-12 20.049999 20.139999 19.950001 20.110001 4842.8 Short
## 2022-08-15 20.020000 20.150000 20.020000 20.110001 2987.5 Short
## 2022-08-16 20.049999 20.160000 19.990000 20.150000 7513.2 Long
## Open High Low Close Volume Pos \
## Date
## 2021-03-23 18.950001 18.950001 18.700001 18.709999 8851.0 Short
## 2021-04-07 19.330000 19.330000 19.160000 19.209999 4643.6 Short
## 2021-06-15 20.639999 20.639999 20.209999 20.230000 7477.4 Short
## 2021-09-16 23.350000 23.350000 22.969999 23.090000 6554.0 Short
## 2021-09-27 23.230000 23.230000 22.870001 22.900000 7458.8 Short
## 2021-10-26 22.900000 22.900000 22.590000 22.690001 5844.6 Short
## 2021-11-05 22.920000 22.920000 22.709999 22.790001 4723.1 Long
## 2021-12-13 23.040001 23.040001 22.580000 22.610001 4551.6 Short
## 2022-06-10 18.620001 18.620001 18.200001 18.330000 8787.0 Short
## 2022-07-26 18.090000 18.090000 17.840000 17.910000 13040.2 Short
##
## gain
## Date
## 2021-03-23 0.240002
## 2021-04-07 0.120001
## 2021-06-15 0.410000
## 2021-09-16 0.260000
## 2021-09-27 0.330000
## 2021-10-26 0.209999
## 2021-11-05 0.129999
## 2021-12-13 0.430000
## 2022-06-10 0.290001
## 2022-07-26 0.180000
## Open High Low Close Volume Pos \
## Date
## 2021-11-11 23.030001 23.280001 23.030001 23.200001 3639.4 Short
## 2021-12-27 24.860001 25.340000 24.860001 25.330000 3527.2 Long
## 2022-02-25 22.240000 22.870001 22.240000 22.840000 8269.3 Short
## 2022-03-10 23.540001 23.930000 23.540001 23.840000 7789.0 Short
## 2022-03-30 24.820000 25.170000 24.820000 24.969999 6945.5 Short
## 2022-04-27 19.990000 20.320000 19.990000 20.120001 9754.1 Short
## 2022-06-02 19.250000 19.520000 19.250000 19.510000 9397.7 Short
## 2022-06-17 17.520000 17.950001 17.520000 17.760000 13242.0 Long
## 2022-07-06 18.700001 19.020000 18.700001 18.930000 8860.2 Short
## 2022-08-15 20.020000 20.150000 20.020000 20.110001 2987.5 Short
##
## gain
## Date
## 2021-11-11 0.170000
## 2021-12-27 0.469999
## 2022-02-25 0.600000
## 2022-03-10 0.299999
## 2022-03-30 0.150000
## 2022-04-27 0.130001
## 2022-06-02 0.260000
## 2022-06-17 0.240000
## 2022-07-06 0.230000
## 2022-08-15 0.090000
1.2.2: Determining Average monthly closing prices
## Open High Low Close Adj Close Volume \
## Date
## 2014-01-02 0.007031 0.007031 0.006926 0.006941 5.529784 3642.4
## 2014-01-03 0.007144 0.007198 0.007111 0.007144 5.691106 8421.6
## 2014-01-06 0.007111 0.007114 0.007021 0.007039 5.607457 4820.0
## 2014-01-07 0.006976 0.007049 0.006956 0.007011 5.585548 6201.6
## 2014-01-08 0.006938 0.006970 0.006905 0.006970 5.552687 9640.0
## ... ... ... ... ... ... ...
## 2022-08-10 0.020450 0.020600 0.020310 0.020380 20.160707 5828.1
## 2022-08-11 0.020290 0.020420 0.020100 0.020150 19.933182 7446.9
## 2022-08-12 0.020050 0.020140 0.019950 0.020110 19.893614 4842.8
## 2022-08-15 0.020020 0.020150 0.020020 0.020110 19.893614 2987.5
## 2022-08-16 0.020050 0.020160 0.019990 0.020150 19.933182 7513.2
##
## VolChange CloseChange
## Date
## 2014-01-02 0.109168 0.000648
## 2014-01-03 1.312102 0.029173
## 2014-01-06 -0.427662 -0.014698
## 2014-01-07 0.286639 -0.003907
## 2014-01-08 0.554438 -0.005883
## ... ... ...
## 2022-08-10 0.133850 0.009911
## 2022-08-11 0.277758 -0.011286
## 2022-08-12 -0.349689 -0.001985
## 2022-08-15 -0.383105 0.000000
## 2022-08-16 1.514879 0.001989
##
## [2171 rows x 8 columns]
## Date
## 2014-01-31 0.007337
## 2014-02-28 0.007403
## 2014-03-31 0.007064
## 2014-04-30 0.006706
## 2014-05-31 0.006595
## ...
## 2022-04-30 0.021800
## 2022-05-31 0.019310
## 2022-06-30 0.018640
## 2022-07-31 0.018665
## 2022-08-31 0.020085
## Freq: M, Name: Close, Length: 104, dtype: float64
## meanprice is 0.011315510710501442
1.2.3: Technical moving averages
1.2.4: Determining the z-scores
## Date
## 2022-08-10 1.793515
## 2022-08-11 1.748007
## 2022-08-12 1.740093
## 2022-08-15 1.740093
## 2022-08-16 1.748007
## Name: zscore, dtype: float64
## Date
## 2022-08-10 -0.735693
## 2022-08-11 -0.483587
## 2022-08-12 -0.889140
## 2022-08-15 -1.178078
## 2022-08-16 -0.473261
## Name: zscorevolume, dtype: float64
1.2.5: Determining the daily support and resistance levels
## PP R1 S1 R2 S2 R3 \
## Date
## 2022-08-10 0.020430 0.020550 0.020260 0.020720 0.020140 0.020840
## 2022-08-11 0.020223 0.020347 0.020027 0.020543 0.019903 0.020667
## 2022-08-12 0.020067 0.020183 0.019993 0.020257 0.019877 0.020373
## 2022-08-15 0.020093 0.020167 0.020037 0.020223 0.019963 0.020297
## 2022-08-16 0.020100 0.020210 0.020040 0.020270 0.019930 0.020380
##
## S3
## Date
## 2022-08-10 0.019970
## 2022-08-11 0.019707
## 2022-08-12 0.019803
## 2022-08-15 0.019907
## 2022-08-16 0.019870
1.2.6: Fibonnacci retracement levels
## Retracement levels for rising price
## 0
## 0 {'min': [0.019989999771118164]}
## 1 {'level5(61.8)': [0.02005493980026245]}
## 2 {'level4(50)': [0.020074999809265137]}
## 3 {'level3(38.2)': [0.020095059818267823]}
## 4 {'level2(23.6)': [0.020119879829406738]}
## 5 {'zero': [0.02015999984741211]}
## Retracement levels for falling price
## 0
## 0 {'zero': [0.02015999984741211]}
## 1 {'level2(23.6)': [0.020030119789123536]}
## 2 {'level3(38.2)': [0.02005493980026245]}
## 3 {'level4(50)': [0.020074999809265137]}
## 4 {'level5(61.8)': [0.020095059818267823]}
## 5 {'min': [0.019989999771118164]}
As we can see, we now have a data frame with all the entries from start date to end date. We have multiple columns here and not only the closing stock price of the respective day. Let’s take a quick look at the individual columns and their meaning.
Open:
That’s the share price the stock had when the markets opened that day.
Close:
That’s the share price the stock had when the markets closed that day.
High:
That’s the highest share price that the stock had that day.
Low:
That’s the lowest share price that the stock had that day.
Volume:
Amount of shares that changed hands that day.
1.3:Reading individual values
Since our data is stored in a Pandas data frame, we can use the indexing we already know, to get individual values. For example, we could only print the closing values using print (df[ 'Close' ])
Also, we can go ahead and print the closing value of a specific date that we are interested in. This is possible because the date is our index column.
#print (df[ 'Close' ][ '2020-07-14' ])
But we could also use simple indexing to access certain positions.
print (df[ 'Close' ][ 5 ])
## 0.0070187501907348635
Here we printed the closing price of the fifth entry.
2:Graphical Visualization
Even though tables are nice and useful, we want to visualize our financial data, in order to get a better overview. We want to look at the development of the share price.
Actually plotting our share price curve with Pandas and Matplotlib is very simple. Since Pandas builds on top of Matplotlib, we can just select the column we are interested in and apply the plot method. The results are amazing. Since the date is the index of our data frame, Matplotlib uses it for the x-axis. The y-values are then our adjusted close values.
2.1:CandleStick Charts
The best way to visualize stock data is to use so-called candlestick charts . This type of chart gives us information about four different values at the same time, namely the high, the low, the open and the close value. In order to plot candlestick charts, we will need to import a function of the MPL-Finance library.
import mplfinance as fplt
We are importing the candlestick_ohlc function. Notice that there also exists a candlestick_ochl function that takes in the data in a different order. Also, for our candlestick chart, we will need a different date format provided by Matplotlib. Therefore, we need to import the respective module as well. We give it the alias mdates .
import matplotlib.dates as mdates
2.2: Preparing the data for CandleStick charts
Now in order to plot our stock data, we need to select the four columns in the right order.
df1 = df[[ 'Open' , 'High' , 'Low' , 'Close' ]]
Now, we have our columns in the right order but there is still a problem. Our date doesn’t have the right format and since it is the index, we cannot manipulate it. Therefore, we need to reset the index and then convert our datetime to a number.
df1.reset_index( inplace = True )
df1[ 'Date' ] = df1[ 'Date' ].map(mdates.date2num)
## <string>:1: SettingWithCopyWarning:
## A value is trying to be set on a copy of a slice from a DataFrame.
## Try using .loc[row_indexer,col_indexer] = value instead
##
## See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
For this, we use the reset_index function so that we can manipulate our Date column. Notice that we are using the inplace parameter to replace the data frame by the new one. After that, we map the date2num function of the matplotlib.dates module on all of our values. That converts our dates into numbers that we can work with.
2.3:Plotting the data
Now we can start plotting our graph. For this, we just define a subplot (because we need to pass one to our function) and call our candlestick_ohlc function.
One candlestick gives us the information about all four values of one specific day. The highest point of the stick is the high and the lowest point is the low of that day. The colored area is the difference between the open and the close price. If the stick is green, the close value is at the top and the open value at the bottom, since the close must be higher than the open. If it is red, it is the other way around.
***2.4:Analysis and Statistics ***
Now let’s get a little bit deeper into the numbers here and away from the visual. From our data we can derive some statistical values that will help us to analyze it.
PERCENTAGE CHANGE
One value that we can calculate is the percentage change of that day. This means by how many percent the share price increased or decreased that day.
The calculation is quite simple. We create a new column with the name PCT_Change and the values are just the difference of the closing and opening values divided by the opening values. Since the open value is the beginning value of that day, we take it as a basis. We could also multiply the result by 100 to get the actual percentage.
## PCT_Change
## count 2171.000000
## mean 0.000242
## std 0.011127
## min -0.074667
## 25% -0.005621
## 50% 0.000000
## 75% 0.006442
## max 0.070588
## Close
## Date
## 2022-08-16 0.02015
*** HIGH LOW PERCENTAGE
***
Another interesting statistic is the high low percentage. Here we just calculate the difference between the highest and the lowest value and divide it by the closing value.
By doing that we can get a feeling of how volatile the stock is.
## Open High Low Close Adj Close ... Open-Open \
## Date ...
## 2022-08-10 0.02045 0.02060 0.02031 0.02038 20.160707 ... 0.00027
## 2022-08-11 0.02029 0.02042 0.02010 0.02015 19.933182 ... -0.00016
## 2022-08-12 0.02005 0.02014 0.01995 0.02011 19.893614 ... -0.00024
## 2022-08-15 0.02002 0.02015 0.02002 0.02011 19.893614 ... -0.00003
## 2022-08-16 0.02005 0.02016 0.01999 0.02015 19.933182 ... 0.00003
##
## zscore zscorevolume PCT_Change HL_PCT
## Date
## 2022-08-10 1.793515 -0.735693 -0.003423 0.014230
## 2022-08-11 1.748007 -0.483587 -0.006900 0.015881
## 2022-08-12 1.740093 -0.889140 0.002993 0.009448
## 2022-08-15 1.740093 -1.178078 0.004496 0.006464
## 2022-08-16 1.748007 -0.473261 0.004988 0.008437
##
## [5 rows x 14 columns]
These statistical values can be used with many others to get a lot of valuable information about specific stocks. This improves the decision making
*** MOVING AVERAGE
***
we are going to derive the different moving averages . It is the arithmetic mean of all the values of the past n days. Of course this is not the only key statistic that we can derive, but it is the one we are going to use now. We can play around with other functions as well.
What we are going to do with this value is to include it into our data frame and to compare it with the share price of that day.
For this, we will first need to create a new column. Pandas does this automatically when we assign values to a column name. This means that we don’t have to explicitly define that we are creating a new column.
## Close 5d_ma 20d_ma 50d_ma 100d_ma ... 5d_ema 20d_ema \
## Date ...
## 2022-08-08 0.02027 0.02 0.02 0.02 0.02 ... 0.02 0.02
## 2022-08-09 0.02018 0.02 0.02 0.02 0.02 ... 0.02 0.02
## 2022-08-10 0.02038 0.02 0.02 0.02 0.02 ... 0.02 0.02
## 2022-08-11 0.02015 0.02 0.02 0.02 0.02 ... 0.02 0.02
## 2022-08-12 0.02011 0.02 0.02 0.02 0.02 ... 0.02 0.02
## 2022-08-15 0.02011 0.02 0.02 0.02 0.02 ... 0.02 0.02
## 2022-08-16 0.02015 0.02 0.02 0.02 0.02 ... 0.02 0.02
##
## 50d_ema 100d_ema 200d_ema
## Date
## 2022-08-08 0.02 0.02 0.02
## 2022-08-09 0.02 0.02 0.02
## 2022-08-10 0.02 0.02 0.02
## 2022-08-11 0.02 0.02 0.02
## 2022-08-12 0.02 0.02 0.02
## 2022-08-15 0.02 0.02 0.02
## 2022-08-16 0.02 0.02 0.02
##
## [7 rows x 11 columns]
Here we define a three new columns with the name 20d_ma, 50d_ma, 100d_ma,200d_ma . We now fill this column with the mean values of every n entries. The rolling function stacks a specific amount of entries, in order to make a statistical calculation possible. The window parameter is the one which defines how many entries we are going to stack. But there is also the min_periods parameter. This one defines how many entries we need to have as a minimum in order to perform the calculation. This is relevant because the first entries of our data frame won’t have a n entries previous to them. By setting this value to zero we start the calculations already with the first number, even if there is not a single previous value. This has the effect that the first value will be just the first number, the second one will be the mean of the first two numbers and so on, until we get to a b values.
By using the mean function, we are obviously calculating the arithmetic mean. However, we can use a bunch of other functions like max, min or median if we like to.
*** Standard Deviation
***
The variability of the closing stock prices determinies how vo widely prices are dispersed from the average price. If the prices are trading in narrow trading range the standard deviation will return a low value that indicates low volatility. If the prices are trading in wide trading range the standard deviation will return high value that indicates high volatility.
## Date
## 2022-08-08 0.000370
## 2022-08-09 0.000326
## 2022-08-10 0.000297
## 2022-08-11 0.000102
## 2022-08-12 0.000100
## 2022-08-15 0.000105
## 2022-08-16 0.000099
## Name: Std_dev, dtype: float64
*** Relative Strength Index
***
The relative strength index is a indicator of mementum used in technical analysis that measures the magnitude of current price changes to know overbought or oversold conditions in the price of a stock or other asset. If RSI is above 70 then it is overbought. If RSI is below 30 then it is oversold condition.
## RSI
## Date
## 2022-08-10 70.215399
## 2022-08-11 62.897491
## 2022-08-12 61.640604
## 2022-08-15 61.640604
## 2022-08-16 62.586825
*** Average True range
***
## ATR 20dayEMA ATRdiff
## Date
## 2022-08-10 0.000398 0.000444 -0.000046
## 2022-08-11 0.000392 0.000439 -0.000047
## 2022-08-12 0.000378 0.000433 -0.000055
## 2022-08-15 0.000361 0.000426 -0.000066
## 2022-08-16 0.000347 0.000419 -0.000072
*** Wiliams %R
***
Williams %R, or just %R, is a technical analysis oscillator showing the current closing price in relation to the high and low of the past N days.The oscillator is on a negative scale, from −100 (lowest) up to 0 (highest). A value of −100 means the close today was the lowest low of the past N days, and 0 means today’s close was the highest high of the past N days.
## Williams %R
## Date
## 2022-08-08 -10.377241
## 2022-08-09 -19.417388
## 2022-08-10 -18.965625
## 2022-08-11 -51.136388
## 2022-08-12 -75.384624
## 2022-08-15 -75.384624
## 2022-08-16 -69.230927
Readings below -80 represent oversold territory and readings above -20 represent overbought.
*** ADX
***
ADX is used to quantify trend strength. ADX calculations are based on a moving average of price range expansion over a given period of time. The average directional index (ADX) is used to determine when the price is trending strongly.
0-25: Absent or Weak Trend
25-50: Strong Trend
50-75: Very Strong Trend
75-100: Extremely Strong Trend
## ADX
## Date
## 2022-08-08 37.641580
## 2022-08-09 38.551145
## 2022-08-10 41.068843
## 2022-08-11 40.206448
## 2022-08-12 37.511612
## 2022-08-15 35.289665
## 2022-08-16 32.920780
## CCI
## Date
## 2022-08-08 112.110256
## 2022-08-09 88.411328
## 2022-08-10 99.468246
## 2022-08-11 67.914648
## 2022-08-12 43.763722
## 2022-08-15 38.402583
## 2022-08-16 31.315216
*** MACD
***
Moving Average Convergence Divergence (MACD) is a trend-following momentum indicator that shows the relationship between two moving averages of a security’s price. The MACD is calculated by subtracting the 26-period Exponential Moving Average (EMA) from the 12-period EMA.
## MACD_IND
## Date
## 2022-08-10 0.000150
## 2022-08-11 0.000117
## 2022-08-12 0.000085
## 2022-08-15 0.000057
## 2022-08-16 0.000036
*** Bollinger Bands
***
Bollinger Bands are a type of statistical chart characterizing the prices and volatility over time of a financial instrument or commodity.
## 0.2 0.2 0.2
In case we choose another value than zero for our min_periods parameter, we will end up with a couple of NaN-Values . These are not a number values and they are useless. Therefore, we would want to delete the entries that have such values.
We do this by using the dropna function. If we would have had any entries with NaN values in any column, they would now have been deleted
3: Predicting the movement of stock
To predict the movement of the stock we use 5 lag returns as the dependent variables. The first leg is return yesterday, leg2 is return day before yesterday and so on. The dependent variable is whether the prices went up or down on that day. Other variables include the technical indicators which along with 5 lag returns are used to predict the movement of stock using logistic regression.
3.1: Creating lag returns
3.2: Creating returns dataframe
3.2: create the lagged percentage returns columns
## Today Lag1 Lag2 Lag3 Lag4 Lag5 \
## Date
## 2022-08-03 3.129813 -0.662595 0.667014 1.775458 2.351687 4.466774
## 2022-08-04 0.248752 3.129813 -0.662595 0.667014 1.775458 2.351687
## 2022-08-05 0.794044 0.248752 3.129813 -0.662595 0.667014 1.775458
## 2022-08-08 -0.196942 0.794044 0.248752 3.129813 -0.662595 0.667014
## 2022-08-09 -0.444007 -0.196942 0.794044 0.248752 3.129813 -0.662595
## 2022-08-10 0.991075 -0.444007 -0.196942 0.794044 0.248752 3.129813
## 2022-08-11 -1.128555 0.991075 -0.444007 -0.196942 0.794044 0.248752
## 2022-08-12 -0.198506 -1.128555 0.991075 -0.444007 -0.196942 0.794044
## 2022-08-15 0.000000 -0.198506 -1.128555 0.991075 -0.444007 -0.196942
## 2022-08-16 0.198901 0.000000 -0.198506 -1.128555 0.991075 -0.444007
##
## Lag6
## Date
## 2022-08-03 -3.502153
## 2022-08-04 4.466774
## 2022-08-05 2.351687
## 2022-08-08 1.775458
## 2022-08-09 0.667014
## 2022-08-10 -0.662595
## 2022-08-11 3.129813
## 2022-08-12 0.248752
## 2022-08-15 0.794044
## 2022-08-16 -0.196942
3.3: “Direction” column (+1 or -1) indicating an up/down day
***3.4: Create the dependent and independent variables ***
## <string>:1: SettingWithCopyWarning:
## A value is trying to be set on a copy of a slice from a DataFrame.
## Try using .loc[row_indexer,col_indexer] = value instead
##
## See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
## Lag1 Lag2 Lag3 Lag4 Lag5 ... CCI \
## Date ...
## 2022-08-10 -0.444007 -0.196942 0.794044 0.248752 3.129813 ... 99.468246
## 2022-08-11 0.991075 -0.444007 -0.196942 0.794044 0.248752 ... 67.914648
## 2022-08-12 -1.128555 0.991075 -0.444007 -0.196942 0.794044 ... 43.763722
## 2022-08-15 -0.198506 -1.128555 0.991075 -0.444007 -0.196942 ... 38.402583
## 2022-08-16 0.000000 -0.198506 -1.128555 0.991075 -0.444007 ... 31.315216
##
## ROC DX Open-Close Open-Open
## Date
## 2022-08-10 8.925709 36.520132 0.00027 0.00027
## 2022-08-11 5.221932 28.113701 -0.00009 -0.00016
## 2022-08-12 3.181123 22.319824 -0.00010 -0.00024
## 2022-08-15 2.497450 22.571233 -0.00009 -0.00003
## 2022-08-16 3.386351 21.302859 -0.00006 0.00003
##
## [5 rows x 29 columns]
3.5: Create training and test sets
***3.6: Create model ***
3.7: train the model on the training set
<style>#sk-container-id-1 {color: black;background-color: white;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: "▸";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: "▾";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: "";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: "";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: "";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}</style><div id="sk-container-id-1" class="sk-top-container"><div class="sk-text-repr-fallback"><pre>LogisticRegression()</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class="sk-container" hidden><div class="sk-item"><div class="sk-estimator sk-toggleable"><input class="sk-toggleable__control sk-hidden--visually" id="sk-estimator-id-1" type="checkbox" checked><label for="sk-estimator-id-1" class="sk-toggleable__label sk-toggleable__label-arrow">LogisticRegression</label><div class="sk-toggleable__content"><pre>LogisticRegression()</pre></div></div></div></div></div>
3.8: make an array of predictions on the test set
3.9: output the hit-rate and the confusion matrix for the model
##
## Train Accuracy: 98.68%
## Test Accuracy: 97.06%
## [[189 1]
## [ 11 207]]
***3.10: Predict movement of stock for tomorrow. ***
## y_test y_pred
## Date
## 2022-08-10 1 1
## 2022-08-11 -1 -1
## 2022-08-12 -1 -1
## 2022-08-15 -1 -1
## 2022-08-16 1 1
## [1]