Python Pandas || Moving Averages and Rolling Window Statistics for Stock Prices




[ad_1]

#pandas #python #rolling

Please SUBSCRIBE:
https://www.youtube.com/subscription_center?add_user=mjmacarty
Try my Hands-on Python for Finance course on Udemy: https://www.udemy.com/hands-on-python-for-finance/

http://alphabench.com/data/pandas-rolling-tutorial.html

fix_yahoo_finance has been renamed yfinance.

This video was made after changes to many APIs including Yahoo and Google prevented the datareader from connecting. This problem was rectified in pandas_datareader 0.80, however. You may still find yfinance to be a useful library – particularly if for some reason you cannot upgrade pandas_datareader.

Quickly download data for any number of stocks and create a correlation matrix using Python pandas and create a scatter matrix. It may take me 10 minutes to explain, but it will only take you 3 to see the power of Python for downloading and exploring data quickly primarily utilizing NumPy and pandas.

****ATTN: as of pandas_datareader 0.6 downloading from Yahoo API no longer works, and downloading from Google is intermittent. If you have a problem downloading data see this video work-around: https://youtu.be/eSpH6fPd5Yw

Video tutorial demonstrating the using of the pandas rolling method to calculate moving averages and other rolling window aggregations such as standard deviation often used in determining a securities historical volatility.

You can download the notebook used here:
https://nbviewer.jupyter.org/urls/alphabench.com/data/pandas_rolling_method.ipynb

Source


[ad_2]

Comment List

  • Matt Macarty
    December 2, 2020

    ModuleNotFoundError: No module named 'pandas_datareader'

  • Matt Macarty
    December 2, 2020

    In addition to the graph, is there a way to display the actual values. predicted and actual? I suppose just do the .head(# of rows)? Thanks

  • Matt Macarty
    December 2, 2020

    Thank you. Nice tutorial.

  • Matt Macarty
    December 2, 2020

    This is helpful. Also, can you do a small tutorial for EMA moving average in Python Pandas?

  • Matt Macarty
    December 2, 2020

    Hello Matt,

    you said in the end of the video when plotting the moving average std the following:" this would include the 21st observation, the volatility should be used the next day, otherwise it will imply that we know something we don't". What do you mean exactly by this please?
    I presume that you are calculating a 21 days moving average std and that's why you did .shift() but I want to understand the logic behind your previous statement.

    Thanks a lot for your patience.

    Regards

  • Matt Macarty
    December 2, 2020

    For some reason, my rolling average estimates get cut off when the index of my main stock data ends (so the current day). Therefore, the data in the dataframe and chart doesn't continue past the current day, meaning all graph points end at the same time spot without the moving averages extending past the current day.

    Do you know why this might be happening?

  • Matt Macarty
    December 2, 2020

    finally quit watching pandas rolling videos to watch pandas.rolling videos i was searching for

  • Matt Macarty
    December 2, 2020

    nice work, I hadn't found this method in book i followed

  • Matt Macarty
    December 2, 2020

    Awesome tutorial – exactly what I was looking for. Thank you!

  • Matt Macarty
    December 2, 2020

    Thank you, this was a nice little tutorial.

  • Matt Macarty
    December 2, 2020

    thanks

  • Matt Macarty
    December 2, 2020

    it is really helpful. Thank you

  • Matt Macarty
    December 2, 2020

    Hi Matt!
    The data in which I am working on is yearly data and I dont know how to do prediction in python. Could u suggest any method.
    Please help 🙁

  • Matt Macarty
    December 2, 2020

    1. You got it the opposite in terms of lagging. The rolling mean by default is lagging. When you use "center=True", that actually takes away the lagging. To reiterate, when you specify centering, that takes away lagging. Not the other way around.
    2. Instead of shifting the rolling mean by 1 to exclude the same row, you should use "closed=Left".

  • Matt Macarty
    December 2, 2020

    Hi Matt, I'm getting
    ModuleNotFoundError: No module named 'pandas_datareader'
    when I try to import pandas-datareader. Any solutions to this?
    Thanks

  • Matt Macarty
    December 2, 2020

    Nice Matt

  • Matt Macarty
    December 2, 2020

    Thanks!

  • Matt Macarty
    December 2, 2020

    Found this very helpful, thank you.

  • Matt Macarty
    December 2, 2020

    very helpful, Thank you Matt

  • Matt Macarty
    December 2, 2020

    Hey Matt, great video 🙂 Do you have an alternative to Yahoo finance now that it's unstable? Or a workaround of some sort

Write a comment