Data Science Projects: NSE Real-Time Stocks Analysis and Predictions Using Python LSTM Model

What is NSE

National Stock Exchange is India’s largest stock exchange in Mumbai, which was first established in November 1992 as the first fully automated, nationwide electronic exchange. First Data Science Projects

I’ll show you in this article :

how to fetch data of any stock(NSE) in realtime

How you can evaluate the stock price using basics visualizations:

Predicting future stock price using machine learning algorithms

This is my first data science machine learning project

Note: It’s very difficult to predict future costs, even for machine learning models. Particularly with regard to the stock market, stock price itself is a derivative of the underlying company and its capital structure, i.e. both economic and control factors, as well as human emotions and intentions.

There are several external factors to consider for knowing whether a stock’s price will rise or fall in the future.

Same as stock price, the only input the algorithm takes is the stock price, there are many other factors which can affect the stock price. Only note that your key purpose should be learning new techniques and instruments.

So Lets gets started

Which machine learning algorithm to use?

There is no such model that is always best. You can use either Regression or Forecasting algorithms to predict stock prices, but the data needs to be in a specific format for an algorithm to function that the machine understands when processing an ML algorithm. LSTM is one such prediction algorithm.

Long  Short Term Memory, commonly called “LSTMs,” is a special form of neural recurrent network that can learn large-term dependencies. Unlike traditional feedforward networks, LSTM has feedback links, i.e. it is essentially their natural behavior to remember knowledge for long periods of time, not something they strive to know!

LSTMs also have this chain-like structure just like the RNN network has the shape of a chain of neural network repeating modules but the LSTM repeating module has a different structure. Rather than having a single layer of the neural network, there are four, which communicate in a very unique way.

 

How can LSTM Predict the Future Price  of the stock?

In sequence prediction problems, LSTMs are very efficient, since they can store past information. This is critical in our case as a stock’s preceding price is crucial in predicting its future price.

In this project, I have used the last 30days ‘s stock close price to predict the closing price for the next day

 

Steps to develop LTSM Data Science Project Stock Price Prediction Model

We begin by importing Numpy for scientific computations, Matplotlib for plotting graphs, Pandas for loading and manipulating our dataset, sklearn for pre-processing our data, Keras for training/fitting/predictions on our dataset and nsepy for extracting historical and real-time data from the NSE website.

First install the nsepy library using the command pip install nsepy

Next, you’ll be asked to enter the stock symbol in order to fetch the stock information such as Hindustan Unilever in my case . We use the DateTime module of python to extract the to date information, end = date.today).

Df.tail() is used to fetch the last 5 data from the data frame

Our data frame has 2568 rows and 15 columns.

Visualizations

Visualize the closing price history from last 30th day’s information

 

Next Step is to Split the data into training and Testing Data

Build a new data frame, which stores the value of the close price column.

Coverting data into numpy array

Divide 75%  data as training  rest 25% as testing data

Feature Scaling

We use the MinMaxScaler from Scikit-learn to scale our dataset to have values from 0 to 1.

We scale our dataset because it is a good idea to scale the data to maximum output before feeding the data into a neural network.

Modify the training dataset with the required timestamp

train_datawill contain all the values of rows from index 0 to training_data_len with all the columns.

Append  the values  of the past 30 days to x train i.e. it will contain all values from index 0 to 29 for the first run and values from index 1 to 30 for the second run, etc.

Append the 31st day value to y train, i.e. the index 30th value for its  first run and then the index 31st value for the second run and so on.

Then we use Numpy to convert x train, y train to an array, then we reshape the array into a 3-dimensional array with x train samples, 30 days timestamp and one function per phase. It’s the shape which our LSTM architecture accepts.

Building the LSTM Architecture

Model is an  object of sequential ()  for initializing a layer of neural networks.

add LSTM layer to our network with parameters, source: Keras

units=50 , can be a positive integer, the dimensionality of the output space

return_sequence , can be True or False, determines whether to return the last output in the output sequence or the full sequence.

input_shape , which is the shape of our training set.

add densely connected neural network layer

next we compile the model using adam optimizer and for the loss we use mean_squared_error.

Then we fit the model with a batch size of 50 on x train and y train to run over 100 epochs.

Finally, we saved the trained model to the system

Create the testing dataset

Test datawill contain all the values of the training data len-30 index rows to the end of our dataset with all the columns

Y test must include all rows from the training data len index to the end of the dataset with all columns (in this case it is just ‘Close’ column).

x test will contain all values from index 0 to 29 for the first run of test data

and values from index 1 to 30 for the second run of test data and so on from test data.

We then transform x test to a Numpy array, then reshape the array to a 3-dimensional array, i.e. the form agreed by our LSTM architecture (similar to our x train and y train).

Predicting Future Stock using the Test Set

First we’ll make x test data predictions and undo the scaling.

Then we calculate the root mean squared error (rmse), which is used to measure the efficiency of our model. The lower the value our model’s achieved the better.

Rmse of hul is 36.68

Finally we use Matplotlib after projections to represent the results of the expected stock price and the real stock price.

To know about what is Stock Market read my share market article

Upcoming Ipo In India 2020

Upcoming IPOs In India

The upcoming ipo 2020 is the IPO that was created or approved with SEBI, and their issue date is no longer relevant. The new IPOs in India are available in this article.

Such businesses prepared their SEBI prospectus or disclosed their red herring prospectus. Find the list of the latest IPOs or the old IPOs below.

Upcoming ipo

List of Most Famous Upcoming IPOs of 2020

1.SBI Cards IPO

Issuer Company: SBI Cards IPO

Price Band: 750-755

IPO Size:9600 cr

Issue Date: 2nd Mar 2020

2. National Commodity & Derivative Exchange Ltd

Price Band: NA

IPO Size: NA

Issue Date: NA

3 Burger King (India ) Limited

Price Band: 600 crore

IPO Size: 400

Issue Date: 1st week of April

4. CAMS IPO

IPO Size: 1500 Cr

Price Band: N/A

Issue Date: Upcoming

5. UTI AMC IPO

 IPO Size: 3000 Cr

Price Band: N/A

Issue Date: Upcoming

6.LIC AMC IPO

IPO Size :3000 cr

Price Band: N/A

Issue Date: Upcoming

New IPO /Recent IPOs/Running IPOs of Jan 2020

1.Madhav Copper IPO

IPO Size: 25.50 Cr

Price Band: 100-102

Issue Date: 27 Jan 2020

2. ICL Organic Dairy IPO

IPO Size: 4.08 Cr

Price Band: 20

Issue Date: 31 Jan 2020

3.Tramway Technologies IPO

IPO Size: 4.24 Cr

Price Band: 10

Issue Date: 27 Jan 2020

4. ITI Limited IPO

IPO Size: 1398.86 Cr

Price Band:71-77

Issue Date: 24 Jan 2020

Upcoming IPOs of Feb -2020

Mindspace REIT IPO

Harsha Engineers IPO

Puranik Builders IPO

Easy My Trip IPO

Home  First Finance IPO

Rossari Bio-Tech IPO

Equitas Bank IPO



How does Student Loan Work

How Does Student Loan Works

Student loans make it possible for college — and, increasingly, a middle-class life. But before you take them out, you should understand how student loans work.

Higher education becomes a must quickly. In the job market, graduates have better odds, the right degree is a great way to follow a passion and at the same time make themselves marketable. Nevertheless, the cost of college and graduate school is only rising. So what are you going to do?

You may be able to enter the student loans of 40 million Americans. It may seem overwhelming to borrow to pay for an education, but lending can be economical and manageable. Only you can decide if loans are your best choice. First, read the answers to the FAQ.

What are the loans for students?

Student loans are sums of money that you borrow for your education and, in most cases, payback with interest over time.

Loans will often be part of your school financial assistance deal. First, seek grants and scholarships because they don’t have to be reimbursed. But if you don’t get a full ride, the difference can be made by loans.

How are you applying for credit?

You must fill out a FAFSA or Free Application for Federal Student Aid when applying to class. Pay attention to the time limits of FAFSA, which vary each year. (For 2016, it’s October 1.) The FAFSA will usually be available for the next autumn school year starting in the fall.

Application for public loans

If you are a dependent student, use the financial information of your parents or guardians. Use your own if you are an independent student.

The website of the Federal Student Assistance has a FAFSA4caster tool to predict what your expected contribution could be. Combine all federal tax information, bank statements, and pay stubs or job information. For the application, you will need these documents.

If you are admitted to a program, your school will send an offer of financial assistance that may include federal loans (federal government loan money).

Private loan application

A different application process includes private loans (money loaned by a bank, credit agency or other organization). On websites such as finaid.org and alltuition.com, you can compare private loans.

You will get federal loan funds before you receive them.

Full admission consultation with a financial advisor, either in person or online. As a creditor, you’ll know your rights and duties.

Sign a Note of Permission or Master Note of Permission. This is a legally binding document that lists the conditions for reimbursing the loan. Keep the document copy! Later on, you will need it

What are the available types of loans?

Two categories of loans are available in the US: private and federal.

Federal credit

Direct Subsidized Loans

The government pays the interest with a subsidized loan while you are at school and during any deferment time (“subsidizing” your schooling by offsetting the cost). Subsidized loans are only available to undergraduates with proven financial need. The amount is limited, as determined by the FAFSA, to cover only your financial need.

Direct Unsubsidized Loans

With an unsubsidized loan, the borrower is responsible for any interest that happens when and after they are in class. Any undergraduate or graduate student is given unsubsidized loans. The amount is determined by your school attendance cost and any other assistance you receive.

You can hear the so-called Stafford Loans Direct Subsidized and Unsubsidized Loans.

Direct PLUS Loans

These loans are available to U.S. graduates or professionals. The Ministry of Education. We need a decent credit check and a history of credit. The sum is intended not to cover any other assistance expenses.

Perkins Loans

Such loans are for undergraduate and graduate students, who are lenders directly from the university, with extraordinary financial needs. Many schools offer Perkins credit and others don’t. After September 30, 2017, the loan program for Perkins expires. After that date, no new loans are issued.

Direct Consolidation Loans

You can combine these into a single loan from a single servant if you have several federal loans. The new loan is called a direct loan for consolidation.

You can learn the so-called Stafford Loans Primary Subsidized and Unsubsidized Loans.

Facts regarding federal credit:

You will not need a co-signer in most situations.

You will not need a credit check unless you take a PLUS loan

Usually, interest rates (the same over the life of the loan) are fixed.

Interest Tax-Deductible

Private Loans

Since private loans offer much less flexibility, federal loans are your best option.

Private student loans come from non-government lenders such as a bank, a credit union, a school, or a government organization. The amount you can withdraw and the repayment options are up to the lender.

Some private loan facts:

While still in class, you may have to start payments.

Loans may need a credit check and a co-signer.

Many private loan service providers will only give you a rate of interest after you apply, so shopping around is fine.

Interest rates may vary (with the financial market fluctuating). Some interest rates for private loans may be as high as 18 percent.

Interest may not be deductible from taxes.

How much money are you able to borrow?

Undergrads

Loans from Perkins

Students with an extraordinary financial need can borrow up to $5,500 per year until the plan ends in September 2017.

Direct Subsidized Loans and Direct Unsubsidized Loans Students can borrow from $5,500 to $12,500 annually.

Graduate Students

Loans from the Perkins

Students with an exceptional financial need can borrow up to $8,000 annually until the program expires in September 2017.

Direct Unsubsidized Loans

Every year, students are able to borrow up to $20,500.

Direct PLUS Loans

The remaining costs of your college are not covered by financial assistance

How much are you going to borrow?

Just because the maximum amount you can borrow doesn’t mean you will.

The financial assistance offered will estimate your living expenses, and if you feel their estimate is too high you can turn down a loan or ask for a lower amount. Just borrow what you need. Buying a cover for the unexpected is a good idea to measure your future living expenses yourself.

One rule of thumb is not to take out more loans in your profession than the planned first-year income. Also, even if you can’t find work in your profession, or your plans change, you’ll still be forced to pay back the loan.

Check at the terms and conditions of any loans given to you — such as interest rates (better lower) and the date you need to begin repayment.

How are interest rates working?

Remember to calculate middle or high school math class interest rates? You don’t have to dust off your SAT prep book, but before you borrow, you should know how interest rates affect your loan.

Interest is money paid to the lender in exchange for borrowing a larger amount at a particular rate. The interest rate is calculated as a percentage of your amount of outstanding debt, also known as the interest (or principal) number. For any unsubsidized loans, you are responsible for paying interest.

Federal loans

Federal loan interest rates are set, which means that the rates will not change over the life of the loan. Congress will determine the rates.

Direct Undergraduate Subsidized and Unsubsidized Loans: 5.05 percent.

Direct Unsubsidized Student and Professional Loans: 6.6%

Direct plus Loans:7.6 percent

Private loans

The creditor sets the interest rates of private loans. Such levels may vary or be set. The price would change over the life of the loan with a variable interest rate.

Calculation of interest

To calculate the amount of interest accruing on your loan or accumulating it, divide the interest rate of the loan by 365.25—the number of days in the year, including the Leap Year. This number is the factor of interest rates or your loan’s daily rate.

A loan with an interest rate of 5 percent (.05 divided by 365.25) would have a daily rate of 0.00013689253, for example.

You can calculate how much interest accrues on your loan from month to month using the interest rate factor.

Use the formula of daily interest: outstanding principal balance (how much of the loan remains unpaid)x number of days from your last payments interest rate factor above= interest amount

An example

Assuming your outstanding student loan amount is $40,000—the average amount of a graduate’s student debt in 2014. It’s been 30 days since your last payment and you have a 5 percent interest rate.

40000 (unpaid principal)x 30 (days from the last payment)x 0,00013689253 (interest rate factor)= around 16427 or 16427 dollars in interest that month.

Our loan calculator can also be used to determine the amount of interest a loan receives.

When and how are you going to pay back loans?

Repayment options are flexible and may change as your life situation changes (especially federal lending).

You can apply for postponement or forbearance— a time period when you don’t have to pay back the loan — on federal loans and some private loans. The debt will continue to accumulate during deferment if you have an unsubsidized mortgage.

Returning federal loans

If you have federal loans, you will not have to pay them back at least half-time while you are in school. If you choose to, you can start paying back early. There are no penalties for advance payment.

Generally, you will have a six-month grace period following graduation before your repayment schedule starts. Your lender will then ask you to select an option for repayment.

You need to pay a different amount each month for each option. The more you are able to pay per month, the less overall you are going to pay.

Remember the daily interest formula above — if you make larger payments, the unpaid principal will be chipped away faster, resulting in lower interest accrued. In the same way, you are likely to pay more money overall if you make smaller transactions, as the interest will add up.

All federal loans except Perkins Loans are covered by the plans below. If you have a Perkins loan, you should be told about repayment options by the school (your lender), which will vary.

The standard plan for repayment.

With the goal of paying off your loan in 10 years (30 years for a Direct Consolidation Loan that tends to be larger), you pay a fixed monthly amount. Overall, this option saves the most money, but at one time costs more.

Graduated Repayment Plan

You begin with smaller payments every two years — again, in order to pay the loan in ten years.

Extended Repayment Plan

In 25 years ‘ time, you pay for a fixed or graduated plan monthly to pay the loan. Only holders who have a debt of $40,000 or more can use this option.

Plan for Income-Based Repayment

Your monthly payments are either 20% of your discretionary income or the monthly amount you paid for over 12 years with a fixed payment, which is lower.

Income-Sensitive Repayment Plan

You make monthly payments for up to 15 years on the basis of your annual income.

Federal Student Aid offers a repayment estimator to allow you to type in the amount of your loans, interest rates and revenue to see which alternative will better work.

Whenever you find your payments can not be afforded, please contact your loan officer and check whether you can change to a cheaper scheme. Failure to pay damages your credit and may lead to default eventually.

Paying back private loans

Know what repayment options you have before you take out a private loan. You can require payment during school time for certain private loans. Some of these options are more flexible than others. They may allow deferment or abstention or can negotiate an interest rate that is highly variable.

Summary

With tuition rising and a college degree becoming more needed for a medium-sized life, student loans play an increasingly important and important role in most people. Student borrowing can be terrifying, frustrating, and painfully repetitive.

But you can use some fear from lending large sums to help finance your future if you know what you are doing — in terms of interest rates and payments systems.