Skip to content

Instantly share code, notes, and snippets.

@FestivalBobcats
Created January 5, 2011 21:57
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 FestivalBobcats/767098 to your computer and use it in GitHub Desktop.
Save FestivalBobcats/767098 to your computer and use it in GitHub Desktop.
def self.volatility(prices)
mean = (prices.inject {|s,n| s+n}) / prices.length
sd = Math.sqrt((prices.inject(0) {|s,n| s + (n-mean)*(n-mean)}) / (prices.length-1))
rsd = sd/mean*100
('%.2f'%rsd)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment