I'd love to see more of stochastics from you, you have such a good ability of simplifying those hard concepts, please consider making a playlist for stochastics.
@gidi57793 жыл бұрын
Great video! I'd definitely like to see more on Brownian motion and other stochastic processes
@mCoding3 жыл бұрын
Noted!
@webdeveloper-vy7hb3 жыл бұрын
That's a great video @mCoding, keep it up please. We need that kind of visualization to grasp the core.
@mCoding3 жыл бұрын
You are welcome, I'm glad you appreciate it! Brownian Motion is a tricky thing, I'm always thinking of new ways to visualize it. Don't forget to check out my Brownian Motion zoom videos too! All viz no code in those though :)
@Jojo-wj8qv3 жыл бұрын
You just helped me completing my homework exercise, I have been looking for a video like this one for two hours and then I found this one. You're blessed!!
@mCoding3 жыл бұрын
Awesome! Brownian motion can be a lot of fun!
@Jojo-wj8qv3 жыл бұрын
@@mCoding So is there a way to calculate the sample mean?
@mCoding3 жыл бұрын
In numpy it's easy, just use np.mean(arr). For a standard brownian motion you should find the sample mean is close to 0.
@hemanthkotagiri88653 жыл бұрын
A small correction: 0:38 - Matplotlib for plotting.
@mCoding3 жыл бұрын
Yes, it irks me everytime I watch the video :(
@bp567893 жыл бұрын
@@mCoding Damn, NumPy does it all.
@mikeh77043 жыл бұрын
Learning Python with well-explained practical examples. Thank you.
@mCoding3 жыл бұрын
You are welcome!
@bunny.bunbob3 жыл бұрын
3:28 why do you multiply by the variance you desire and not specify it as a parameter of the np.random.normal function? i thought the SD of the normal distribution is specified in brackets and multiplying a normal distribution with a factor just changes its shape on the y-axis?!
@yuvanmar423 жыл бұрын
You have great content lol you deserve the love from the algorithm
@mCoding3 жыл бұрын
I appreciate that! Make sure to tell your friends!
@jankyjake4015 ай бұрын
You were super helpful, thanks man
@Grersh3 жыл бұрын
weren't you at like 800 subs yesterday lol
@mCoding3 жыл бұрын
It seems I have been chosen by the algorithm...
@delinquenice3 жыл бұрын
@@mCoding I’m pretty happy for it in this case. Your tutorials are very clear and presented in a clear way, so I’m staying 🙂
@sneakyturtle61432 жыл бұрын
Straight to the point me: happy
@mCoding2 жыл бұрын
Glad you enjoyed!
@Patrickoliveirajf3 ай бұрын
Very good content!
@ren2007583 жыл бұрын
Great video. I've used it to simulate not only Brownian motion but also others, such as geometric and Ornstein-Uhlenbeck. even being able to compare with the theoretical predictions. one thing I do wonder is that how do we start from such models and apply them to real-world data? probabilistic programming?
@mCoding3 жыл бұрын
Awesome! Be aware that this simulation method is not stable for OU processes with certain parameters. Your question is totally valid but unfortunately the answer is a whole career not just a KZbin comment!
@cdellio3 жыл бұрын
Hi James! I've been watching a lot of your python videos recently. I don't use in python for work, but in my leisure it's what I always try to use. I have a question: how do you get to your level of understanding, best? You knock out hard concepts in really concise code. Is your skill just from investing time and energy in learning these topics, and enhancing your abilities along the way? If you have any secrets, please share them!
@mCoding3 жыл бұрын
Hi Christian! Glad to hear you like my videos! This is just one of those things I don't have a good answer for. I try to learn as much as I can, and I watch lectures every day, which help. Experience helps a lot but I also have to purposefully invest in learning things that I don't understand well enough yet. My goal is to look back each year and feel like I knew nothing compared to what I learned this year.
@KaranGupta291119942 жыл бұрын
@@mCoding, and I think that articulating it, making these videos also helps solidify that learning. Sometimes, just saying out loud things that we understand or rather we think we do helps us smoothen out any gaps in our concept. Learning is a continuous process after all. 😉Btw, I was this video's 1K (th) like.
@agb25573 жыл бұрын
Could you elaborate a bit more on dt being the variance and having to square root it and multiply with the Brownian motion? I got a bit lost there.. 😅 Around 3:20 Thanks
@mCoding3 жыл бұрын
Brownian motion has the property that B(t_1) - B(t_2) has variance t_1-t_2. In our array, we take B(k * i) where k = delta t and i ranges from 0 to T/k. So each increment in our array has variance k (i+1) - k i = k = delta t. The parameter numpy wants though is the standard deviation, which is the sqrt of the variance.
@agb25573 жыл бұрын
@@mCoding got it, thank you. It wasn’t immediately obvious to me that the stdev was required.
@TheSchoolDestructer2 жыл бұрын
In general when variance of a random variable X is say V, then variance of a*X, where a is some constant is equal to a*a*V. Hence, to set the variance of distribution with variance 1 to some V, we multiply the that distribution with sqrt(V).
@OscarMartinez-cf1hq3 жыл бұрын
Thanks great video! But why not concatenate first then cumsum? Would this not be more intuative and would start at 0 anyway, or whatever number you concatenated to?
@ibtissamaymen7321 Жыл бұрын
Plz ! Python has more benefits to programmate with than Matalb and R ?
@EW-mb1ih3 жыл бұрын
Why do you use a cumulative sum for the brownian values?
@mCoding3 жыл бұрын
The array contains values that are supposed to be differences of the brownian motion, i.e. B0-0, B1-B0, B2-B1, B3-B2. Doing the cumulative sum gives B0, B1-B0+B0 == B1, B2-B1+B1 == B2, B3-B2+B2 == B3, and so on. You can see that taking the cumulative sum of differences of a sequence creates a telescoping sum which recovers the original sequence.
@mikechen29513 жыл бұрын
Can you comment on the relationship between the normal distribution you used and the zero mean auto-correlation function in the definition of Langevin and Brownian dynamics?
@mCoding3 жыл бұрын
Brownian motion is an example of a stationary zero-mean Gaussian process, which is characterized completely by its auto-correlation function R(t,s) = min(t,s). For Langevin or Brownian dynamics, you work with a stationary zero-mean Gaussian process whose auto-correlation is given by R(t,s) = 1 if t=s and 0 otherwise. In particular, in those dynamics you are not working with Brownian motion. However, there is a very general theory of Gaussian processes that covers those cases.
@mikechen29513 жыл бұрын
@@mCoding Thanks for the reply! I think it is funny that Brownian dynamics is not Brownian motion. Do you have any recommended readings if I want to learn more about the theory of the Gaussian process?
@mCoding3 жыл бұрын
@@mikechen2951 Gaussian Processes for Machine Learning by Rasmussen and Williams is a popular text, though it requires some math knowledge.
@AbuTuraab723 жыл бұрын
@@mCoding do you think it is possible to integrate that with selenium to move the mouse without being detected as a bot
@renemartinez30143 жыл бұрын
Excelente job, keep going!
@ibtissamaymen7321 Жыл бұрын
your video really helps me to simulate the Brownian motion, but plz I don't understand why you convert 1 and 0 to float by adding points (1. ),(0. )
@PeterZaitcev Жыл бұрын
Why haven't you used Manim for the visualization?
@ibtissamaymen7321 Жыл бұрын
Hi james! Plz in the definition of brownian motion, their increment must be independants, i can't see it in the code 🙏🙏
@mCoding Жыл бұрын
We use a multidimentional standard normal, whose components are independent, to create the increments.
@ibtissamaymen7321 Жыл бұрын
@@mCoding Thanks.
@gabrielamosqueda53913 жыл бұрын
Many thanks!
@mCoding3 жыл бұрын
You are welcome!
@erreddadjarfi371 Жыл бұрын
Good work james , but if they ask me the theory justification of the code what can i say? because we simulate just vector
@mCoding Жыл бұрын
Well firstly anything on a computer is not going to be a true brownian motion, it's always just an approximation, but you can also think of the components of the vector as being samples from the brownian motion. So a true brownian motion has B(t) for all real t >=0, but the vector holds (approximations) of B(0.00), B(0.01), B(0.02), B(0.03), ... , up to B(T).
@rajivshukla78923 жыл бұрын
very interesting, thank you very much for making this video, !!! :)
@mCoding3 жыл бұрын
Glad you liked it!
@philippb96023 жыл бұрын
Instead of concatenating you could do cumsum of N values and then subtract the first value. Should be fast enough and reduce the number of lines.
@johanestanujaya12552 жыл бұрын
Hi i am interested in this formula, can you write the syntax of the formula?
@EW-mb1ih3 жыл бұрын
Why the variance is sqrt(dt)? I mean is it a reason why the variance is linked to the time interval?
@mCoding3 жыл бұрын
The variance of brownian motion over an interval of length dt is dt. This is one of the defining properties of Browniam motion. The square root is to convert from variance to standard deviation.
@SB-pj3oj3 жыл бұрын
Brownie emotion
@federicadedomenico2572 жыл бұрын
Could please explain me also how to implement geometric Brownian motion without going through the log or exp, just with the formula dS= r S dt + sigma S dW? Cheers from Italy!
@mCoding2 жыл бұрын
Hello from the US! For a single sample path you can just update S_i+1 = S_i * (r dt + sigma sqrt(dt) N_i+1) repeatedly in a loop. Here N_i+1 is a standard normal. Because the next time step depends on the value of the previous time step, this formula cannot be vectorized across multiple time steps. However, it can still be vectorized across sample paths, so if you want a million sample paths you can just make S a million length vector. This is "vertical" vectorization, as opposed to "horizontal" vectorization shown in the video.
@mountaindrew_2 жыл бұрын
Why can't we simulate BM by sampling the increments Wt-Ws with N(0,t-s) and instead we must use sqrt(t-s)*N(0,1) ?
@mCoding2 жыл бұрын
Some libraries take the mean and variance, but numpy takes the mean and standard deviation as parameters, so yes I could pass N(0, sqrt(t-s)) instead of sqrt(t-s)*N(0, 1), but this is a stylistic change at best. Mainly I put it out front so I don't have to talk about whether the argument is std deviation or variance, as the multiplication out front has no ambiguity.
@mountaindrew_2 жыл бұрын
@@mCoding Thanks a lot! I was sampling the wrong distribution because of this issue. I was using rnorm from R and I was sure that no library took std dev as input. Thanks again!
@geniusben45033 жыл бұрын
Just to confirm, this is Brownian motion and not Geometric Brownian motion, right?
@mCoding3 жыл бұрын
That is correct! A geometric Brownian motion would be K exp(aB + ct) where B is this Brownian motion.
@charan24463 жыл бұрын
Just learned if else functions and watching this video.......
@BillyZeKidd3 жыл бұрын
What's the purpose of the if __name__ == '__main__' check?
@mCoding3 жыл бұрын
The check passes if and only if the code is being executed/run as opposed to imported. For this code it is not necessary because the code is so small, but the structure of the program prevents the use of global variables, which can quickly get out of hand if you want to extend your code. That's why I put that in pretty much all my code (except for import only code).
@GuRuGeorge033 жыл бұрын
People use brownian motion and add a "bias" (up or downward) to it to create stock models. they can be extremely accurate (mathematically speaking)
@mCoding3 жыл бұрын
I am one of those people :). You are looking for geometric brownian motion. Biased brownian motion is not used for stock modeling because it will lead to negative prices, geometric brownian motion does not have this issue.
@venkateshmurugadas74813 жыл бұрын
wow
@jonathanfan37093 жыл бұрын
I think you need a better microphone man!!
@mCoding3 жыл бұрын
I'm trying to get this sorted out! Sorry for the inconvenience.
@Codeman40432 жыл бұрын
Wait you imported numpy for plotting? then why does it look like you imported pyplot instead?😂😂
@aniruddhasharma57383 жыл бұрын
I hate coding being used for chemical engineering in the form of “simulations”.