JSPM

@hugov/correl-range2

0.2.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 37
  • Score
    100M100P100Q69182F
  • License MIT

monte carlo simulation for correlated variables expressed as ranges

Package Exports

  • @hugov/correl-range2
  • @hugov/correl-range2/sim.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@hugov/correl-range2) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

correl-range2

correlated variable monte carlo simulations

ExampleAPINotesLicense

Example

import SIM from '../sim.js'

const res = SIM(
(_,
// initiation ran once
fixed$ = _`600_000 900_000 [0 demand:0.6 price:0.3`,
month$ = _`5,000 7,000 demand:0.5 season:0.5`,
months = _`6 9 [1 season:0.5 price:-0.5`
)=>(
// calculations on every iterations
total$ = fixed$ + month$ * months
)=>({
// exported results
months,
month$,
total$
})
).run(10_000)

//console.log(res.buffer)
const stats=res.stats
console.log('total$ range', stats.total$.Q(0.1).toFixed(0), stats.total$.Q(0.9).toFixed(0))
console.log('correlation', stats.total$.cor('months'))

API

sim( factory, {confidence=0.8, resolution=128} ).run( N=25_000 ) ⇒ simulation

  • factory: randomVariableFactory => model
  • randomVariableFactory: taggedTemplatelow high [min med max] {riskName:40%}, ...correlation) => randomVariable to match the simulation confidence interval. The string is parsed to match the metanorm arguments
  • randomVariable: with .valueOf() that changes on each iteration
  • simulation
    • stats: empirical distribution cdf, pdf, quantiles, average (based on modules sample-distribution and lazy-stats)

Notes

  1. use case is human approximation in decision making - "guesstimates"
  2. default is to use a confidence interval of 80%
  3. variables can be correlated with independent risk factors by providing the linear factor
  4. to maintain correlation, each variable returns a single value per cycle - random variables are constant within a given cycle

License

MIT © Hugo Villeneuve