Created
September 30, 2014 11:17
-
-
Save joyeecheung/92a0c95f96e6d5671017 to your computer and use it in GitHub Desktop.
Python script for jade's quant case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
data = list() | |
f = open("data") | |
for line in f: | |
data.append(float(line)) | |
T = len(data) - 1 | |
u = list() | |
for i in range(1, T + 1): | |
u.append(math.log(data[i] / data[i - 1])) | |
mean = sum(u) / len(u) | |
square = sum(math.pow(ret - mean, 2) for ret in u) | |
s = math.sqrt(1.0 / (T - 1) * square) | |
volatility = s * math.sqrt(252) | |
print volatility |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment