volatility

0.2.1 • Public • Published

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) => (+ 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

Readme

Keywords

Package Sidebar

Install

npm i volatility

Weekly Downloads

10

Version

0.2.1

License

MIT

Unpacked Size

3.85 kB

Total Files

5

Last publish

Collaborators

  • fibo