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))
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!
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'
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")
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)
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?
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.
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.
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
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?
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
@@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?
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?
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...
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))
Before doing ks /sw test, did I need to standardize the log return?
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!
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'
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")
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)
excellent as always!
Thanks for sharing with us........
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?
Simple and beautiful.
Perfect
Stock returns and log returns can be modeled more accurately with the t-distribution.
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.
Great stuff
Thanks 🙌
awesome content thank you so much!
fantastic!
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.
good job. tks
Doesn't this basically show that log returns are normally distributed and therefore the stock returns have a lognormal distribution?
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
in which IDLE are you runing your code?
This is Jupyter Lab (notebooks) for python. If you’re using straight IDE, I like to use Visual Studio Code 👍
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?
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
@@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?
For those running into issues with the yahoofinance pandareader, here's the fix:
import yfinance as yf
yf.pdr_override()
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?
Yes keep the rare events, have a look at what happened to LTCM when they didn’t include large deviations from their models.
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...
Thanks Manit, all code on my website in the link in the description if you’ve missed anything 👍
Do some videos on crypto