<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Stock Analysis | Nick Analytics</title>
	<atom:link href="https://www.nickanalytics.com/category/stock-analysis/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.nickanalytics.com</link>
	<description></description>
	<lastBuildDate>Mon, 03 Jun 2024 19:08:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://www.nickanalytics.com/wp-content/uploads/2024/03/cropped-mini-logo-wordpress-32x32.jpg</url>
	<title>Stock Analysis | Nick Analytics</title>
	<link>https://www.nickanalytics.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Stock Gap Analysis Using Streamlit</title>
		<link>https://www.nickanalytics.com/stock-gap-analysis-using-streamlit/</link>
		
		<dc:creator><![CDATA[Nick]]></dc:creator>
		<pubDate>Sat, 13 Apr 2024 15:34:22 +0000</pubDate>
				<category><![CDATA[Stock Analysis]]></category>
		<guid isPermaLink="false">https://nickanalytics.com/?p=647</guid>

					<description><![CDATA[As a stock market enthusiast I tried many strategies to make a profit with technical analysis and data predictions. Most of them failed, because the stock market is basically unpredictable. But I found one interesting phenomenon that could potentially turn your odds.]]></description>
										<content:encoded><![CDATA[
<div class="et_pb_section et_pb_section_0 et_section_regular" >
				
				
				
				
				
				
				<div class="et_pb_row et_pb_row_0">
				<div class="et_pb_column et_pb_column_4_4 et_pb_column_0  et_pb_css_mix_blend_mode_passthrough et-last-child">
				
				
				
				
				<div class="et_pb_module et_pb_text et_pb_text_0  et_pb_text_align_left et_pb_bg_layout_light">
				
				
				
				
				<div class="et_pb_text_inner"><h1 data-sourcepos="3:1-3:62" style="text-align: left;">Gap Strategy with Stocks</h1>
<p>Welcome to this new post about my Data Analytics journey.</p>
<p>As a stock market enthusiast I tried out many strategies to make a profit with technical analysis and data predictions. Most of them failed, because the stock market is basically unpredictable. And we as humans are impatient and want cash in on our profits as fast as we can.</p>
<p>One interesting thing I found during my ventures on the stock market, was the phenomenon of &#8216;gaps&#8217; in the stock price. I didn&#8217;t know they existed or were relevant, until I glared at my screen for hours and found a repeating pattern of gaps opening and closing.</p>
<p data-sourcepos="5:1-5:294">I decided to do my own investigation. I collected data, did some statistical analysis and came up with a strategy. Let&#8217;s see how this played out.</p>
<p>&nbsp;</p>
<h1>Introduction to Gaps</h1>
<p><span>Let me first explain what Gaps are:</span></p>
<p><strong><em>Gaps are areas where a stock&#8217;s price jumps sharply from one level to another without much trading in between. These gaps often occur due to after-hours news or events that cause a sudden increase in buying or selling pressure. </em></strong></p>
<p>Gaps are clearly visible on stock charts when the candle view is chosen:<strong><em></em></strong></p>
<p>&nbsp;</p></div>
			</div><div class="et_pb_module et_pb_image et_pb_image_0">
				
				
				
				
				<span class="et_pb_image_wrap has-box-shadow-overlay"><div class="box-shadow-overlay"></div><img fetchpriority="high" decoding="async" width="869" height="550" src="https://nickanalytics.com/wp-content/uploads/2024/05/Gap-Close.jpg" alt="Stock Gaps" title="Gap Close" srcset="https://www.nickanalytics.com/wp-content/uploads/2024/05/Gap-Close.jpg 869w, https://www.nickanalytics.com/wp-content/uploads/2024/05/Gap-Close-480x304.jpg 480w" sizes="(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 869px, 100vw" class="wp-image-654" /></span>
			</div><div class="et_pb_module et_pb_text et_pb_text_1  et_pb_text_align_justified et_pb_bg_layout_light">
				
				
				
				
				<div class="et_pb_text_inner"><p style="text-align: center;"><em>Disney (DIS) chart Feb-Apr 2024 (in days).</em></p>
<h3></h3>
<h3>What happened here?</h3>
<p>On the chart an Open Gap is formed on the left. Price jumped up from one day to the next leaving a large gap (price difference) between the previous top and the next bottom of the candles. This is called a gap, or a &#8216;<strong>price inbalance&#8217;</strong>. The general belief in the market is that gaps act as &#8216;magnets&#8217; that want to draw the price of the stock back to the point where the gap started, thus creating a &#8216;Gap Close&#8217; and restoring the balance.</p>
<p>After the Gap came about we see the plot continue to rise, but some weeks later a price fall sets in and now the ideal target would be the point where the gap has closed. And yes, we see the chart move in that direction.</p>
<p>&nbsp;</p>
<h3>Same day gap closes</h3>
<p>A &#8216;same day gap close&#8217; happens when the stock price leaves a gap at the opening, but that gap is closed or filled that same day. This is a phenomenon we see happening over and over again. And not just on daily charts. It is can be viewed on weekly, hourly or minute charts as well.</p></div>
			</div><div class="et_pb_module et_pb_text et_pb_text_2  et_pb_text_align_justified et_pb_bg_layout_light">
				
				
				
				
				<div class="et_pb_text_inner"><h1></h1>
<h1>Developing the &#8216;Gap Dashboard&#8217;</h1>
<p style="text-align: left;">It is not so easy to watch charts for gaps and come up with a workable strategy. That is why I created a <span>Streamlit dashboard</span><span> that allows users to select a ticker, define a date range, and analyze the gaps for that particular stock. The dashboard utilizes Python’s </span><code>yfinance</code><span> library to fetch historical stock data and </span><code>pandas</code><span> for data manipulation. In order to create a nice front-end I used the python library Streamlit.</span></p>
<p style="text-align: left;"><span></span></p>
<h3>Steps and Features</h3>
<p>Here are the key features and steps I integrated into the dashboard:</p>
<p>&nbsp;</p>
<ol>
<li><strong>Setting Up the Environment:</strong>
<ul>
<li style="list-style-type: none;">
<ul>
<li>The Streamlit dashboard is set up with a configuration that includes custom CSS for styling, ensuring a user-friendly interface.</li>
</ul>
</li>
</ul>
</li>
<li><strong>Ticker and Date Selection:</strong>
<ul>
<li style="list-style-type: none;">
<ul>
<li>Users can select from a predefined list of tickers and specify how many years ago they want to analyze, using a slider for the date range. This flexibility allows for dynamic analysis over different periods.</li>
</ul>
</li>
</ul>
</li>
<li><strong>Data Fetching and Processing:</strong>
<ul>
<li style="list-style-type: none;">
<ul>
<li>The application fetches data from Yahoo Finance using the <code>yfinance</code> library. Data such as opening, high, low, and closing prices are retrieved and processed.</li>
<li>The dates are localized to ensure consistency in the data.</li>
</ul>
</li>
</ul>
</li>
<li><strong>Gap Detection Algorithm:</strong>
<ul>
<li style="list-style-type: none;">
<ul>
<li>The dashboard identifies two types of gaps: <strong>True Gaps</strong> and <strong>Same Day Closes</strong>. True gaps are where the stock does not return to its previous day&#8217;s range in the next session, while same day closes are gaps that return to the previous day’s range within the same trading day.</li>
</ul>
</li>
</ul>
</li>
<li><strong>Visualization and Metrics:</strong>
<ul>
<li style="list-style-type: none;">
<ul>
<li>My application provides a visual representation of gaps and a detailed breakdown of each type, including the size of the gaps and their dates.</li>
<li>Additional metrics such as the nearest gap, mean gap size, and correlations between gap size and duration are calculated and displayed.</li>
</ul>
</li>
</ul>
</li>
<li><strong>Interactive Charts and Data Tables:</strong>
<ul>
<li style="list-style-type: none;">
<ul>
<li>A line chart showing the stock&#8217;s closing prices over the selected date range helps users visually identify the gaps.</li>
<li>Interactive data tables display the list of identified gaps, providing a clear and actionable insight into the gap analysis.</li>
</ul>
</li>
</ul>
</li>
</ol></div>
			</div><div class="et_pb_module et_pb_image et_pb_image_1">
				
				
				
				
				<a href="https://nickanalytics.com/wp-content/uploads/2024/05/Dashboard.jpg" class="et_pb_lightbox_image" title="classified text"><span class="et_pb_image_wrap has-box-shadow-overlay"><div class="box-shadow-overlay"></div><img decoding="async" width="1803" height="876" src="https://nickanalytics.com/wp-content/uploads/2024/05/Dashboard.jpg" alt="classified text" title="Dashboard" srcset="https://www.nickanalytics.com/wp-content/uploads/2024/05/Dashboard.jpg 1803w, https://www.nickanalytics.com/wp-content/uploads/2024/05/Dashboard-1280x622.jpg 1280w, https://www.nickanalytics.com/wp-content/uploads/2024/05/Dashboard-980x476.jpg 980w, https://www.nickanalytics.com/wp-content/uploads/2024/05/Dashboard-480x233.jpg 480w" sizes="(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) and (max-width: 1280px) 1280px, (min-width: 1281px) 1803px, 100vw" class="wp-image-660" /></span></a>
			</div><div class="et_pb_module et_pb_text et_pb_text_3  et_pb_text_align_justified et_pb_bg_layout_light">
				
				
				
				
				<div class="et_pb_text_inner"><p style="text-align: center;"><em>Impression of the result</em></p>
<h3 style="text-align: left;"></h3>
<h3 style="text-align: left;">Two strategy examples (for educational use only)</h3>
<p style="text-align: left;">I have defined two strategies that may succesfully play the Gap:</p>
<p style="text-align: left;">&#8211; first one is to go for the &#8216;<strong>same day gap close</strong>&#8216;.</p>
<p style="text-align: left;">&#8211; second one is to evaluate a gap that hasn&#8217;t closed the same day and use statistics to make your &#8216;bet&#8217;.</p>
<h3 style="text-align: left;">Same day Gap Close Strategy</h3>
<p>In the Dashboard I visualized how many same day closes there were in the selected timeframe (2,5 years for Microsoft):</p></div>
			</div><div class="et_pb_module et_pb_image et_pb_image_2">
				
				
				
				
				<a href="https://nickanalytics.com/wp-content/uploads/2024/05/Same-Day-Closes-MSFT.jpg" class="et_pb_lightbox_image" title="clustered histogram"><span class="et_pb_image_wrap has-box-shadow-overlay"><div class="box-shadow-overlay"></div><img loading="lazy" decoding="async" width="339" height="560" src="https://nickanalytics.com/wp-content/uploads/2024/05/Same-Day-Closes-MSFT.jpg" alt="clustered histogram" title="Same Day Closes MSFT" srcset="https://www.nickanalytics.com/wp-content/uploads/2024/05/Same-Day-Closes-MSFT.jpg 339w, https://www.nickanalytics.com/wp-content/uploads/2024/05/Same-Day-Closes-MSFT-182x300.jpg 182w" sizes="(max-width: 339px) 100vw, 339px" class="wp-image-663" /></span></a>
			</div><div class="et_pb_module et_pb_text et_pb_text_4  et_pb_text_align_justified et_pb_bg_layout_light">
				
				
				
				
				<div class="et_pb_text_inner"><p style="text-align: left;"><em>MSFT Same Day Gap Closes in the last 2,5 years</em></p></div>
			</div><div class="et_pb_module et_pb_text et_pb_text_5  et_pb_text_align_justified et_pb_bg_layout_light">
				
				
				
				
				<div class="et_pb_text_inner"><p>It is pretty impressive to know that almost 71% of all gaps that occur close the same day. If you play this consistenly you may have a pretty high chance of success.</p>
<p>&nbsp;</p>
<h3>Strategy for multiple day gaps</h3>
<p>Gaps that last longer than 1 day need some more metrics to make a calculated guess if the gap will be closed any time soon. One nice plot I created is the &#8220;<span style="font-size: 15px;">Days to close a Gap, given the Gap Size&#8221;. I want to know if larger gaps take more time to close. In order to check that I created 2 visuals:</span></p>
<p>&#8211; <strong>First Visual</strong>: The <strong>C</strong><span><strong>orrelation</strong> between gap_size and duration<br />This metric gives and indication if smaller size gaps take less time, and larger size gaps take more time to close. For Microsoft the outcome was:</span></p>
<p><span></span></p></div>
			</div><div class="et_pb_module et_pb_image et_pb_image_3">
				
				
				
				
				<span class="et_pb_image_wrap has-box-shadow-overlay"><div class="box-shadow-overlay"></div><img loading="lazy" decoding="async" width="268" height="72" src="https://nickanalytics.com/wp-content/uploads/2024/05/correlation.jpg" alt="" title="correlation" class="wp-image-666" /></span>
			</div><div class="et_pb_module et_pb_text et_pb_text_6  et_pb_text_align_justified et_pb_bg_layout_light">
				
				
				
				
				<div class="et_pb_text_inner"><p>This means that for MSFT there is barely any relationship between gap_size and its duration.</p>
<p>&nbsp;</p>
<p>&#8211; <strong>Second Visual</strong>: A Scatter plot showing the gap_size with duration.</p>
<p>Indicated below is the chart of MSFT (april 2024).</p></div>
			</div><div class="et_pb_module et_pb_image et_pb_image_4">
				
				
				
				
				<span class="et_pb_image_wrap "><img loading="lazy" decoding="async" width="767" height="394" src="https://nickanalytics.com/wp-content/uploads/2024/05/Scatter-Gap-Size-vs.-Duration.jpg" alt="" title="Scatter Gap Size vs. Duration" srcset="https://www.nickanalytics.com/wp-content/uploads/2024/05/Scatter-Gap-Size-vs.-Duration.jpg 767w, https://www.nickanalytics.com/wp-content/uploads/2024/05/Scatter-Gap-Size-vs.-Duration-480x247.jpg 480w" sizes="(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 767px, 100vw" class="wp-image-664" /></span>
			</div><div class="et_pb_module et_pb_text et_pb_text_7  et_pb_text_align_justified et_pb_bg_layout_light">
				
				
				
				
				<div class="et_pb_text_inner"><p style="text-align: left;">This plot indicates that from the 63 multiple day gap closes, 52 closed roughly within 30 days. The other 11 are more or less outliers where the closure could take up to 500 days in this example.</p>
<p style="text-align: left;">So, knowing that there is no relationship between size and duration, and knowing that 80% of the multi day gaps of MSFT closed within 30 days, we can formulate a strategy. This strategy could be to wait for the market to start moving into the direction of the gap and then buy or sell those stocks.</p>
<p style="text-align: left;">*** <strong>Note</strong>: the 2 strategies I described above do not serve as advice, but only for <strong>educational purposes</strong>.</p>
<p style="text-align: left;"></div>
			</div><div class="et_pb_module et_pb_text et_pb_text_8  et_pb_text_align_left et_pb_bg_layout_light">
				
				
				
				
				<div class="et_pb_text_inner"><h3>Check out my dashboard</h3>
<p>My dashboard can be found on this link: <a href="https://gap-detection-in-stocks.streamlit.app/" title="Nick Analytics Dashboard">Nick Analytics Dashboard</a> or press the button:</p></div>
			</div><div class="et_pb_button_module_wrapper et_pb_button_0_wrapper et_pb_button_alignment_center et_pb_module ">
				<a class="et_pb_button et_pb_button_0 et_pb_bg_layout_light" href="https://gap-detection-in-stocks.streamlit.app/" target="_blank">My Dashboard</a>
			</div><div class="et_pb_module et_pb_text et_pb_text_9  et_pb_text_align_justified et_pb_bg_layout_light">
				
				
				
				
				<div class="et_pb_text_inner"><h1>Conclusion</h1>
<p>In this blog post, I have explored the steps of analyzing Gaps in stock prices. I created a Streamlit Dashboard that can display the gaps and point to trading opportunities. I added statistics to back up the decision making process.</p>
<p>Thanks for reading my blog.</p>
<p>&nbsp;</p></div>
			</div><div class="et_pb_module et_pb_text et_pb_text_10  et_pb_text_align_justified et_pb_bg_layout_light">
				
				
				
				
				<div class="et_pb_text_inner"><h3>The coding I&#8217;ve done (in VS Code)</h3>
<p>Check out the code of this project on Github: <a href="https://github.com/nickanalytics/Gap-Detection-in-Stocks" title="Gap Detection in Stocks">Gap Detection in Stocks</a><a href="https://colab.research.google.com/drive/12fzJuVqZ5-AMaH_h2nXqaicj_Z8doglX?usp=sharing" title="PyCaret use case"></a></p></div>
			</div><div class="et_pb_module et_pb_divider et_pb_divider_0 et_pb_divider_position_ et_pb_space"><div class="et_pb_divider_internal"></div></div>
			</div>
				
				
				
				
			</div>
				
				
			</div>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
