Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Preprocess/Normalize Stock Prices as an input to a statistic analysis

Assuming Change in Stock price has a relation ship to the future change in the stock price,
I am trying to develop a statistical model

What is the best way to pre-process/normalize this price data to be used as input for statistical modeling.

I am reading about Price Change following log-normal distribution, which seems to make intuitive sense to.

    price_history = history(bar_count=3000, frequency='1d', field='price')  
    stock_price_series = price_history[symbol('CSCO')]  
    log_stock_price_series = numpy.log(stock_price_series)  
    log_ma10 = talib.MA(log_stock_price_series,10)  
    log_deviation=log_ma10-my_stock_series  
    record(log_normal=log_deviation)  

Do I have the right understanding of log-normal distribution of price change?

Are there other better ways of normalizing price change for input to a statistical model?

2 responses

Hi Saravanan,

If you want price changes you have to compute returns from the price. E.g.

stock_return_series = price_history[symbol('CSCO')] .pct_change()  
Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

This is the point that confuses me. It seems that most code snippets use the % difference to calculate the return:

Equation 1: %_return = (price[today]-price[yesterday])/price[yesterday]

However, since this return calculation actually assumes a normal distribution, most finance sources tend to use the lognormal return:

Equation 2: ln_return = ln(price[today]/price[yesterday]).

The natural log return of Equation 2 also has a nice property in that the daily returns from each day can be added across a longer time period and yields the same answer as is you used the start and ending price of the time period directly (Equation 3):

Equation 3: Sum(ln(price[today]/price[yesterday]),21) = ln(price[today]/price[21 days ago])

Equation 1 does not work that way and will give you very wrong answers when comparing different time periods.

This video provides more detail: https://www.youtube.com/watch?v=PtoUlt3V0CI