0.2.1 • Published 6 years ago

volatility v0.2.1

Weekly downloads
7
License
MIT
Repository
github
Last release
6 years ago

volatility

is the degree of variation of a trading price series over time

Annotated source | License

NPM version No deps JavaScript Style Guide KLP

Annotated source

/**
 * Volatility is the degree of variation of a trading price series over time.
 *
 * @param {Array} values
 * @returns {Number} sigma, a.k.a. *standard deviation* that is the square root of the values *variance*
 */
function volatility (values) {
  const n = values.length

  const mean = values.reduce((a, b) => (a + b), 0) / n

  const deviation = values.reduce((dev, val) => (dev + (val - mean) * (val - mean)), 0)

  return Math.sqrt(deviation / n)
}

module.exports = volatility

License

MIT

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago