Silver Prices Prediction Using Machine Learning

Why I chose the silver to predict with Linear Regression?

As In the third week of July 2020, silver prices(SLV) broke out of the $14 to $20 price range in which they have been caged for the most part since the second half of 2014. After breaking out of this long held range, silver prices raced sharply higher, rising to an intraday high of $29.91 on 7 August basis the nearby active September Comex contract. This made the silver the most outperforming asset of the year.

 This gave me the idea of doing a project, to predict Silver with Machine learning Algorithm.

What is Machine Learning?

Machine learning is an application of artificial intelligence (AI) that provides systems the ability to automatically learn and improve from experience without being explicitly programmed. 

What is Linear Regression?

Linear regression may be defined as the statistical model that analyzes the linear relationship between a dependent variable with given set of independent variables.

Mathematically the relationship can be represented with the help of following equation −

Y = mX + b

Here, Y is the dependent variable we are trying to predict

X is the dependent variable we are using to make predictions.

m is the slop of the regression line which represents the effect X has on Y

b is a constant, known as the Y-intercept. If X = 0,Y would be equal to b.

So while brushing up with the above concepts, let me begin with the project:

Therefore I have downloaded all of my data from https://finance.yahoo.com/ . The data was for last year.

Installing the Libraries:

Loading the Data:

Getting the Shape and Visualizing the Data:

Creating a new row to predict named ‘Prediction’ to predict the next 20 Days of SLV

Visualizing the volatility of SLV of last 100 Days

As we can see the above chart SLV has been the most volatile in last 100 Days as compared to Spiders(SPY) and Dow jones Industrial index(DJIA).

Creating a feature Data set (x) and convert it to numpy array and remove the last ‘x’ rows/days:

Creating the target data set(y) and convert it to numpy array and get all of the target values except the last ‘x’ rows/days

Splitting the data into 75% training and 25% testing:

Creating the model:

Getting the last ‘x’ rows of the feature data set:

Showing the model tree prediction:

Finally Visualizing the output:

Conclusion:

What does the above chart shows?

The last data for the Silver was till 10th of September,2020. I have Predicted the Silver prices for the next 20 Days which is till the end of this month.

My model’s prediction has been very accurate as the prices of silver falls around $23 in the September month as you can see in the below chart. But there is a whole lot of parameters to be considered and the equation needs to be improvised, to actually make the decision on the market data.

Pros of Linear Regression

  1. Simple to implement.
  2. Used to predict numeric values.

Cons of Linear Regression:

  1. Prone to overfitting
  2. Cannot be used when the relation between independent and dependent variable are non linear.

Leave a comment