<?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 Maxim on Medium]]></title>
        <description><![CDATA[Stories by Maxim on Medium]]></description>
        <link>https://medium.com/@kiesel_maxim?source=rss-2b977ea9b888------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2G5aAJWDiSH0OS-IISAgUw.jpeg</url>
            <title>Stories by Maxim on Medium</title>
            <link>https://medium.com/@kiesel_maxim?source=rss-2b977ea9b888------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 16:30:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kiesel_maxim/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[Unleashing the Power of LSTM: A Comparative Study on Predicting Stock Prices Across Different…]]></title>
            <link>https://medium.com/@kiesel_maxim/unleashing-the-power-of-lstm-a-comparative-study-on-predicting-stock-prices-across-different-4798977c1af3?source=rss-2b977ea9b888------2</link>
            <guid isPermaLink="false">https://medium.com/p/4798977c1af3</guid>
            <category><![CDATA[stonks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[lstm]]></category>
            <category><![CDATA[stock-market]]></category>
            <category><![CDATA[stocks]]></category>
            <dc:creator><![CDATA[Maxim]]></dc:creator>
            <pubDate>Sun, 14 May 2023 10:13:31 GMT</pubDate>
            <atom:updated>2023-05-15T16:35:47.183Z</atom:updated>
            <content:encoded><![CDATA[<h3>Unleashing the Power of LSTM: A Comparative Study on Predicting Stock Prices Across Different Market Segments</h3><h4>Exploring the Limits of Predictive Analytics: A Comparative Analysis of LSTM Models for Stock Price Forecasting in Varied Market Segments</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Y5nx9iQZ2DXTQaY5" /><figcaption>Photo by <a href="https://unsplash.com/@nampoh?utm_source=medium&amp;utm_medium=referral">Maxim Hopman</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>In the dynamic world of data science, various realms continue to <br>fascinate and challenge professionals and enthusiasts alike. One such <br>domain is stock price prediction — a field that intersects finance and <br>machine learning, and holds the power to guide critical investment decisions.</p><p>In this blog post, we will navigate the complex landscape of stock price prediction, focusing on the application of a powerful machine learning technique known as Long Short-Term Memory (LSTM). This sophisticated variant of Recurrent Neural Networks (RNNs) has garnered significant attention due to its capability to capture long-term dependencies in time-series data, a property that makes it highly suitable for this task at hand.</p><p>I chose to compare predictive performance across four distinct types of stocks: blue-chip represented by BMW.DE, growth stocks illustrated by TSLA and BTC-USD, dividend stock using JNJ as an example, and small-cap stock represented by ETSY.</p><p>This analysis will provide insights into the performance of the model across different types of stocks and how it varies among them.</p><h3>Technical Concept</h3><p>To evaluate the performance of my model, I used the Mean Absolute Percentage Error (MAPE).</p><pre>MAPE = (1/n) * Σ|[(Yi - Ŷi) / Yi]| * 100</pre><p>MAPE is a widely accepted metric in the forecasting literature and is particularly useful when working with percentage-based data, such as stock prices. The metric provides a measure of the average percentage error in the model’s predictions, making it easy to interpret and compare across different models.</p><p>Also, MAPE is a symmetric metric that takes into account both positive and negative errors, which is especially important in stock market prediction where market movements can be in either direction. By using the absolute value of the error term, MAPE ensures that both over- and under-predictions are treated equally.</p><p>Lastly, MAPE is a relative measure, meaning that it is independent of the scale of the data being predicted. This makes it useful for comparing the performance of different models across different stocks, time periods, and other contexts.</p><p>The objective is to achieve a MAPE of less than 5% for predicting the Adjusted Close, which is the target variable.</p><p>My choice for using LSTM, implemented via the Keras library, is driven by its ability to capture long-term dependencies in sequential data — a feature that makes it a powerful tool for stock price prediction.</p><p>At the core of an LSTM model is the LSTM cell, which consists of three main components: the input gate, the forget gate, and the output gate. These gates are used to regulate the flow of information into and out of the cell, allowing the model to selectively remember or forget information over time.</p><p>The input gate controls the flow of new information into the cell. It takes as input the current input vector and the previous hidden state and applies a sigmoid activation function to produce a value between 0 and 1. This value determines how much of the new information should be added to the cell.</p><p>The forget gate controls the flow of information from the previous hidden state. It takes as input the previous hidden state and the current input vector and applies a sigmoid activation function to produce a value between 0 and 1. This value determines how much of the previous hidden state should be retained in the cell.</p><p>The output gate controls the flow of information out of the cell. It takes as input the current input vector and the current hidden state and applies a sigmoid activation function to produce a value between 0 and 1. This value determines how much of the current hidden state should be output.</p><p>In addition to these gates, the LSTM cell also includes a memory cell that stores long-term information. The memory cell is updated by the input gate and forget gate based on their respective values, and then passed through an activation function to produce the current hidden state.</p><p>During training, the LSTM model adjusts the weights of the gates and the memory cell to minimize the difference between the predicted output and the true output. This is done using backpropagation through time, which computes the gradients of the loss function with respect to the LSTM model parameters and updates them using gradient descent.</p><p>The goal of my project was to predict the Adjusted Close stock price for future timeframes of 7, 14, and 28 days. I sourced the data from the <a href="https://de.finance.yahoo.com/">Yahoo Finance</a> API, a popular choice for obtaining historical stock data.</p><p>Upon acquiring the data, I divided it into training, validation, and testing sets in a 60:20:20 ratio, respectively. For the LSTM networks to process the data, a transformation into a time series format was necessary. Here is an example for the data transformation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vUxmJUy2050dfFfys3xLiw.png" /><figcaption>Figure 1.: Data Transformation in X- and y-Data for time series prediction</figcaption></figure><p>To begin with, it’s important to define a window size that specifies the number of days the model should consider for prediction. This window size represents the X-data for all features, including the Adjusted Close. The day following the window size represents the y-data. In the next iteration, the entire process shifts by one day and repeats.</p><p>During data preprocessing, I identified and treated outliers using the Z-score method, setting a threshold at 3. This approach helped me to ensure the quality of the data. Here is an example of outlier in the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1feZTtRWrATo5ibSbnMkrw.png" /><figcaption>Figure 2.: Outliers in the Volume data</figcaption></figure><p>When plotting the Volume data against the Adjusted Close, certain values fall outside the normal range and may have a negative impact on the model.</p><p>Afterward, I applied Z-transformation to normalize the data, which is a critical step in preparing the data for LSTM, as it can help the model perform better by bringing all features to a similar scale.</p><h3>Exploratory Data Analysis (EDA)</h3><p>I conducted a thorough EDA to better understand the structure and characteristics of the data. Here’s a more detailed summary of my findings:</p><ul><li><strong>Outliers</strong>: All datasets contained outliers, primarily in the volume feature. I found it important to treat these outliers to prevent them from skewing the results of the model.</li><li><strong>NaN-Values</strong>: No NaN values were found in the datasets, indicating good overall data quality.</li><li><strong>Rolling Mean High-Low Comparison</strong>: I observed significant price differences between the High and Low prices during peak trading periods, indicating high volatility during these periods.</li><li><strong>Rolling Mean Open-Close-Adj_Close Comparison</strong>: All datasets showed negligible differences between Open and Close prices, except for BMW.DE and JNJ, where different Adjusted Close values were found.</li><li><strong>Daily Price-Change</strong>: I found that BMW.DE had small daily price changes indicating low volatility, while ETSY, JNJ, TSLA displayed higher volatility. Interestingly, BTC-USD was more stable than expected.</li><li><strong>Adjusted Close/Volume Correlation</strong>: There were no correlations between Adjusted Close and Volume for ETSY and JNJ. BMW and Tesla showed a slight negative correlation, while BTC-USD exhibited a slight positive correlation.</li><li><strong>Monthly Price Difference</strong>: I found no consistent pattern of higher or lower prices in the same months over the years. This suggests that the stocks do not exhibit a strong seasonality pattern, at least on a monthly basis.</li></ul><h3>Feature Engineering</h3><p>I trained the LSTM model using six features: Open, Close, High, Low, Volume, and Adjusted Close. Interestingly, the model’s performance declined when I introduced more 11 additional features including Moving Averages, Average True Range, Bollinger Band, Moving Average Convergence Divergence, Relative Strength Index, Stochastic Oscillator, and Stochastic signal. It appears that these additional features added more noise than valuable, predictive information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*2mGBhAGHqL2idY2ly91xsQ.png" /><figcaption>Figure 3.: MAPE-Score comparison</figcaption></figure><p>There could be several reasons for the higher MAPE score when using the additional features:</p><ol><li>Overfitting: The additional features may have introduced noise or irrelevant information to the model, causing it to overfit the training data and perform poorly on the test data.</li><li>Multicollinearity: The additional features may have been highly correlated with each other or with the existing features, leading to multicollinearity issues that can make it difficult for the model to distinguish their individual effects.</li><li>Data quality: The additional features may have contained errors or missing values that negatively impacted the model’s performance.</li><li>Complexity: The additional features may have increased the complexity of the model, making it more difficult to train or interpret.</li><li>Lack of relevance: The additional features may simply not have been relevant to the prediction task at hand, and including them may have added unnecessary complexity without improving performance.</li></ol><p>Here is visual comparison between a model with 6 features and one with 17 features for the same stock.</p><p><em>Comparison for 6 Features:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gTdOu2_7QKZWiLg50oY-7w.png" /><figcaption>Figure 4.: Model comparison with 6 features</figcaption></figure><p><em>Comparison for 17 Features:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IdFGwXwOulzNedjMbw3EPA.png" /><figcaption>Figure 5.: Model comparison with 17 features</figcaption></figure><p>Visually, there are clear differences here.</p><h3>Modeling</h3><p>The training process was conducted over 200 epochs. To tune the model, I randomly generated and tested different parameters over 20 rounds, including the following parameters.</p><pre>{&#39;window_size&#39;: [4, 8, 12, 20], <br>&#39;lstm_units&#39;: [16, 32, 64, 128], <br>&#39;dense_units&#39;: [16, 32, 64, 128],<br>&#39;learning_rate&#39;: [0.0001, 0.001, 0.01, 0.1]}</pre><p>While this exploration didn’t cover all possible parameter combinations, it was a practical choice considering the extensive training time required for each round.</p><p>During the modeling phase, I retrieved the data from the SQL database, followed by splitting, training, and model validation. I created validation graphs to visually compare the actual and predicted values. I then used the trained model to predict the Adjusted Close price for the next 7, 14, and 28 days. These predictions were also visualized using graphs to facilitate interpretation. Here is an example for a prediction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6NfkAL_oGdF8506lf6C3XA.png" /><figcaption>Figure 6.: Visualization of a prediction</figcaption></figure><h3>Conclusion</h3><p>After running my model on different types of stocks, I found that growth stocks (TSLA and BTC-USD) and the small-cap stock (ETSY) performed worse than blue-chip (BMW.DE) and dividend stocks (JNJ). This was evident from the comparative graphs I generated.</p><p><em>Performance of the Stock ‘BMW.DE’:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AYscQ54T7HYGiUJW7h7yPw.png" /><figcaption>Figure 7.: Comparison between real and predicted data for the stock ‘BMW.DE’</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hKCbZJ-iBeyIvYZhCoUFeQ.png" /><figcaption>Figure 8.: Percentage deviation between real and predicted data for the stock ‘BMW.DE’</figcaption></figure><p><em>Performance of the Stock ‘TSLA’:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K_DBd8dYjbdNwawjniT-nQ.png" /><figcaption>Figure 9.: Comparison between real and predicted data for the stock ‘TSLA’</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1sa_YV8KRHBA8w1tqZqlHg.png" /><figcaption>Figure 10.: Percentage deviation between real and predicted data for the stock ‘TSLA’</figcaption></figure><p>The graphs indicate that there was a point in time when the accuracy of TSLA was notably low, despite the model following the actual data. Over-reliance on this machine learning model could therefore potentially be problematic.</p><p>To view additional visual comparisons, please visit my Github profile (link provided at the end of the article).</p><p>Nevertheless, I was able to achieve a MAPE score of &lt;5% of the presended stock tpyes.</p><p>Regarding future improvements, there are several potential routes to explore. For example, I could implement a form of cross-validation designed for time series analysis, or investigate other machine learning models such as Gradient Boosting Decision Tree or Autoregressive Integrated Moving Average (ARIMA) for comparison. I also could try different variable numbers of features to see what the ideal number would be for this purpose.</p><p>One particular aspect of the project that I found interesting was the data preparation process, which differed from other models due to the time series nature of the problem. In particular, transforming the data into X and y sets required careful consideration to ensure that the time series structure was preserved and that the model had access to the necessary information for making accurate predictions.</p><p>In closing, it should be noted that while LSTM models can be effective at predicting stock prices, it’s important to exercise caution when using them for specific stocks.</p><p><em>Note:</em> To see more about my algorithm, see the link to my <a href="https://github.com/maximkiesel1/Stock_Market_Prediction">Github-Profile</a>.</p><h3>Reference</h3><p>Yahoo Finance. (Accessed on May 16, 2023). Historical Data for BMW.DE Stock. <a href="https://finance.yahoo.com/quote/BMW.DE/history?p=BMW.DE">https://finance.yahoo.com/quote/BMW.DE/history?p=BMW.DE</a></p><p>Yahoo Finance. (Accessed on May 16, 2023). Historical Data for TSLA Stock. <a href="https://finance.yahoo.com/quote/TSLA/history?p=TSLA">https://finance.yahoo.com/quote/TSLA/history?p=TSLA</a></p><p>Hogg, G. (Host). (2021, March 12). LSTM Stock Market Prediction Example. [Video file]. Retrieved from <a href="https://www.youtube.com/watch?v=QIUxPv5PJOY&amp;t=2002s">https://www.youtube.com/watch?v=QIUxPv5PJOY&amp;t=2002s</a></p><p>Hogg, G. (Author). (Accessed on May 16, 2023). LSTM Model for Stock Market Prediction Notebook. [Google Colab notebook]. Retrieved from <a href="https://colab.research.google.com/drive/1b3CUJuDOmPmNdZFH3LQDmt5F0K3FZhqD?usp=sharing">https://colab.research.google.com/drive/1b3CUJuDOmPmNdZFH3LQDmt5F0K3FZhqD?usp=sharing</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4798977c1af3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[This analysis of the top 30 countries by GDP makes you think about mental health in this world]]></title>
            <link>https://medium.com/@kiesel_maxim/this-analysis-of-the-top-30-countries-by-gdp-makes-you-think-about-mental-health-in-this-world-9c5e96e037bd?source=rss-2b977ea9b888------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c5e96e037bd</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[mental-health]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[suicide-prevention]]></category>
            <dc:creator><![CDATA[Maxim]]></dc:creator>
            <pubDate>Wed, 18 Jan 2023 18:33:53 GMT</pubDate>
            <atom:updated>2023-01-19T09:34:23.020Z</atom:updated>
            <content:encoded><![CDATA[<h3>Can We Guess How Mental Health Is REALLY Doing?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A1np7Ri-GOovTTIhs98rMA.jpeg" /><figcaption>Source: unsplash.com/de/fotos/hluOJZjLVXc</figcaption></figure><p><strong>Introduction</strong></p><p>Mental Health is an important topic, but how much do we know about the current situation in the world, especially in the industrialized nations?</p><p>This post aims to raise awareness about suicide in our society and hopefully kickstart actions against it.</p><p>I have often heard things like…</p><blockquote>“ Just Japan has a high suicide rate.”</blockquote><blockquote>“Teenagers are the only ones who kill themselves.”</blockquote><blockquote>“In our generation, this wouldn’t happen.”</blockquote><p>… and so on. Maybe you have heard similar statements?</p><p>But is this all true? Which countries are really at the top of the food chain and how are their rates developing? How old are people when they decide to end their lives? Which generation tends to have a high suicide rate?</p><p>All of these questions will be answered throughout this article.</p><p><em>Note:</em> This analysis focuses on the period between 1985–2015 of the top 30 countries by GDP and uses a modified dataset from the WHO (World Health Organization).</p><p><strong>PART I: The Top Tier Countries</strong></p><p>As I mentioned in the beginning, I have often heard blanket statements about suicide. The next picture tells the real story.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TTvuuqOX-BvPOH4HSPguWQ.png" /><figcaption>Figure 1.: Time Series Of The Top 5 Countries By Suicide Rates</figcaption></figure><p>This graphic shows the 5 countries with the highest suicide rate per 100,000 inhabitants. This time series makes it clear that Japan does not have the highest suicide rate. There is a huge difference between the other top countries like Russia and South Korea (Republic of Korea).</p><p>The following bar chart shows a comparison between the mean suicide rate of the top 5 countries and to the recent year.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bSYjGDEfc6CdCCPmt-RLuQ.png" /><figcaption>Figure 2: Suicide Rate Comparison between Top 5 Countries</figcaption></figure><p>It´s clear that almost all countries have a significant reduce of the suicide rate. But this says not that suicide isn´t a problem anymore! The numbers a still to high. South Korea is an example that the trend don´t always go down. You see that there is an huge increase of the suicides.</p><p><strong>PART II: The Age Groups</strong></p><p>Do you know which age groups have a higher risk of committing suicide? A common assumption is that only teenagers commit suicide. The next chart tells another story.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ou1W3LaDEROHtfhwx_tK4A.png" /><figcaption>Figure 3.: Suicide Rate Comparison Between Age Groups</figcaption></figure><p>The harsh truth is that most people who end their lives are people over 74. The older the people get, the higher the suicide risk is. Also, every age group is affected, even the youngest of us.</p><p>The good news is that the trend goes down in almost each age group. The exception is the age group 5–14 years. The suicide rate is very low but has not changed over the years.</p><p><strong>PART III: The Generations</strong></p><p>The last question I asked myself was: Are there generations with higher suicide rates? This can lead to an explanation that the living conditions and the characteristics of a generation lead to higher or lower suicide rates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*62bZDZ-kCdczjJ-VjNGOeQ.png" /><figcaption>Figure 4.: Suicide Rate Comparison Between Generations</figcaption></figure><p>This graphic is in chronological order and shows the suicide rates from the oldest to the youngest generation. You can see that the highest rate is among the Silent Generation. The reason for this may be the difficult times due to wars, economic crises, and the fact that this generation tends to be older than 74.</p><p>After the Silent Generation, the trend goes down. However, after Generation X, the tendency goes steeply uphill. This means that the present generation tends to suffer more from suicide.</p><p><strong>Conclusion</strong></p><p>In this article, I aim to dispel common misconceptions and show the real situation in industrialized nations regarding suicide.</p><p>This analysis shows that although the general tendency for suicide goes down, there are countries that have a strong increase. One example is South Korea.</p><p>Also, the statement that only one group of people tends to commit suicide is incorrect. All age groups are affected, especially older people.</p><p>Lastly, some generations have higher and lower suicide rates, but the current situation is that the latest generations have an increase in their rates.</p><p>In conclusion, there are three things to note:</p><ul><li>Don´t be biased about countries when it comes to suicide.</li><li>Ask the people around you, especially the older ones, if they need somebody to talk.</li><li>Pay attention about the current generation, when it comes to mental health.</li></ul><p><em>Note:</em> To see more about this analysis, see the link to my <a href="https://github.com/maximkiesel1">Github-Profile</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c5e96e037bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>