<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Navaneeth Rayavarapu on Medium]]></title>
        <description><![CDATA[Stories by Navaneeth Rayavarapu on Medium]]></description>
        <link>https://medium.com/@navaneethrayavarapu?source=rss-443f7314c7d0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0zsvWLK6Xt3UPHbDmwh47Q.jpeg</url>
            <title>Stories by Navaneeth Rayavarapu on Medium</title>
            <link>https://medium.com/@navaneethrayavarapu?source=rss-443f7314c7d0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 12:39:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@navaneethrayavarapu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Stock Market Prediction using Artificial Intelligence(AI)]]></title>
            <link>https://navaneethrayavarapu.medium.com/stock-market-prediction-using-artificial-intelligence-ai-d5f4e86055be?source=rss-443f7314c7d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5f4e86055be</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[analysis]]></category>
            <category><![CDATA[text-mining]]></category>
            <category><![CDATA[stock-market]]></category>
            <dc:creator><![CDATA[Navaneeth Rayavarapu]]></dc:creator>
            <pubDate>Wed, 21 Oct 2020 03:43:02 GMT</pubDate>
            <atom:updated>2020-12-17T04:09:02.324Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*V32PbJTwez6Bn_b8bRdBIw.jpeg" /></figure><h3><strong>1. Business Problem</strong></h3><p>Stock Market Prediction offers great profit avenues and is a fundamental stimulus for most researchers in this area. There are two ways to predict the stock market : <strong>1. Technical Analysis</strong> and <strong>2: Fundamental Analysis.</strong></p><blockquote><strong>Technical Analysis</strong> uses the market price data to predict the future movements or prices of the stock.</blockquote><blockquote><strong>Fundamental Analysis</strong> uses the unstructured textual information like financial news and earning reports.</blockquote><p>There are many problems can be formulated using stock market data. In this article, I’m writing about the problem which uses widely in the research area. To understand the problem you need to know the basics of stock market. If you’re complete beginner in this area please look into the following resources to understand the stock market.</p><ul><li><a href="https://en.wikipedia.org/wiki/Stock_market">Stock market - Wikipedia</a></li><li><a href="https://analyzingalpha.com/open-high-low-close-stocks">What is Open High Low Close in Stocks?</a></li></ul><p>Every company’s stock market opens with an <strong>Open </strong>price and ends with a <strong>Close</strong> price in a given day. These prices are determined by the <strong>sellers</strong> and <strong>buyers</strong> of the stock.</p><blockquote><strong>Sellers control </strong>: If Close price <em>is greater than</em> the Open price in a given day, it means Sellers are in control of the given company’s stock price on that particular day.</blockquote><blockquote><strong>Buyers control :</strong> If Close price <em>is less than</em> the Open price in a given day, it means Buyers are in control of the given company’s stock price on that particular day.</blockquote><p>In this article I’m going to explain how to predict whether buyers or sellers are in control in the next day by using using both technical analysis and fundamental analysis.</p><h3>2<strong>. Use of Machine Learning and Deep Learning</strong></h3><p>In the past, researchers only used historical stock market data to predict the future stock market. They mainly depends on the time-series analysis. But, the stock data is non-stationary and very volatile which leads it difficult to use traditional time-series models. And also stock market price heavily depends on the traders sentiment, where the time-series models doesn’t use the sentiments. It turns out that the traders sentiment heavily depend on the financial news articles. So, with the advancement of Machine Learning and Deep Learning and also there are so many publicly available news datasets we can use AI to predict the stock market.</p><h3><strong>3. Source of Data</strong></h3><p>In my research, I’ve used two different types of datasets.</p><ol><li>Dow Jones Industrial Average (DJIA) stock market data set and the top 25 reddit headlines in the period of 2008–06–08 to 2016–07–01. You can get the data set from <a href="https://www.kaggle.com/aaron7sun/stocknews">here</a>.</li><li>The second data set is the stock market data of a specific company (Microsoft) has been used and also the financial news articles have been used in the period of March 10th, 2014 to August 10th, 2014. News data can be find <a href="https://www.kaggle.com/uciml/news-aggregator-dataset">here.</a> stock data can be find <a href="https://finance.yahoo.com/quote/MSFT/history?p=MSFT">here</a>.</li></ol><h3><strong>4. Existing Approaches</strong></h3><p>There are different approaches, but most of researchers either use technical analysis or fundamental analysis. For the above datasets there is a one <a href="https://github.com/EmielStoelinga/CCMLWI">git hub</a> repository which explains how to use fundamental analysis. There is another <a href="https://www.researchgate.net/publication/318298991_Predicting_Stock_Market_Behavior_using_Data_Mining_Technique_and_News_Sentiment_Analysis">research</a> on how to use technical analysis on the same problem but different data set.</p><h3><strong>5. My Approach</strong></h3><p>I’ve used both technical analysis and fundamental analysis on the data sets by referring to the above two research papers and able to improve the accuracy by 5% on the second data set.</p><h3><strong>6. Understanding the Data</strong></h3><p><strong>Note:</strong> The below shown data is not raw data they are preprocessed data.</p><h4>6.1 DJIA Stock data and Reddit news</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*2MuFC-wM8yf7cbuNdEkOUA.png" /></figure><p>The above data is the DJIA stock data. let’s understand the categorical features which are generated from the OHLC values.</p><blockquote>If close price of today is greater than the yesterday the <strong>move_close</strong> is increased otherwise it’s decreased. Similarly for <strong>move_open</strong>, <strong>move_high</strong>, <strong>move_low</strong> are generated. <strong>move_close_open</strong> is whether close price is greater than open price on that day.</blockquote><p>Along with the stock data we have top 25 headlines of reddit news also.</p><h4>6.2 Microsoft Stock data and technology news</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*ISYkYJD77jwwWgeigLG8dg.png" /></figure><p>The above data set is the stock data of Microsoft company with <strong>normalized_title</strong> is the technological related news of Microsoft published on that day. <strong>tomorrow </strong>is the class label which represents the <strong>move_close_price </strong>on next day.</p><h3>7. Exploring the data.</h3><h4>7.1 DJIA Stock Data and Reddit news</h4><p>Let’s see how the class label distributed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*LlQdxq0ic8WPH4YeHS5J_Q.png" /></figure><p>You can clearly see that the class label is balanced in the DJIA stock dataset.</p><p>Similarly, we can explore word cloud of Reddit news in each class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*h5W3fSnI7X69inIMejjidw.png" /><figcaption>The above word cloud is the Top 25 Reddit news published when sellers are in control of DJIA Stock</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*0An_iimA_lhIlKDPP6v2yA.png" /><figcaption>The above word cloud is the top25 Reddit news published when buyers are in control</figcaption></figure><p>From the above word clouds we can clearly see that the news contains mostly country names and some political news which doesn’t related to the stock data. From this, we can infer that these news is not highly correlated with the stock data. So that the model may not perform well with this data.</p><h4>7.2 Microsoft stock data and it’s technology news.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*5ucog23E3dDO4g_1ZXfuZQ.png" /><figcaption>0 indicates Buyers are in control, 1 indicates sellers are in control</figcaption></figure><p>You can see that the Microsoft stock data class label is also balanced.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*ih9XwSlhQEbeyDiCYZRwjw.png" /><figcaption>The above word cloud is the Microsoft Technology news published when sellers are in control of Microsoft Stock</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*1nDLCxO_zNwE0-1wqZ7nQQ.png" /><figcaption>The above word cloud is the Microsoft Technology news published when Buyers are in control of Microsoft Stock</figcaption></figure><p>From the above word cloud we can infer that there are not many different words between the two classes. But, may be the sentiment of the statements might be different.</p><h3>8. Text encoding and ML models explanation</h3><h4>8.1 Text encoding</h4><p>There is text data in both data sets. The important thing is How do we encode this text data to numerical so that the ML models can run on the data set. Here, we’ll see the encoding techniques.</p><p>I’ve used two types encoding techniques. They are : 1) Average Word2Vec, 2)weighted word2vec with the weights being IDF(Inverse Document Frequency) values of the word.</p><pre><br>embeddings_dict = {}<br>with open(data_path + &quot;glove/glove.6B.50d.txt&quot;, &#39;r&#39;, encoding = &quot;utf-8&quot;) as f:<br>    for line in f:<br>        values = line.split()<br>        word = values[0]<br>        vector = np.asarray(values[1:], &quot;float32&quot;)<br>        embeddings_dict[word] = vector</pre><pre>glove_words =  set(embeddings_dict.keys())<br></pre><p>The above code represent how to use global vectorizer to encode each word with the dimension being 50.</p><pre># average Word2Vec<br># compute average word2vec for each review.<br>x_train_avg_w2v_news = []; # the avg-w2v for each sentence/review is stored in this list<br>for sentence in tqdm(x_train_news[:]): # for each review/sentence<br>    vector = np.zeros(50) # as word vectors are of zero length<br>    cnt_words =0; # num of words with a valid vector in the sentence/review<br>    for word in sentence.split(): # for each word in a review/sentence<br>        if word in glove_words:<br>            vector += embeddings_dict[word]<br>            cnt_words += 1<br>    if cnt_words != 0:<br>        vector /= cnt_words<br>    x_train_avg_w2v_news.append(vector)</pre><p>The above code represents how to get the average of word2vec for a given sentence.</p><pre>tfidf_model = TfidfVectorizer()<br>tfidf_model.fit(x_train_news)</pre><pre>dictionary = dict(zip(tfidf_model.get_feature_names(), list(tfidf_model.idf_))) #dictionary of words and corresponding idf values<br>tfidf_words = set(tfidf_model.get_feature_names())</pre><pre>x_train_tfidf_w2v_news = []; <br>for sentence in tqdm(x_train_news):<br>    vector = np.zeros(50)<br>    tf_idf_weight =0;<br>    for word in sentence.split():<br>        if (word in glove_words) and (word in tfidf_words):<br>            vec = embeddings_dict[word]<br>            tf_idf = dictionary[word]*(sentence.count(word)/len(sentence.split())) # getting the tfidf value for each word<br>            vector += (vec * tf_idf) # calculating tfidf weighted w2v<br>            tf_idf_weight += tf_idf<br>    if tf_idf_weight != 0:<br>        vector /= tf_idf_weight<br>    x_train_tfidf_w2v_news.append(vector)</pre><p>The above code represents how to get the weighted Word2Vec for a given sentence.</p><p>Not only the encoding of text data we need the sentiments of the text data which is very important in stock market prediction.</p><pre>#sentiment scores for the news data<br>import nltk<br>#nltk.download(&#39;vader_lexicon&#39;)<br>from nltk.sentiment.vader import SentimentIntensityAnalyzer<br>sentiment_scores = []<br>sid = SentimentIntensityAnalyzer()<br>for sentence in tqdm(raw_data_news[&#39;clean_news&#39;].values):<br>    ss = sid.polarity_scores(sentence)<br>    sentiment_scores.append(ss[&#39;compound&#39;])</pre><p>The above code represents how to get the sentiment scores of given sentence.</p><h4>8.2 ML models</h4><p>I’ve used two ML models one is KNN and another one is SVM with different encoded data on DJIA data set. But, the results are very poor test accuracy is being in the range of 48 to 52 only. The one reason being that the news data is top 25 headlines in Reddit which are not related to stock data most of the times. I’m adding the results with different models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*j58lCx2qn2Oi_6LRvw3Xsw.png" /><figcaption>Comparision of results on different models on DJIA data set.</figcaption></figure><p>we can clearly see that the results are not great.</p><h3>9. Deep Learning Model</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*klb-26fVDTF4m_St8YR99Q.png" /></figure><pre>max_review_length = 100<br>        X1_train = sequence.pad_sequences(X1_train, maxlen=max_review_length)<br>        X1_test = sequence.pad_sequences(X1_test, maxlen=max_review_length)<br>        # create the model<br>        <br>        embedding_vecor_length = 32<br>        <br>        input_1 = Input(shape=(max_review_length,))<br>        input_2 = Input(shape=(5,))<br>        <br>        embedding_layer = Embedding(top_words, embedding_vecor_length, input_length=max_review_length)(input_1)<br>        conv_layer = Conv1D(filters=32, kernel_size=3, padding=&#39;same&#39;, activation=&#39;relu&#39;)(embedding_layer)<br>        max_pool_layer = MaxPooling1D(pool_size=2)(conv_layer)<br>        lstm_layer = LSTM(100)(max_pool_layer)<br>        <br>        dense_layer_1 = Dense(10, activation=&#39;relu&#39;)(input_2)<br>        dense_layer_2 = Dense(10, activation=&#39;relu&#39;)(dense_layer_1)<br>        <br>        concat_layer = Concatenate()([lstm_layer, dense_layer_2])<br>        output_layer = Dense(1, activation=&#39;sigmoid&#39;)(concat_layer)<br>        <br>        model = Model(inputs = [input_1, input_2], outputs = output_layer)<br>        optimizer = Adam(lr=1e-3)<br>        model.compile(loss=&#39;binary_crossentropy&#39;, optimizer=optimizer, metrics=[&#39;accuracy&#39;])</pre><p>The Deep Learning model use both text data and stock data. It contains two input layers.</p><blockquote><strong>Input Layer 1</strong>: It takes the news data with maximum length of words is 100.</blockquote><blockquote><strong>Input Layer 2</strong>: It takes the categorized stock price data. There are 5 features.<strong>Embedding Layer</strong>: It embed the each word into 32 dimensional vector from <strong>Input Layer 1</strong>.</blockquote><blockquote><strong>Convolution Layer: U</strong>sed a convolution with kernel size 3 on the output of <strong>embedding layer.</strong></blockquote><blockquote><strong>Max Pooling Layer: </strong>Used Max pool layer with pool_size is 2 on the output of <strong>Convolution Layer.</strong></blockquote><blockquote><strong>LSTM Layer:</strong> Applied LSTM layer on the output of Max Pooling Layer with the number of units are 100.</blockquote><blockquote><strong>Concatenated layer: </strong>The output from the Input Layer 1 which is applied with two dense layers sequentially is concatenated with the output layer of LSTM.</blockquote><blockquote><strong>The final layer: </strong>The Final layer contains the output of 1 unit.</blockquote><p>After Applying this model with 100 epochs on DJIA Stock data and Reddit news data. The test accuracy is 0.52 only but the good thing is that precision and recall are good with this model compared to machine learning model.</p><p>When this same model applied on Microsoft stock data and the corresponding news data the <strong>test accuracy is 0.78. </strong>The test accuracy of 0.78 is good in stock market prediction.</p><p>With the same Microsoft data, Using only Fundamental analysis <a href="https://github.com/EmielStoelinga/CCMLWI">this</a> git hub repository got the <strong>test accuracy of 0.73. </strong>But by using both both Technical Analysis and Fundamental Analysis, my model <strong>improved the accuracy by 5%.</strong></p><h3>10. Future Work</h3><p>After applying different models with different data sets. It seems that the deep learning model applied on data set containing the company’s specific headlines gave the good accuracy. Similarly, we can use twitter tweets about the specific company and the tweets of biggest investors of the company to increase the accuracy.</p><h4>Code resources</h4><p>GitHub Link: <a href="https://github.com/navanith007/Stock-Market-Prediction">https://github.com/navanith007/Stock-Market-Prediction</a></p><p>My Linkedin: <a href="https://www.linkedin.com/in/navanith-rayavarapu-b6359b12a/">https://www.linkedin.com/in/navanith-rayavarapu-b6359b12a/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5f4e86055be" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>