Skip to content
All library documents

Comparing Historical Volatility with Log Changes

Article Quant Q&A · Author: Mr hodges

Summary

The document asks how to compare historical volatility estimates over nested windows using logarithms. It calculates each adjacent log change by subtracting the logarithm of the earlier estimate from that of the later estimate. Because the volatility estimates decline across the stated windows, these log changes are negative. Taking the logarithm of either negative change is undefined in the real numbers, which explains the reported domain error.

The accepted response applies an absolute-value transformation before taking another logarithm, effectively comparing the magnitudes of the adjacent log changes. That is a workaround for the domain error, but it changes the quantity being measured and does not itself define an overall volatility change. The direct log change from the longest to shortest window is the difference between their log volatility estimates; the document does not clearly develop this distinction. Its numerical illustration is limited to the stated volatility estimates and does not establish a general volatility-trend method.

Key ideas

  • A difference between logarithms of positive volatility estimates can be negative without being invalid.
  • The logarithm of a negative log change is undefined over the real numbers, causing the reported error.
  • Taking an absolute value before applying another logarithm compares magnitudes and changes the interpretation.
  • The overall log change across the full span can be computed directly from the endpoint volatility estimates.

Tags

Full text
# want to get the trend in 20 10 5 day historical volatility using Logs but getting negative number


# want to get the trend in 20 10 5 day historical volatility using Logs but getting negative number












Ok so I am not a math whizz so need some SERIOUS help here. I have historical volatilities:

20 day historical volatility = 49.07% 10 day historical volatility = 47.43% 5 day historical volatility = 41.77%

My goal is to show the relative change between the following:

the change between the 20 day HV and the 10 day hv = diff2010

the change between the 10 day HV and the 5 day hv = diff105

the overall change of 20 10 5 day = diffabs

I got helpful advice that I should use the log function to get the difference in a mathematically accurate manner using the equation below

log_diff2010 = math.log(10 day hv ) - math.log(20 day hv )

log_diff105 = math.log(5 day hv) - math.log(10 day hv )

log_diffabs = math.log(log_diff105) - math.log(log_diff2010)

BUT the log_diffabs results in a -ve log num which causes an error. SO I have two questions:

1 are my calculations for log_diff2010 and log_diff105 correct?

2 how can I find the overall change for the period 20 10 5 day

here is the python 3.5 run where it all goes wrong for me :-(

> import math math.log(47.43)

```
 3.85925493988949
```

> log_diff2010 = math.log(47.43) - math.log(49.07) log_diff105 = math.log(41.77) - math.log(47.43) log_diffabs = math.log(log_diff105) - math.log(log_diff2010)

```
Traceback (most recent call last):
 File "<pyshell#6>", line 1, in <module>
   log_diffabs = math.log(log_diff105) - math.log(log_diff2010)

    ValueError: math domain error

  >>> log_diff105

 -0.12707656138040635

  >>> log_diff2010

-0.03399291021232198
  >>> r2010 = round(log_diff2010,4)

  >>> r105 = round(log_diff105,4)

  >>> r2010

  -0.034

  >>> r105

    -0.1271

   >>> rrabs = math.log(r105) - math.log(r2010)

   Traceback (most recent call last):

      File "<pyshell#14>", line 1, in <module>

      rrabs = math.log(r105) - math.log(r2010)

   ValueError: math domain error

   >>>
```

## Answer by OTP (score 1, accepted)

https://quant.stackexchange.com/a/30720

Using exponents / root will solve nagative values

```
import math

log_diff2010 = math.log(47.43) - math.log(49.07)
log_diff105 = (math.log(41.77) - math.log(47.43))
print log_diff105,(log_diff105**2)**.5,(log_diff2010**2)**.5,(log_diff2010**2)**.5
log_diffabs = math.log( (log_diff105**2)**.5) - math.log( (log_diff2010**2)**.5)
print log_diffabs
```

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.