0
$\begingroup$

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

   >>>
$\endgroup$
2
  • $\begingroup$ Hmmm, it wasn't exactly helpful advice. If the volatilitys are given as percentages, you would take log(1+vol). If there are given as changes in log price, you can just add and subtract. $\endgroup$
    – user59
    Oct 22, 2016 at 17:31
  • $\begingroup$ Hi @barrycarter thanks fot taking an interest in this. Yep the volatilities are given as a percentage ( sorry for not making that clear). how would you achieve the comparisons using my example please? $\endgroup$
    – Mr hodges
    Oct 22, 2016 at 20:34

1 Answer 1

1
$\begingroup$

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
$\endgroup$
1
  • $\begingroup$ thanks so much for the answer, I will have to hit the books to find out why this works. Great help BUT I cannot vote it up as I don't have the points. When I do I will come back and fix that. Thanks again I would NEVER have got that answer $\endgroup$
    – Mr hodges
    Oct 25, 2016 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.