<?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 Mark Babbe on Medium]]></title>
        <description><![CDATA[Stories by Mark Babbe on Medium]]></description>
        <link>https://medium.com/@babbemark?source=rss-e71f279318b8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Snu3_W5RUP1UsPoXDNng9A.jpeg</url>
            <title>Stories by Mark Babbe on Medium</title>
            <link>https://medium.com/@babbemark?source=rss-e71f279318b8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 10:02:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@babbemark/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[Mutual Funds are better than ETFs. Here’s why.]]></title>
            <link>https://babbemark.medium.com/mutual-funds-are-better-than-etfs-heres-why-1452d9de13d0?source=rss-e71f279318b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/1452d9de13d0</guid>
            <category><![CDATA[covid19]]></category>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[etf]]></category>
            <category><![CDATA[mutual-funds]]></category>
            <category><![CDATA[stock-market]]></category>
            <dc:creator><![CDATA[Mark Babbe]]></dc:creator>
            <pubDate>Tue, 30 Mar 2021 22:25:10 GMT</pubDate>
            <atom:updated>2021-03-30T22:25:10.938Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LQgsioml9AUQfGzXcmoZsw.jpeg" /><figcaption>Photo by <a href="https://www.pexels.com/@anna-nekrashevich?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Anna Nekrashevich</a> from <a href="https://www.pexels.com/photo/photo-of-person-holding-ceramic-mug-6801874/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><p>I am sure most of you have heard that the key to a great stock portfolio is to find an ETF with a low expense ratio and good growth history. While this approach will undoubtedly work, it is not optimal.</p><p>Following the COVID-19 pandemic, virtually every fund having to do with U.S. and global stocks took a massive hit. As we learned from the 2008 stock market crash, the best course of action was to stay in the market and wait out the storm. As time progressed, we saw most ETFs and mutual funds recover at expected rates. However, some mutual funds skyrocketed. The difference? Stock selection.</p><p>By nature, exchange traded funds track an index (frequently the S&amp;P 500) and hold an array of stocks that update on a quarterly or annual basis. The update has certain criteria, and it happens almost automatically. Some of the <a href="https://www.spglobal.com/spdji/en/documents/additional-material/sp-500-brochure.pdf"><strong>criteria</strong></a> includes having a market capitalization of at least $11.8 billion and being a U.S. company. This means that when the market drops or rises for any reason, the fund will keep the same holdings unless new companies qualify, and an update date occurs. Due to this feature, the management fees and expenses associated with ETFs are significantly lower than that of mutual funds because there is no one actively managing the fund.</p><p>On the other hand, mutual funds can contain whatever holdings the portfolio manager(s) decides, whether it be aimed at a goal of growth, dividend payment, value, or simply the size of the company. Because the holdings can change at will (as indicated by the turnover ratio), and because a team or an individual is actively managing the fund, fees tend to be higher. This alone is a turn off to many investors looking for a simple fund with low expenses, and a good track record of growth.</p><p>While my opinion on the two types of funds have fluctuated over the years, the COVID-19 pandemic really settled the score. How did it? When I noticed my mutual funds had been growing exponentially higher than my ETFs. Why? You guessed it, stock selection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*-nIq2KhcNA6VQBxyCvi1gA.png" /><figcaption>($10,000 is used as a starting reference point and does not reflect my actual portfolio)</figcaption></figure><p>As seen in the graph above, my mutual fund took off following the low in March of 2020. This happened because the portfolio managers saw an opportunity that an ETF could not account for.</p><h4><strong>Adjusting on the Fly</strong></h4><p>After the lockdowns began, it was slowly becoming clear that Americans would be sitting idle for a while. Many companies made the decision to continue their work, but not to continue in-person work, and for good reason. This led to the rise and investment in companies like Zoom Video Communications, Inc., and Microsoft Corporation, both of which had platforms for communicating over the internet face to face.</p><p>Many mutual funds took advantage of this trend and adjusted their holdings for the new way of life for the next year. This was not unique to just video communication. Existing online in all facets of life became the new norm, and portfolio managers knew this would be the case.</p><p>In the example above, I used the S&amp;P 500 and Morgan Stanley’s Growth Portfolio Class A. For fiscal year end 2020, the mutual fund grew a whopping 115.57% after fees and reinvestment of distributions. Conversely, the S&amp;P 500 earned 17.88% after fees and dividend reinvestment. If you had invested $10,000 at the low point in March of 2020 in both funds, you would have almost $7,500 more profit from the mutual fund.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/1*mztNwHv5MYcyRUbtNwBAmw.png" /></figure><p>But how do mutual funds compare when we are not going through a pandemic? Good question. It is true that most mutual funds do not outperform ETFs like the one I am showing above. The truth is that it is pretty hard to outperform. You can see in chart below that even between the S&amp;P 500 and MSEGX, historical returns since 2000 are not incredibly different.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*Gl89u_7hKiaZV5AET-MAXw.png" /></figure><p>If you are in the stock market for the long haul (i.e. retirement), then it makes sense to explore higher growth opportunity funds. While past results do not guarantee future outcomes, it is still nice to know that that your fund is actively managed with a goal of outperforming its benchmark. On the bad years, growth mutual funds often mirror ETFs. On the good years, they can substantially outperform them.</p><h4><strong>Conclusion</strong></h4><p>All of this is to say that no matter which fund you choose, you should still see great growth in your portfolio. But I do think it is worth looking into actively managed mutual funds, especially if you are wanting an extra set of eyes on your holdings. Keep in mind that I am not a portfolio advisor, and this is strictly my opinion.</p><p>My advice would be to invest in array of funds to ensure your portfolio is properly diversified in hopes of handling any stock market climate. Investing in ETFs as well as mutual funds are a great way to ensure you keep up with the market, but also have the possibility of exceeding it. I have both in my portfolio and suggest you do too.</p><p>If you liked this article, please consider sharing with friends! If you have questions or comments regarding the content, please leave a comment!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1452d9de13d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[BERT is the Word: Predicting Stock Prices with Language Models]]></title>
            <link>https://babbemark.medium.com/bert-is-the-word-predicting-stock-prices-with-language-models-8d5205b8537c?source=rss-e71f279318b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d5205b8537c</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[naturallanguageprocessing]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[bert]]></category>
            <category><![CDATA[stock-market]]></category>
            <dc:creator><![CDATA[Mark Babbe]]></dc:creator>
            <pubDate>Sat, 16 Mar 2019 02:05:26 GMT</pubDate>
            <atom:updated>2019-03-16T02:05:26.297Z</atom:updated>
            <content:encoded><![CDATA[<p>Project By: Mark Babbe, Cory Nguyen, Won Lee, and Hanny Noueilaty</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/0*qjc4uJ9U-WrXme8Z" /></figure><p>Source: <a href="https://www.huffingtonpost.com/entry/the-future-of-machine-learning-in-finance_us_58d55c99e4b06c3d3d3e6d42">https://www.huffingtonpost.com/entry/the-future-of-machine-learning-in-finance_us_58d55c99e4b06c3d3d3e6d42</a></p><h3><strong>Introduction</strong></h3><p>Machine learning and neural networks continue to revolutionize industries all around the globe, and the finance industry is no exception. In our class project we decided to implement a neural network with the hopes of understanding how information in SEC 8-K forms could be utilized in predicting the overall movement of the S&amp;P 500. In reality, the success of such a model in the real world and its applications would depend on the infrastructure, datasets, and processing/action time. That said, we found that publicly available 8-K forms could provide valuable insights in determining the overall movement of markets.</p><p>We were inspired by a Huffington News <a href="https://www.huffingtonpost.com/entry/the-future-of-machine-learning-in-finance_us_58d55c99e4b06c3d3d3e6d42">article</a> titled “The Future of Machine Learning in Finance” as well as a blog post on Medium from a fellow data scientist. We thank Yusef Aktan for his <a href="https://towardsdatascience.com/using-nlp-and-deep-learning-to-predict-the-stock-market-64eb9229e102">blog post</a>, which was a helpful starting point.</p><h3><strong>Data Collection &amp; Preprocessing</strong></h3><p>For data collection, we were fortunate enough to have access to Atkan’s work on his Github, which allowed us to build on top of his hard work. So, from the start we had access to a scraper and a Jupyter notebook for data preprocessing. With this as our starting point, we began modifying the code to see if we could improve how the data preprocessing stage was handled while addressing any bugs that inadvertently occurs when programming scripts change hands. For instance, we quickly ran into problems with the scraper that was meant to retrieve 8-K filings from the SEC Edgar database. Attaching a timer to the requests.get function would not solve the issue, since access to the documents was not the problem. We attributed the cause more than likely to how the text data was stored on the SEC Edgar database which proved to be a rather interesting reminder on how data sources can change quite quickly. We handled the issue by simply wrapping a standard timer class and function inside the scraper, since the problem could not be isolated down to a single point. After that, we were able to retrieve the text data without hindrance.</p><p>We faced a similar issue with data sources when it came to obtaining daily stock prices. At first, we tried to retrieve data from Alpha Vantage through their documented API using our own API key, but Alpha Vantage limited how much data we could call on in a day, requiring premium membership to do more. We instead turned to Quandl, which is another source of economic and financial data, so we could use their Wiki dataset. It should be noted that people began to turn from Quandl to Alpha Vantage after the Wiki dataset was discontinued in April 2018. With some degree of irony, we ended up turning from Alpha Vantage to Quandl’s Wiki dataset, since we only needed data up to April 2018 to compare our approach to the original developer.</p><p>Ultimately, we ended up with approximately 19,000 documents, slightly less than what Atkan had to start with, since the scraper had to skip a few hundred documents. The dataset was around 3 gigabytes in size at this point with some documents having a massive word count. In fact, a handful of documents had close to three million words in length despite our timer. It became evident to us that the data we procured was not clean and needed to be brought down to its necessary components. This part proved to be tricky, yet the solution turned out to be rather simple. In the original, the text documents obtained had information such as the accession number and so forth, that would not help us. Towards the end of these parts, however, there was a field called “Check the appropriate box.” Using regular expressions, we were able to eliminate all of the text leading up to this phrase. Still, our text data continued to have extraneous data. In order to find the most relevant information, we had to look on the second page where we identified a recurring pattern in the documents where the word “On” was usually used to precede the start of the actual information divulged by the corporation in question.</p><p>Using regular expression, we started to look for that particular word in the document, allowing us to obtain more quality data. The price for this, however, was the decrease in the number of documents we could use. Atkan had 17,000 after data preprocessing, while we were down to 11,000. On the other hand, our file size was brought down to 22 megabytes after we handled the documents with the excessive word counts. Most importantly, however, we ended up with a more polished set of documents brought down to its necessary parts.</p><p>Atkan’s Original Text Document Summary:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/0*Lf1L8O98vMP8GnPk" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/290/0*Of2_V_xg61QGfdOX" /></figure><p>Our Team’s Text Document Summary:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/0*Y30CgGgUgbSM8PEX" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/0*N7Ry0OZwF8HPQ9oa" /></figure><p>At the end of our data preprocessing stage, we ended up with a data composition that differed from Atkan. For instance, we used the difference between adjusted opening and adjusted closing price to obtain the normalized price change for each stock, while Atkan used the difference between the normal opening price and the adjusted closing price to gather his normalized price change which might account for the difference. We should note for transparency’s sake that the Wiki dataset may differ in how it calculates adjusted stock prices from Alpha Vantage. On the other hand, we should see no difference when it comes to calculating the difference in index price from Atkan’s end or ours, since adjusted and normal prices are the same for the GSPC and VIX. They represent index prices, so they do not need to account for dividends, stock splits, and so on. So, using adjusted or normal prices does not matter when calculating the price change for the index, so we felt comfortable using adjusted prices when finding the price change for stocks. Additionally, we also slightly altered the code used to obtain said price changes which may have also played a part.</p><p>All of this put together caused us to end up with different numbers in terms of the three classes we have: up, stay, and down. Up is basically anything over 1% increase, stay is anything between 1% and -1%, and down is anything that constitutes a decrease of more than 1%. The bulk of our data would have constituted what we classified as “stay” at around 66%, while we ended up evenly splitting up and down for the rest of the 33%. Atkan, on the other hand, had around 58% in the “up” class, 18% in the “down” class, and around 24% in the “stay” class. Unlike Atkan, we did not use historical price trends for our processing, though we have gathered it for a possible future project. Lastly, we decided to use oversampling like our predecessor to deal with the class imbalance problem we faced which would improve our model’s accuracy significantly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/0*OvvyNtXebwS9AT-l" /></figure><p>Above is the signal distribution of the raw data. Note that the distribution is different from Aktan’s due to a difference in computing it.</p><h3><strong>BERT</strong></h3><p>Of all of the options available for us in this analysis, we wanted to use the BERT (Bidirectional Encoder Representations from Transformers) model. BERT is the latest pre-trained language model introduced by researchers at Google AI Language just last year (published in <a href="https://ai.googleblog.com/2018/11/open-sourcing-bert-state-of-art-pre.html">this</a> paper). The main benefit of using this model is that we would capture context in a document. In Aktan’s article, he used embeddings from <a href="https://nlp.stanford.edu/projects/glove/">Stanford’s GloVe</a> (Global Vectors for Word Representation) instead, but the flaw we noticed was that it actually does not take context from the SEC Forms 8-K into account. We felt that by doing so, our model can better understand the implications of these documents and arrive at a conclusion that has better predicting power.</p><p>Prior to BERT, models had trouble capturing the contextual information of a word because they could only analyze the words preceding it. These are known as directional models because they read text inputs sequentially. With BERT however, we are able to overcome this obstacle in the form of two key methods: Masked Language Modeling (MLM) and Next Sentence Predicting (NSP).</p><h4><strong>Training Strategies</strong></h4><p>The reason models in the past could never use bidirectional methods is because the word being predicted would essentially have to already know what itself is when feeding it into the first layer. Conditioning on the previous <em>and </em>following word was simply not feasible until Masked Language Modeling. In MLM, 15% of the words in each sequence are masked and the model attempts to predict them based on the context of other non-masked words. This way, the model is able to use both sides of a word (bidirectional) as context for the context of the word that is being analyzed. An example of this is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/0*DKCm0ejjzFKjjkfb" /></figure><p>Source: <a href="https://ai.googleblog.com/2018/11/open-sourcing-bert-state-of-art-pre.html">https://ai.googleblog.com/2018/11/open-sourcing-bert-state-of-art-pre.html</a></p><p>Another key method in bidirectional training is the Next Sentence Predicting method. When BERT is being trained, the model is fed pairs of sentences and predicts whether the second sentence is subsequent or not. In order to do so, 50% of the inputs are in fact subsequent, while the remaining 50% are random sentences form the corpus. This helps the model learn relationships throughout the training process and ultimately helps distinguish between the two sentences. An example is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/0*FNnnB1rmF6cbftVH" /></figure><p>Source: <a href="https://ai.googleblog.com/2018/11/open-sourcing-bert-state-of-art-pre.html">https://ai.googleblog.com/2018/11/open-sourcing-bert-state-of-art-pre.html</a></p><p>Something to keep in mind is that both of these methods (MLM &amp; NSP) are trained simultaneously in BERT, with the overall goal of minimizing loss. Additionally, what made these methods even possible were Tensor Processing Units (TPUs), which essentially allow for maximum performance with the ability to quickly debug and edit models. If you are interested, you can read more <a href="https://cloud.google.com/tpu/docs/tpus">here</a>.</p><p><strong>BERT Implementation</strong></p><p>BERT already comes with a specific tokenizer for preprocessing text. First, we need to specify a max sequence length from our data to be input into the model. Because of our current hardware limitations, we played it safe and only allowed for a max sequence length of 128. What this means is that our model would only see the first hundred or so words in the text. This made the preprocessing crucial, and explains why we would rather cut our data by almost 50% instead of keeping the useless text. Furthermore, we would lose a few more words, as the BERT tokenizer adds CLS tokens at the beginning of a sentence pair and SEP tokens are added at the end of both the first and second sequence.</p><p>Once the data passes through the model, we have the option of extracting the pooled output or the sequence output. For a classification task such as ours (up, down, or stay), we requested the pooled output, which is only the output vector of the CLS token. With this output vector, an additional layer is added in order to be more specific in how we want to train. This process is known as “fine-tuning” and in our case, we added a fully connected dense layer.</p><h3><strong>Results</strong></h3><p>Unlike the original project, we did not separate our training data and test data by random sampling, rather we wanted to avoid using information from the “future” so to speak and avoid potentially biasing our results. In order to represent the real world better, we separated our test data and training data by time with a 90/10 split where the test data took on the most recent data while training data took on the rest.</p><p>After fitting our model of BERT + single layer MLP on the processed text data, our model produced a loss of 0.448 and an out of sample accuracy of 60.39%. This is impressive as it outperforms Aktan’s GloVe + single layer MLP (which had about 45% accuracy on a test data set). However, the result is disappointing as the baseline for accuracy in our testing data is 63% which could be achieved by labeling all data as “stay.”</p><p>Class imbalance proved to be the main issue we faced at this point, so we used oversampling. Within the original training data set, we resampled the data with replacement to create a new, balanced training set with the same number of rows labeled as “up,” “down,” or “stay.” With this resampled data, we re-trained the BERT + single layer MLP model with processed text data. The model produced a loss of 1.18 in the final step of training, but had an out of sample accuracy of 71%.</p><p>This result is a major improvement over our previous model. It also exceeds the baseline test accuracy of 66% which can be obtained by choosing only “stay” for the test data set. Furthermore, our model outperformed all of the models described in our Aktan’s blog with only one hour of training on the Google Colaboratory GPU runtime.</p><p>Our Test Data Signal Composition:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/0*dBL5Zae0pz7WDjC_" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/0*-qwwJYQ0BU7-bZFW" /></figure><p>These results are surprising, as we did not expect to outperform the original blog’s models. We consider this result as evidence of the effectiveness of Google’s BERT model for contextual language processing. Since BERT considers the context of the tokens, it was able to store more information relevant to the stock market into each of its word embeddings. This single deviation from using GloVe’s word embeddings allowed us to get better results from our model, and it highlights the idea that context is key in natural language processing. From Aktan’s models, we already knew that the SEC Form 8-K texts were useful in predicting the S&amp;P 500, and our project supports this idea.</p><p>We expect that we can improve this model by using some of the ideas that we did not carry over from Aktan’s original blog. For instance, Aktan’s model takes in the SEC Form 8-K text as well as some financial data as its inputs. Once we extract the CLS token’s vector from BERT, we could pass it through a network with other financial data vectors, in an attempt to improve our out of sample accuracy. Another idea would be to utilize an RNN, specifically an LSTM, on the token sequence vectors that we did not extract from BERT to see if that can improve our out of sample accuracy. This approach would also allow us look at the different weights in the network as they pertain to certain samples of data and pinpoint exactly which tokens are the most important within the Form 8-K text.</p><p>In closing, we found this project to be a success. While the improvement is only 5% better than the baseline, there is evidence that our network is using text to correctly predict some rises and falls within the S&amp;P 500. Our improvements over Aktan’s model, despite using similar data, also highlight the effectiveness of BERT over GloVe for handling text data at the present time. Finally, the code for this project can be found here (https://github.com/markbabbe/BERT-Stock-Prediction-Using-NLP).</p><p>And to answer the burning question on everyone’s mind, yes. Yes we have heard. That BERT is in fact, the word.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d5205b8537c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>