Analyze the Correlations Between Stock Market and the Keywords under News

Posted on Apr 3, 2018

Natural Language Processing is a technique used by a computer to understand and manipulate natural languages. Social Media can be an influence when delivering the right frame of speech, so I got very interested in this topic because I know Morgan Stanley and Stanford NLP group are using NLP techniques to evaluate past data pertaining to the stock market and world affairs of the corresponding time period, in order to make predictions in stock trends. They built models that will be able to buy and sell stock based on profitable prediction without any human interactions. The models use NLP to make smart “decisions” based on news, current affairs and some investor’s viewpoint. In my project, my motivation of this study is to scrape the titles and dates from relevant news and use them to analyze and try to find out the correlations between the stock market and the keywords under the news, so I scraped all the titles and date under the financial, economy and tech news sections from CNBC. The dataset I use was from Jan 06 2016 to Feb 06 2018. I downloaded the stock price from Jan 06 2016 to Feb 06 2016 from finance yahoo and join them by date. It was interesting to know about how to go from text data to vectors of numbers and applying Machine learning techniques that can help to influence the stock market.

I scraped the titles and data from 15 subcategories and the dataset was like this:

Data Cleaning

When I just got the data, the data was like this:

 

I cleaned the data and I also got to see if the stock market rise or fall compare to the previous day.

Natural Language Processing

After I cleaned up the data, I tokenized the words, stemlize, removed punctuations and stop words such as ‘the’, ‘is’, ‘and’. I have also converted all the letters to lowercase to make a more even data set to play with. The data is manipulated by python(spacy package). Then I got the top 100 keywords and how many times that appeared on the news titles. The data was like this:

Model

I used random forest run a model and got the variable importance to help me decide what are the keywords that had the most important relationship with the stock market.

I got 64 true negatives  and 159 false positives, 76 false negatives and 217 true positives. This shows that my model predicts "rise" reach to 75% correct and predict "fall" 29% correct. This means that the model predict "rise" much better than "fall".

I chose 10 words from the variable importance of random forest, and got a histogram to see the a better understanding of their correlations with the stock fluctuation.

Future Work

This project helped me understand the basics of Natural Language Processing and gain wider sense of the power of NLP in financial market. Even though I can’t create a perfect model or get more content and news from different websites because more features will help the model learn better, this work can be treated as a try of using Natural Language Processing and get a sense of machine learning.I will use TF-IDF(term frequency–inverse document frequency) to cut down more words. I will also try to get more news content, and add more features and observations.

About Author

Xiao Jia

Xiao received a MS degree in Biomedical Informatics from Nova Southeastern University in Florida. She was working as a data analyst at a healthcare IT company in Fort Lauderdale, where she developed her passion and got to know...
View all posts by Xiao Jia >

Related Articles

Leave a Comment

No comments found.

View Posts by Categories


Our Recent Popular Posts


View Posts by Tags

#python #trainwithnycdsa 2019 2020 Revenue 3-points agriculture air quality airbnb airline alcohol Alex Baransky algorithm alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus ames dataset ames housing dataset apartment rent API Application artist aws bank loans beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep boston safety Bundles cake recipe California Cancer Research capstone car price Career Career Day citibike classic cars classpass clustering Coding Course Demo Course Report covid 19 credit credit card crime frequency crops D3.js data data analysis Data Analyst data analytics data for tripadvisor reviews data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization database Deep Learning Demo Day Discount disney dplyr drug data e-commerce economy employee employee burnout employer networking environment feature engineering Finance Financial Data Science fitness studio Flask flight delay gbm Get Hired ggplot2 googleVis Hadoop hallmark holiday movie happiness healthcare frauds higgs boson Hiring hiring partner events Hiring Partners hotels housing housing data housing predictions housing price hy-vee Income Industry Experts Injuries Instructor Blog Instructor Interview insurance italki Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter las vegas airport lasso regression Lead Data Scienctist Lead Data Scientist leaflet league linear regression Logistic Regression machine learning Maps market matplotlib Medical Research Meet the team meetup methal health miami beach movie music Napoli NBA netflix Networking neural network Neural networks New Courses NHL nlp NYC NYC Data Science nyc data science academy NYC Open Data nyc property NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time performance phoenix pollutants Portfolio Development precision measurement prediction Prework Programming public safety PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R Data Analysis R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn seafood type Selenium sentiment analysis sentiment classification Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau teachers team team performance TensorFlow Testimonial tf-idf Top Data Science Bootcamp Top manufacturing companies Transfers tweets twitter videos visualization wallstreet wallstreetbets web scraping Weekend Course What to expect whiskey whiskeyadvocate wildfire word cloud word2vec XGBoost yelp youtube trending ZORI