<?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 Pinak Chakraborty on Medium]]></title>
        <description><![CDATA[Stories by Pinak Chakraborty on Medium]]></description>
        <link>https://medium.com/@pinak.cborty?source=rss-2c2343d2a555------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*VV7wCH92IXGNLxp2SgVbUQ.jpeg</url>
            <title>Stories by Pinak Chakraborty on Medium</title>
            <link>https://medium.com/@pinak.cborty?source=rss-2c2343d2a555------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 11:00:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pinak.cborty/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[A drunkard’s walk, insights from simulation and regression, and a model for stock price movement.]]></title>
            <link>https://medium.com/@pinak.cborty/a-drunkards-walk-insights-from-regression-of-data-generated-in-simulation-and-a-model-for-stock-6c161444058f?source=rss-2c2343d2a555------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c161444058f</guid>
            <category><![CDATA[stock-market]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machıne]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Pinak Chakraborty]]></dc:creator>
            <pubDate>Sun, 20 Sep 2020 20:56:25 GMT</pubDate>
            <atom:updated>2020-09-21T06:59:33.241Z</atom:updated>
            <content:encoded><![CDATA[<h3>A drunkard’s walk, insights from simulation and regression of data generated, and a model for stock prices movement</h3><p>Randomness plays a pivotal role in our lives though we may not perceive it most of the times.</p><p>In this series of two articles,</p><p>(1) I will first revisit the well-studied process of a drunkard’s walk, describe the basic mathematical formulation and simulate drunkard’s walk using Python libraries and show that how empirical study of the data generated on random walks by simulation can lead to amazing conclusions.</p><p>(2) I will then model movement of stock prices as a random walk process with a drift and variability. This will be covered in the second part of this article.</p><p>To begin with, a drunkard walk is described as a random walk in 2D plane where at each point in the plane, a drunkard can either move one step to east, west, north, or south. We make two assumptions:</p><p>(i) Each of the four choices to move east, west, north, and south is equally probable (that is, there is no drift in any direction)</p><p>(ii) Probability at a step does not depend on the past choices. That is, we assume that it to be a memoryless Markov process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*EFiTbjf5UT-Yj70Ao-vG-g.jpeg" /></figure><p>The following Python script implements the random path equation (<em>Equation-A</em>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*Md-0_XIGjqZmxIKkhTv7_w.png" /></figure><p>Then we generate random walk with 25 steps for 10 times (each starting from origin) and we plot these random walks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*Ix7z9kT8BzCGcGG2DpsE-w.png" /></figure><p>A beautiful picture of these 10 random walks of 25 steps emerges:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*F942ob_FTox3VKgRSItMhA.png" /></figure><p>We can notice that though 25 steps have been taken in these 10 tries starting from origin every time, distance travelled does not seem to be far from the origin in all the attempts. In fact, most of the points seem to have traversed around the origin.</p><p>If all 25 steps were taken in the same direction, then distance would be 25 steps from the origin, which is highly unlikely. It is because probability of taking 25 steps in the same direction is :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*1_jZ_XsFUOQSfeAK41sjhg.jpeg" /></figure><p>But it is apparent from the above plot that the distance travelled is not more than 7 grids away from origin most of the times even after taking 25 steps.</p><p>To examine this further, we now simulate random walks of our drunkard in 1000 steps and we simulate it for 10000 times and plot these random walks. In order words, we simulate 1000 steps of random walk for 10000 times. This generates the following plot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*AeiAocUCFHrAj-82zVojoA.png" /></figure><p>Even after 1000 steps and 10000 tries, it is clear than the most the points traversed are around origin and the distance travelled form origin is not far off.</p><p>We calculate the mean of Euclidean distance travelled from all of these 10000 tries for 1000 steps from origin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*VyrhNqewJ638JeIYne_pvQ.png" /></figure><p>On an average therefore the distance travelled from origin was only 28.21.</p><p>To examine it further, we now run a simulation of 20000 times for random walk of the same 1000 steps and plot the random paths. We now get the following plot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*CKQQVRzHTRWbuHt_8CNFwA.png" /></figure><p>Almost the same plot as earlier with 10000 simulation emerges as shown above. There is not much difference in the distance travelled on an average either.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*Qidyp3hLWdKf8JrtM5_wUQ.png" /></figure><p>The mean of Euclidean distance for this simulation run also 28.20 (compared to 28.21 earlier).</p><p>We ran the simulation with different numbers a few times (not shown here) and we observed the same average distance (~28.2) and points visited for random walk of 1000 steps.</p><p>Therefore, it seems at this stage that there is a relation between average distance travelled and the number of steps taken the random walk.</p><p>We also observe that the number of points visited are distributed as follows in xy plane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*s-nuvwpHxB0fVb2YCawMbw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*RX5Oi2Mg7-a1V7pdOwzckg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*q9Rd5i8NKtbD2fZ-iVKlww.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/1*UCOOpE9vvAK5Eu6v5rB7yQ.png" /></figure><p><strong>Clearly, the points visited are distributed in a Gaussian distribution of its characteristic bell curve shape and this is the first conclusion of this simulation.</strong></p><p>We now endeavour to examine the relation between average distance travelled in after a certain number of steps.</p><p>We prepare and run simulations as follows:</p><p>From step 1 to a maximum (we set it at 1000), we run simulation of 20,000 times. Then we calculate average distance travelled in each step and plot the average distance travelled against the number of steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*J4mug9KhKUN9ezR2kaYybQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*EQDcHpRYoxFNM64UUeaTXA.png" /></figure><p>This graph clears shows a relation between the average distance travelled with the number of steps taken. The relationship is not linear but seems to be a polynomial one.</p><p>We then do a polynomial regression of degree 2 to examine the relation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*oUdHmAQ5desSV1Gc8JfxJw.jpeg" /></figure><p>In fact, when we plot the average distance from the simulation and the average that calculated from above, we see two lines completely overlap each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*7KvQDpUG-lEw3hVXCPd9eA.png" /></figure><p>Moreover, the mean squared difference between the calculated average distance and average distance from simulation is almost zero, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*XwhFbfzgTBM0aJJFQZSqzQ.png" /></figure><p><strong>Therefore, we come to our second conclusion of this simulation, that is:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*IsBs1tgJV_Febg1KLpK7dg.jpeg" /></figure><p>We then examine the probability of returning back to the starting point (i.e. origin) while doing this random walk in 2D plane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*WcnW6DuOaQzRRXqk4w6qmA.jpeg" /></figure><p>We notice that the probability of returning to the starting point at least once during the random walk increase as the number of steps increases. That is, the more the number of steps taken, the more probable it is to return to the starting point at least once. <strong>This is the third conclusion of this simulation.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*MV_z1jHn7Nkg6w7Ry_zp3w.png" /></figure><p>In summary, our simulation of random walk in 2D plane without any drift and equal probability of four choices at each point that does not depend on past choices (i.e. a Markov process), have led to the following conclusions:</p><p>1. Points visited are distributed in a Gaussian distribution around the starting point,</p><p>2. Average Euclidean distance travelled from starting point is proportional to the square root of steps taken in the random walk, and</p><p>3. Probability of returning back to the starting point (i.e. recurrence) while doing the random walk increases as the number of steps increases.</p><p><strong>Python jupyter notebook that contains the code shown in this article is available in:</strong></p><p><a href="https://github.com/Pinak-Chakraborty/Random_Walk"><strong>https://github.com/Pinak-Chakraborty/Random_Walk</strong></a></p><p>The above conclusions are drawn from simulation and study of the data generated from simulation. For rigorous mathematical proofs for the above conclusions, <a href="https://mathworld.wolfram.com/RandomWalk2-Dimensional.html">Wolfram Mathworld</a> and references mentioned there can be looked at.</p><p><strong>Disclaimer</strong></p><p>Random walk in 2D plane is well studied and I do not claim any new conclusion from the simulation but have proved these conclusions by an empirical study of data generated in simulation, visualization and regression using Python libraries.</p><p>Views and work presented here are personal and do not represent or belong to any of the organization that I have ever been associated with.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c161444058f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>