Skip to content

Instantly share code, notes, and snippets.

@FestivalBobcats
Created January 5, 2011 21:57
Show Gist options
  • 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