<?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 Darshil Desai on Medium]]></title>
        <description><![CDATA[Stories by Darshil Desai on Medium]]></description>
        <link>https://medium.com/@darshildesai?source=rss-2b0a91553328------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*iElfWX6Sl_nBOxg8bIQhcw.jpeg</url>
            <title>Stories by Darshil Desai on Medium</title>
            <link>https://medium.com/@darshildesai?source=rss-2b0a91553328------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 01:01:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@darshildesai/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[Identifying Buy Signals for Stock Trading]]></title>
            <link>https://medium.com/@darshildesai/identifying-buy-signals-for-stock-trading-c03fba6e694d?source=rss-2b0a91553328------2</link>
            <guid isPermaLink="false">https://medium.com/p/c03fba6e694d</guid>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[stock-market]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-visualisation]]></category>
            <dc:creator><![CDATA[Darshil Desai]]></dc:creator>
            <pubDate>Thu, 23 Jan 2020 21:48:33 GMT</pubDate>
            <atom:updated>2020-01-23T21:57:37.322Z</atom:updated>
            <content:encoded><![CDATA[<h3>Identifying Buy Signals in Stock Trading</h3><p>In this article, I would like to introduce you to a buy signal strategy for U.S equities using <em>technical indicators</em>. Before you read any further, please be warned that there are no supervised machine learning algorithms employed here, only identifying trends!</p><p><em>Please note: This article is not meant to give you advice on buying specific stocks :)</em></p><h4>What are these technical indicators?</h4><p>According to <a href="https://school.stockcharts.com/doku.php?id=technical_indicators:introduction_to_technical_indicators_and_oscillators">StockCharts</a> a leading publication for technical indicator analysis, — “ <em>A technical indicator is a series of data points that are derived by applying a formula to the price data of a security.”</em></p><p>A simple example is illustrated below where the <em>moving average</em> indicator (blue line) formula is applied to <em>n</em> days from a date to the <em>n </em>days before that date. Using the image below, the average price between January 9, 2020, and 50 days before January 9, 2020, is around $271.33. Its called “moving” because, on Jan 10, 2020, the average formula will again take 50 days before Jan 10 thereby changing the overall input every day.</p><p>So clearly this is a technical indicator as we use the<strong> price</strong> <strong>data</strong> such as the price (obviously), volume, price the stock opened daily/weekly/monthly, price the stock closed daily/weekly/monthly, etc and then transform them into newer variables to use for further analysis. This transformation is analogous to feature engineering we often see applied to raw data to use as input data in machine learning algorithms.</p><p>You can learn more about the technical analysis <a href="https://school.stockcharts.com/doku.php?id=technical_indicators:introduction_to_technical_indicators_and_oscillators">here</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*RqP8TI4KzO1mV2lNRY-pwQ.png" /><figcaption>Image Source: <a href="https://stockcharts.com/h-sc/ui">Stockcharts</a></figcaption></figure><p>I hope that we’re on the same page with the concept of technical indicators which again are essentially some variables or features that provide lagging or leading information about the stock price movement, momentum, possible trend reversal signals, etc. In this article, I will showcase the use of 2 technical indicators, the <strong><em>RSI</em></strong> &amp; the <strong><em>MACDH</em></strong><em> </em>to try &amp; identify buy signals.</p><h4>A few examples where the algorithm recommends buy dates</h4><p><em>Example 1<br></em>To illustrate my point: the image below consists of the buy signals for the stock symbol <em>EXEL</em> generated <strong>using my strategy which makes use of <em>MACDH</em> &amp; <em>RSI</em> indicators simultaneously.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*van23ItI_Rxgj9eCMBYqDg.png" /></figure><p>The arrows along with the annotated month-day allow you to visually gauge how well your investment would have done should you have bought the stock on the dates shown. For instance, buying the stock on Jan 7th, 2019 would have had you enjoy the benefits of an upward run until about the end of the month. The value of returns (if any) you enjoy entirely depends on when you may choose to sell the equity. However, as one can see, not all is always well and good. There are times, such as on May 22, 2019, where an investment would have seen a significant decrease in its value up until June 2019 where it would perhaps break-even.</p><p><em>Example 2</em><br>Here is another example of buy signals recommended for the stock symbol <em>BIOS. </em>Although the strategy identifies some good buy signals, it misses out on quite a few between July 2019 and October 2019.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_oaXFH09lsAgBH8AOn9rTA.png" /></figure><p><em>Example 3</em><br>And here is another example of buy signals recommended for the stock symbol <em>AGFS. </em>Some good buy signals: November 27, 2019, | November 29,2019, |December 16, 2019. And some bad ones: January 6 &amp; 7, 2020</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M1XPGfr_CQxOhdL41lYmNQ.png" /></figure><p><em>Example 4</em><br>And here is yet another example of buy signals recommended for the stock symbol <em>INVA. </em>Some good buy signals: September 10, 2019, | October 15 &amp; 16,2019, |October 29 &amp; 39, 2019. And some bad ones: August 21 &amp; 30, 2019</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s4Rli1Y8kyvl8vyDbz41_Q.png" /></figure><h4>Diving deeper into how the algorithm recommends buying signals</h4><p>So now we arrive at what you may be curious about, what analytical techniques did I use? As mentioned before I simply look at the <em>MACDH</em> &amp; <em>RSI</em> indicators to help me identify buying signals. Here is how:</p><ul><li><strong>MACDH (Moving Average Convergence Divergence)</strong>: <br>Here is how its calculated, source <a href="https://school.stockcharts.com/doku.php?id=technical_indicators:macd-histogram">StockCharts</a></li></ul><pre>EMA = Exponential Moving Average</pre><pre>MACD: (12-day EMA - 26-day EMA) </pre><pre>Signal Line: 9-day EMA of MACD</pre><pre>MACD Histogram: MACD - Signal Line</pre><p>If you were to look at the chart below, you may see a trend in the histogram and the price movements. Essentially, the MACDH <em>is designed to reveal changes in the strength, direction, momentum, and duration of a trend in a stock’s price (source: </em><a href="https://en.wikipedia.org/wiki/MACD"><em>Wikipedia</em></a><em>) </em>So in this case, <strong>I look at the trend of MACDH values and if the general trend is just beginning to be positive</strong>, <strong><em>I flag that period of time to be possible buy time for the stock</em></strong>.</p><p>For example, you can in the chart below how the <strong>MACDH</strong> values (blue bars at the very bottom) move from being negative towards being positive, hence crossing the zero line at various instances. And every time this trend occurs, the price seems to be gaining upward momentum. Note the period from November 11 to November 18 where the general trend is positive and strong. Similarly, at the beginning of January 2020, you can see a positive trend in MACDH values and price momentum simultaneously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*i1bzyJWH0WIe13_DjCgdcw.png" /></figure><p>A word of caution: using MACDH values solely does NOT promise positive ROI on your investment. There have been numerous instances wherein a positive MACDH trend does <strong>NOT</strong> find itself hand in hand with a strong upward trend in price. Technical indicators simply assist you in possibly identifying short term signals, not a guarantee.</p><ul><li><strong>RSI: Relative Strength Index: </strong>Simply put, an RSI looks at recent price changes and determines if a certain stock is overbought or oversold. The implication here is that if a stock is oversold (and therefore <strong>undervalued</strong>), it would provide a good opportunity to buy it and if overbought (and therefore overvalued), perhaps it is time to sell it as the stock price may “correct” itself and undergo a pullback. Source: <a href="https://www.investopedia.com/articles/active-trading/042114/overbought-or-oversold-use-relative-strength-index-find-out.asp">Investopedia</a></li></ul><p>A rather popular momentum indicator, the RSI is calculated as follows: source <a href="https://school.stockcharts.com/doku.php?id=technical_indicators:relative_strength_index_rsi">StockCharts</a></p><pre>                  100<br>    RSI = 100 - --------<br>                 1 + RS<br><br>    RS = Average Gain / Average Loss</pre><p>You can read more about it <a href="https://school.stockcharts.com/doku.php?id=technical_indicators:relative_strength_index_rsi">here</a>, but I’d like to briefly explain how I have interpreted it on a basic level. The illustration below shows the RSI line (at the very top) as it constantly fluctuates from being overbought to oversold and on several occasions often dwelling in the middle. We can observe how when the RSI values (line) trends upward from below 30 (hence oversold and undervalued), there exists a simultaneous upward price momentum on various occasions. For example: note the RSI values &amp; the price movement between October 7, 2019, &amp; October 28, 2019, where the RSI values indicate that the stock is escaping its undervalued position (as determined by the RSI) as buying occurs and the price moves upwards.</p><p>So here, I’ve employed a basic strategy where<strong> I look at the trend of RSI values and if the general trend is positive between RSI values 40/50 &amp; 70 then <em>I flag that period of time to be possible buy time for the stock</em>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*_Lj0_tFcsCbozAcmPYI2Sg.png" /></figure><p>The same word of caution as above: using RSI values solely does NOT promise positive ROI on your investment. There have been numerous instances wherein a positive RSI trend does <strong>NOT</strong> find itself hand in hand with a strong upward trend in price. Technical indicators simply assist you in possibly identifying short term signals, not a guarantee.</p><p><strong>So in short, when there exists a time period when both the RSI &amp; MACDH indicators are trending favorably, this simple algorithm marks that time period (specific dates) as a good time to buy the stock</strong></p><p>All in all, it is important to acknowledge that exist a myriad of technical indicators as well as fundamental analysis techniques (which I don’t even look at) that can help further guide you in your process for identifying good stock investment strategies, short &amp; long term. Furthermore, the market is influenced by millions of parameters including but not limited to economic and geopolitical events so it would be wise to make sound, informed decisions when it comes to using your hard-earned money to invest!</p><h3>Evaluating the Strategy</h3><p>Following our discussion of the buying strategy, which involves looking at trends of two technical indicators, I would like to hypothetically analyze how the algorithm fares across different industries. The idea here is that different industry segments (Example: Communication Equipment vs Medical Devices) move differently and are often affected by a unique set of geopolitical variables as well. An example would be Oil &amp; Gas wherein tensions in the midwest or meteorological conditions could affect the price of oil and consequentially companies in the oil industry.</p><p>I would like to showcase how the simple buying strategy does with the help of the visual below where:</p><ul><li>Y-axis: Shows the different industries the list of stocks I analyzed were distributed in</li><li>X-axis: Highlights the timeline when the stocks were sold. Example: the first cell with a value of $5<em>.9 </em>indicates the median net investment return you would get if you were to buy 1 share of all stocks in my sample, at the recommended time, belonging to the <em>Communication Equipment </em>industry and then sell them <strong>blindly </strong>after 2 days</li><li>Numerical Values: Showcases the median <strong>net investment return, </strong>by industry. The idea here is that if you could automatically buy stocks using this strategy, and automatically (&amp; blindly) sell it N days after how would you do? The primary point of all this is to determine how worthwhile would your investments be if you could set up a trading script (or bot) to do the buying and selling on its own using these principals- buying when the algorithm above recommends, &amp; sell N days from buying. (Which as it turns out you can do today, what a time to be alive…)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-gZayT2xO7w4q3MSTQ3CIA.png" /></figure><p>Finally, let&#39;s interpret this chart by looking at specific examples:</p><ul><li>Lets look at the <em>Biotechnology</em> industry on the Y-axis and the <em>net_investment_returns_2_days </em>on the X-axis<em>, </em>you can see that the median net investment returns equal $2.1 if you were to buy 1 share of all biotech stocks in the sample at a time recommended by the algorithm and sell if <strong>blindly</strong> 2 days after.</li><li>Overall, I would like to say that this chart is <strong>biased</strong> as the number of stock data I consider in the <em>Biotechnology</em> industry, for instance, is much lower than the number of stocks in the <em>Drug Manufacturing </em>industry which is why the median returns seem to be higher.</li></ul><p>NEXT: I will possibly add to this article and edit the charts after conducting analysis on a larger subset of the overall stock data.</p><p>Thank you very much for your time. I hope you like the article!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c03fba6e694d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[User Retention in Python]]></title>
            <link>https://medium.com/analytics-vidhya/user-retention-in-python-8c33fa5766b6?source=rss-2b0a91553328------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c33fa5766b6</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[metrics]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[saas]]></category>
            <category><![CDATA[retention]]></category>
            <dc:creator><![CDATA[Darshil Desai]]></dc:creator>
            <pubDate>Wed, 06 Nov 2019 00:44:06 GMT</pubDate>
            <atom:updated>2020-01-23T21:51:19.133Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will show you how to run a user retention analysis on your dataset by importing a very small easy to run retention module. This article is intended for analysts (and students alike) who wish to quickly conduct a retention analysis with minimal effort- therefore allowing you to spend more time analyzing and less time coding.</p><p><strong>So what is User Retention?</strong></p><p>Essentially user retention allows you to perform a cohort analysis (which just means grouping users in some time period) and see how many users have engaged in *some activity* since they joined.</p><p>Perhaps the above explanation confused you, but no worries this concept is quite simple to understand visually. Let’s say you begin with a dataset like this one below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/1*d8nZGPGQ5XXYnfP5iil3tg.png" /><figcaption>An example of the format your data should be in</figcaption></figure><p>The above image is the raw data format you would ideally be working with wherein:</p><ul><li><strong>user_id</strong>: A unique identifier for every user for whom you would like to include in your retention calculation.</li><li><strong>created_at</strong>: The signup date of the user. How you consider what is “signup” entirely depends on your specific use case. But a simple example can be having a website where users have to create an account (hence signup)</li><li><strong>end_time</strong>: The last date this user was performing an action. Example: last time the user logged in to your service. Again, this metric is completely up to your use case.</li></ul><p><strong>Note: </strong>the <em>end_time</em> for a given user must always be greater than or equal to the <em>created_at</em> value. Which makes sense intuitively when you think about it. For instance: no user activity can be tracked before the user has signed up and therefore been introduced to your environment.</p><p>Let’s use the CalculateRetention package to perform this analysis:</p><p><strong>Step 1: Install the package</strong></p><pre>pip install calculate-retention</pre><p><strong>Step 2: Import required packages</strong></p><pre>from calculate_retention import CalculateRetention</pre><p>Along with other packages</p><pre>import pandas as pd<br>import numpy as np<br>import seaborn as sns<br>import matplotlib.pyplot as plt<br>from datetime import date, timedelta<br>import datetime as dt<br>import warnings</pre><p><strong>Step 3: Import your file in as a Pandas Dataframe</strong></p><p>The key point here is that all you need to feed in is a pandas data frame. Therefore you could implement this retention analysis in the middle of any Python workflow.</p><p>I simply read in a CSV file into a pandas DataFrame which contains the data shown in the image above (I’ll show it again here for completion)</p><pre># Reading in the file <br>my_file = pd.read_csv(&#39;retention_test.csv&#39;)<br>my_file.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*LqilnYAVlb98d1dqOlGRMA.png" /><figcaption>First 5 rows of my_file</figcaption></figure><p><strong>Step 4: Create a Retention Analysis object</strong></p><pre># Use &#39;weekly&#39; for weekly retention and &#39;monthly&#39; for monthly retention<br>retention_data = CalculateRetention(my_file, &#39;monthly&#39;)</pre><p><strong>Step 7: Plot retention</strong></p><p><em>Plot raw data:</em></p><pre>retention_data.plot_retention(&#39;raw&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PjN9si0XwVVfm79_gggM1A.png" /></figure><p>How to read this: Quite simply this plot shows how the actual number of users that signed up in month 0 and how many <strong>of those </strong>users performed an activity (like signing in, doing something, etc) through the coming weeks</p><p><em>Example</em>: Let’s look at the month of May for instance. Essentially we’re saying that 5 users signed up (or entered your system) in May, all 5 users performed some activity in June. However, we lose 2 users in June and so only 3 are left signing in or performing some activity in July, Aug, Sept, Oct. In Oct all 3 signed in for the last time thus leaving the rest of the months blank.</p><p><em>Plot percentages:</em></p><pre>retention_data.plot_retention(&#39;percentage&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CpB58NSrZYX9z0s3rhrLkQ.png" /></figure><p>How to read this: Let&#39;s look at the month of May for instance. Essentially we’re saying that of the 100% users signed up (or entered your system) in May, 100% of those users performed some activity in June. However, only 0.66% of users perform some activity in July, Aug, Sept, Oct. In Oct the 66% of the 100% signed in (or performed some activity) for the last time thus leaving the rest of the months blank.</p><p><strong>What about steps 5 &amp; 6?</strong></p><p>Now you might have noticed that I missed steps 5 &amp; 6. This is because they weren’t needed to perform a quick retention analysis as described above.</p><p><strong>Step 5: Get underlying data</strong></p><p>The goal here is to allow you, the analyst, to incorporate these results into your analysis with ease</p><p><em>Raw data</em></p><pre>z = retention_data.get_raw_retention()<br>z.fillna(&#39;&#39;)  # Just to make it look neater</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P_PRu3kfTtY0AyHiN7_Iig.png" /><figcaption>A pandas DataFrame with the same data plotted above</figcaption></figure><p><em>Percentages</em></p><pre>p = retention_data.compile_percentages()<br>p.fillna(&#39;&#39;)  # Just to make it look neater</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VDFkVQQZ3Bk0Lps1rsmaow.png" /><figcaption>A pandas DataFrame with the same data plotted above</figcaption></figure><p>General note: this analysis was based on mock data. When using production-level data, your results will make a lot more sense. I used a small dataset to not throw anyone off especially people who are just starting in their programming &amp; analytical journey.</p><p>Good luck I hope this helps. Please let me know in the comments if something didn’t work or broke, I will help fix it within a few hours :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c33fa5766b6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/user-retention-in-python-8c33fa5766b6">User Retention in Python</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>