Python Will Make You Rich in The Stock Market
Python Will Make You Rich in The Stock Market
Python Will Make You Rich in The Stock Market
stock market!
Free Python course with 57 real-time projects - Learn Python in Hindi | Learn Python
in English
a. Fundamental Analysis
This includes analyzing the current business environment and finances to
predict the future profitability of the company.
b. Technical Analysis
This deals with charts and statistics to identify trends in the stock market.
Linear Regression
Linear Regression linearly models the relationship between a dependent variable
and one or more independent variables. This is simple to implement and is
used for predicting numeric values. But this is prone to overfitting and can’t be
used where there’s a non-linear relationship between dependent and
independent variables.
2. Get the Amazon stock data from quandl. Print the top 5 rows.
3. Now get only the data for the Adjusted Close column. Print the first 5 rows
for this.
#DataFlair - Get only the data for the Adjusted Close column
amazon = amazon[['Adj. Close']]
print(amazon.head())
4. Set the forecast length to 30 days. Create a new column ‘Predicted’- this
should have the data of the Adj. Close column shifted up by 30 rows. The last 5
rows will have NaN values for this column.
#DataFlair - Predict for 30 days; Predicted has the data of Adj. Close shifted up by 30 rows
forecast_len=30
amazon['Predicted'] = amazon[['Adj. Close']].shift(-forecast_len)
print(amazon.tail())
5. Now, drop the predicted column and create a NumPy array from it, call it
‘x’. This is the independent dataset. Remove the last 30 rows and print x.
#DataFlair - Drop the Predicted column, turn it into a NumPy array to create dataset
x=np.array(amazon.drop(['Predicted'],1))
#DataFlair - Remove last 30 rows
x=x[:-forecast_len]
print(x)
6. Create a dependent dataset y and remove the last 30 rows. Print it then.
#DataFlair - Create dependent dataset for predicted values, remove the last 30 rows
y=np.array(amazon['Predicted'])
y=y[:-forecast_len]
print(y)
7. Split the datasets into training and testing sets. Keep 80% for training.
#DataFlair - Split datasets into training and test sets (80% and 20%)
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2)
10. Now, create a model for Linear Regression and train it.
11. Get the score for this model and print it in percentage.
Additive tools
These are very powerful for analyzing and predicting time series. We know
that the long term trend of any established multinational company seems to be
increasing in nature but there is a possibility of identifying yearly or daily
basis patterns. Such help of time series with daily observations can be
provided by Prophet, developed by Facebook. Stocker can do all the work that
be done by Prophet behind the scenes using simple method call to create and
inspect the model.
These types of models remove disturbance present in data and smoothen it.
Prophet models also look into fluctuations of data in real-life processes and
make predictions for the future. Though there is concern related to past data
but future data analysis is what companies strive for. This method call returns
two objects (data and model) which are then assigned to variables that are
later on used to plot time series components.
Explore top Python Applications to know more about the use of Python
Changepoints
It occurs when the time-series go from increasing to decreasing or vice-versa.
These patterns are also very important as one needs to know when the stock
rate is at its peak or there are significant economic benefits. Identifying these
points and their cause of change helps in predicting the future. The stocker
object can automatically predict the 10 largest changepoints which tend to line
up near the peaks and valleys of the stock price graph (generally). On the other
hand, the prophet can only find changepoints in the first 80% data only.
Google search tools allow us to see the popularity of any search word over time
in Google searches. Stocker can automatically retrieve this data for any
specific term.
These are only the first half capabilities of the stocker where Python for stock
market is used. The second half –
Predictions
They are designed for forecasting, or predicting future prices. This is a
tiresome exercise and hence needs plenty of learning to get into the actual
process. The capabilities are publically available, even creating the tool itself.
Summary
We live in an age where anyone can learn programming or arts like data
science or machine learning without that much of formal instructions. The
idea can be anything, even stock prediction, python can be used in any sort of
application base. All you need is hands-on knowledge of it!