Skip to content

Instantly share code, notes, and snippets.

@joyeecheung
Created September 30, 2014 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joyeecheung/92a0c95f96e6d5671017 to your computer and use it in GitHub Desktop.
Save joyeecheung/92a0c95f96e6d5671017 to your computer and use it in GitHub Desktop.
Python script for jade's quant case
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