No video

Python for Finance: Are stock returns normally distributed?

  Рет қаралды 14,765

QuantPy

QuantPy

Күн бұрын

Today we investigate whether stock returns are normally distributed! First, I show the difference between simple returns and log returns, highlighting the main reason log returns are preferred for financial analysis.
Then we explore whether CBA (ASX listed stock, Commonwealth Bank of Australia) log returns are normally distributed. We do this by considering several visual and statistical techniques; Quantile-Quantile Plots, Box Plots, Histograms, and numerically by Hypothesis Testing with Kolmogorov Smirnov and Shapiro Wilk tests.
00:00 Intro
00:27 Why use log returns?
02:18 Simple returns
07:28 Log returns
10:44 Are log returns normally distributed?
16:08 Quantile-Quantile Plots
18:00 Box Plots
19:20 Kolmogorov Smirnov test
22:10 Shapiro Wilk tests
As a high-level programming language, Python is a great tool for financial data analysis, with quick implementation and well documented API data sources, statistical modules and other frameworks related to the financial industry. We will be using Jupyter Lab as an interactive web browser editor for this series due to ease of use and presenting code in a live notebook is ideal for this tutorial series.
This is the third video of many on the topic of Python for Finance. The series will include general techniques used for financial analysis and act as an introduction for more in-depth tutorials that we may explore later (such as time series modelling, building financial dashboards, machine learning ect.).
★ ★ Code Available on GitHub ★ ★
GitHub: github.com/The...
Specific Tutorial Link: github.com/The...
★ ★ QuantPy GitHub ★ ★
Collection of resources used on QuantPy KZbin channel. github.com/the...
★ ★ Discord Community ★ ★
Join a small niche community of like-minded quants on discord. / discord
★ ★ Support our Patreon Community ★ ★
Get access to Jupyter Notebooks that can run in the browser without downloading python.
/ quantpy
★ ★ ThetaData API ★ ★
ThetaData's API provides both realtime and historical options data for end-of-day, and intraday trades and quotes. Use coupon 'QPY1' to receive 20% off on your first month.
www.thetadata....
★ ★ Online Quant Tutorials ★ ★
WEBSITE: quantpy.com.au
★ ★ Contact Us ★ ★
EMAIL: pythonforquants@gmail.com
Disclaimer: All ideas, opinions, recommendations and/or forecasts, expressed or implied in this content, are for informational and educational purposes only and should not be construed as financial product advice or an inducement or instruction to invest, trade, and/or speculate in the markets. Any action or refraining from action; investments, trades, and/or speculations made in light of the ideas, opinions, and/or forecasts, expressed or implied in this content, are committed at your own risk an consequence, financial or otherwise. As an affiliate of ThetaData, QuantPy Pty Ltd is compensated for any purchases made through the link provided in this description.

Пікірлер: 32
@weirdcuteai
@weirdcuteai 3 жыл бұрын
Hi, thanks for the video! I just want to add that when you using stats.kstest, by default it compares with standard normal distribution (std=1 and mean =0), however your stock returns has different std & mean, so you might want to add args in your function, then the stock return might fit normal distribution better for example: ks_stat, p_value = kstest(log_returns, 'norm', args = (mean, std))
@vladislavpyatnitskiy
@vladislavpyatnitskiy Жыл бұрын
Thank you for a great content! I would like to add that there is one more test for normality which is Jarque-Bera test that should be familiar to students who have done econometrics. Therefore, I might suppose that you have completed non-economic major. However, I think it is nice to know other normality tests as well!
@sahilharidas4747
@sahilharidas4747 Жыл бұрын
Great video! Just a bit of nit-picking though: at 13:00 when you subtract the mean and divide by standard deviation, you say that will 'normalise' the best and worst case scenarios when they are instead being 'standardised'
@MA-oj8zk
@MA-oj8zk Жыл бұрын
For those running into issues plotting the diagrams, replace df.Close.plot().update_layout(autosize=False,width=500,height=300).show(renderer="colab") with df.Close.plot().update_layout(autosize=False,width=500,height=300).show() Same for log_returns.plot(kind='hist').update_layout(autosize=False,width=500,height=300).show(renderer="colab") and log_returns.plot(kind = 'box').update_layout(autosize=False,width=350,height=500).show(renderer="colab")
@yeuyang5551
@yeuyang5551 5 ай бұрын
Before doing ks /sw test, did I need to standardize the log return?
@konturgestalter
@konturgestalter 3 жыл бұрын
excellent as always!
@joaopedrorocha5693
@joaopedrorocha5693 Жыл бұрын
Wow, great class! Thanks! Was thinking that the mean of the simple return was a good to have a first idea of returns over time but it can overshoot a lot! Will be able to estimate better now! And learned what the heck a ks test is about hehe Thanks a lot! Just a tip ... I think that you could have just sum 1 to simple_returns instead of doing a list comprehension, it's cleaner and more efficient (on cell 57 of the notebook)
@DimitarDobrinov
@DimitarDobrinov 9 ай бұрын
Great explanation! I have a question. If arithmetic average of simple returns does not yield a correct measure of mean and we need to use geometric mean instead, what do we do with standard deviation? How will we compute standard deviation in a manner that deals with the fact that simple returns are not additive?
@sdsagdfd117
@sdsagdfd117 3 жыл бұрын
Perfect
@kaiwang2924
@kaiwang2924 Жыл бұрын
Simple and beautiful.
@AkashChauhan-rw1qh
@AkashChauhan-rw1qh 3 жыл бұрын
Thanks for sharing with us........
@joshuaGmartin2023
@joshuaGmartin2023 7 ай бұрын
Great stuff
@ncheymbamalu4013
@ncheymbamalu4013 2 жыл бұрын
Stock returns and log returns can be modeled more accurately with the t-distribution.
@sahilharidas4747
@sahilharidas4747 Жыл бұрын
More generally, the t-distribution is better suited when the underlying population variance is unknown, as is usually the case in practice. However, the t-distribution becomes the standard normal distribution as the number of degrees of freedom approaches infinity.
@FRANKWHITE1996
@FRANKWHITE1996 3 жыл бұрын
Thanks 🙌
@MA-oj8zk
@MA-oj8zk Жыл бұрын
For those running into issues with the yahoofinance pandareader, here's the fix: import yfinance as yf yf.pdr_override()
@omololaomotalade8105
@omololaomotalade8105 2 жыл бұрын
Hello, I got the same figure when adding log or simple return to the beginning price to get the ending price. My code: For log_return: data.Price[0] * np.exp(data['log_return'].mean() * len('log_return')) This code did not give me the price at the end of the timeseries For simple_return : data.Price[0] * (1 + data['simple_return'].mean()) ** len('simple_return') . Is there something I am doing wrong? Kindly respond.
@jure4835
@jure4835 2 жыл бұрын
Doesn't this basically show that log returns are normally distributed and therefore the stock returns have a lognormal distribution?
@QuantPy
@QuantPy 2 жыл бұрын
Log returns could be normally distributed, depends on your data. Yes modelling stock returns with a lognormal distribution is a strong assumption, but one that is made often
@modeocheng2190
@modeocheng2190 Жыл бұрын
fantastic!
@andrewbenson8842
@andrewbenson8842 2 жыл бұрын
So what's the solution to this? Most all of theoretical finance assumes a normal distribution (Markowitz theory, CAPM, Black-Scholes). What do quants do in the real world when returns are not normally distributed?
@QuantPy
@QuantPy 2 жыл бұрын
Excellent question, obviously there is no one answer that solves all problems. However things for you to research, a way to model different distributions for various assets is through copulas. This could be incorporated through Monte Carlo simulations for either “real” world risk or portfolio optimisation or “risk-neutral” world derivative valuation
@andrewbenson8842
@andrewbenson8842 2 жыл бұрын
@@QuantPy do you have any materials or information you could point me to that talk about how to deal with non normal data in finance? I'm aware of copulas but am definitely not an expert and haven't see how they can help with non normal data. My understanding was that copulas are used for risk management. When you say use monte carlo is it just a matter of making random draws from an empirical distribution rather than the normal distribution and seeing how that affects an option price for example?
@wilsongomes3360
@wilsongomes3360 Жыл бұрын
good job. tks
@gian_piano
@gian_piano Жыл бұрын
awesome content thank you so much!
@carlosarrieta1145
@carlosarrieta1145 3 жыл бұрын
in which IDLE are you runing your code?
@QuantPy
@QuantPy 3 жыл бұрын
This is Jupyter Lab (notebooks) for python. If you’re using straight IDE, I like to use Visual Studio Code 👍
@vladk9152
@vladk9152 3 жыл бұрын
In a lot of engineering projects we ignore >3sigma events. Is it the same for finance projections? Let's say i want to make an ARIMA projection, or a monte carlo simulation. Should i keep these rare events as useful data?
@TheMLPRyan
@TheMLPRyan 2 жыл бұрын
Yes keep the rare events, have a look at what happened to LTCM when they didn’t include large deviations from their models.
@ooddy24
@ooddy24 2 жыл бұрын
I would appreciate if you would move your picture outside of the script...it is hard enough to see the blurred script because its small scale. And your photo makes it worst...
@QuantPy
@QuantPy 2 жыл бұрын
Thanks Manit, all code on my website in the link in the description if you’ve missed anything 👍
@shaaf9817
@shaaf9817 3 жыл бұрын
Do some videos on crypto
Kids' Guide to Fire Safety: Essential Lessons #shorts
00:34
Fabiosa Animated
Рет қаралды 12 МЛН
EVOLUTION OF ICE CREAM 😱 #shorts
00:11
Savage Vlogs
Рет қаралды 14 МЛН
Box jumping challenge, who stepped on the trap? #FunnyFamily #PartyGames
00:31
Family Games Media
Рет қаралды 30 МЛН
Testing For Normality - Clearly Explained
9:56
Steven Bradburn
Рет қаралды 188 М.
This is why Deep Learning is really weird.
2:06:38
Machine Learning Street Talk
Рет қаралды 381 М.
How Financial Firms Actually Make Money
22:40
QuantPy
Рет қаралды 345 М.
Log Returns in Finance: Continuous Compounding and Euler's Number (e) Explained
14:04
Why Independent Quants Don't Exist
10:14
Dimitri Bianco
Рет қаралды 70 М.
Kids' Guide to Fire Safety: Essential Lessons #shorts
00:34
Fabiosa Animated
Рет қаралды 12 МЛН