Why logarithm is used for computing mean and std dev?

Course Name: Statistical Arbitrage Trading, Section No: 4, Unit No: 5, Unit type: Notebook



Why logarithm (np.log) is used for calculating the mean and std dev? What purpose does it have?



Code:

--------

Define z-score calculation function

def zscore_cal(data1, data2, start, end):

    

    s1 = pd.Series(data1['Close'][start:end])

    s2 = pd.Series(data2['Close'][start:end])

    

    # Compute mean of the spread till now

    mvavg_old = np.mean(np.log(s1/s2))  

    

    # Compute stdev of the spread till now

    std_old = np.std(np.log(s1/s2))  



     # Compute spread

    current_spread = np.log(

        data1['Close'][end]/data2['Close'][end])  



    # This is the same as current_spread = np.log(data1['Close'][end]) - np.log(data2['Close'][end])

    

    # Compute z-score

    zscore = (current_spread - mvavg_old) / <br />
        std_old if std_old > 0 else 0  



    return zscore

--------



Thanks in advance!

Hi Bernhard,



The log-prices linearise the prices and give better estimation.



For example, if you consider a price change from $10 to $20, on a linear scale this is simply $10. And a change from $20 to $40 is a change of $20 (which is two times the previous case). But if you reconsider this, from $10 to  $20, there is a 100% increase. This is same as the change from $20 to $40 (100%). These changes are equivalent and would be represented by same vertical distance on a logaritmic scale. Therefore, the log of the prices are desired.



Hope this answers your question.



Thanks!