@d3fc/d3fc-random-data
Advanced tools
Comparing version 3.0.8 to 3.0.9
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-random'), require('d3-time')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'd3-random', 'd3-time'], factory) : | ||
(factory((global.fc = global.fc || {}),global.d3,global.d3)); | ||
}(this, (function (exports,d3Random,d3Time) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-random'), require('d3-time')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'd3-random', 'd3-time'], factory) : | ||
(global = global || self, factory(global.fc = global.fc || {}, global.d3, global.d3)); | ||
}(this, function (exports, d3Random, d3Time) { 'use strict'; | ||
var geometricBrownianMotion = function () { | ||
var period = 1; | ||
var steps = 20; | ||
var mu = 0.1; | ||
var sigma = 0.1; | ||
var random = d3Random.randomNormal(); | ||
function geometricBrownianMotion () { | ||
var period = 1; | ||
var steps = 20; | ||
var mu = 0.1; | ||
var sigma = 0.1; | ||
var random = d3Random.randomNormal(); | ||
var geometricBrownianMotion = function geometricBrownianMotion() { | ||
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
var geometricBrownianMotion = function geometricBrownianMotion() { | ||
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
var timeStep = period / steps; | ||
var pathData = []; | ||
var timeStep = period / steps; | ||
var pathData = []; | ||
for (var i = 0; i < steps + 1; i++) { | ||
pathData.push(value); | ||
var increment = random() * Math.sqrt(timeStep) * sigma + (mu - sigma * sigma / 2) * timeStep; | ||
value = value * Math.exp(increment); | ||
} | ||
for (var i = 0; i < steps + 1; i++) { | ||
pathData.push(value); | ||
var increment = random() * Math.sqrt(timeStep) * sigma + (mu - sigma * sigma / 2) * timeStep; | ||
value = value * Math.exp(increment); | ||
} | ||
return pathData; | ||
}; | ||
return pathData; | ||
}; | ||
geometricBrownianMotion.period = function () { | ||
if (!arguments.length) { | ||
return period; | ||
} | ||
period = arguments.length <= 0 ? undefined : arguments[0]; | ||
return geometricBrownianMotion; | ||
}; | ||
geometricBrownianMotion.period = function () { | ||
if (!arguments.length) { | ||
return period; | ||
} | ||
period = arguments.length <= 0 ? undefined : arguments[0]; | ||
return geometricBrownianMotion; | ||
}; | ||
geometricBrownianMotion.steps = function () { | ||
if (!arguments.length) { | ||
return steps; | ||
} | ||
steps = arguments.length <= 0 ? undefined : arguments[0]; | ||
return geometricBrownianMotion; | ||
}; | ||
geometricBrownianMotion.steps = function () { | ||
if (!arguments.length) { | ||
return steps; | ||
} | ||
steps = arguments.length <= 0 ? undefined : arguments[0]; | ||
return geometricBrownianMotion; | ||
}; | ||
geometricBrownianMotion.mu = function () { | ||
if (!arguments.length) { | ||
return mu; | ||
} | ||
mu = arguments.length <= 0 ? undefined : arguments[0]; | ||
return geometricBrownianMotion; | ||
}; | ||
geometricBrownianMotion.mu = function () { | ||
if (!arguments.length) { | ||
return mu; | ||
} | ||
mu = arguments.length <= 0 ? undefined : arguments[0]; | ||
return geometricBrownianMotion; | ||
}; | ||
geometricBrownianMotion.sigma = function () { | ||
if (!arguments.length) { | ||
return sigma; | ||
} | ||
sigma = arguments.length <= 0 ? undefined : arguments[0]; | ||
return geometricBrownianMotion; | ||
}; | ||
geometricBrownianMotion.sigma = function () { | ||
if (!arguments.length) { | ||
return sigma; | ||
} | ||
sigma = arguments.length <= 0 ? undefined : arguments[0]; | ||
return geometricBrownianMotion; | ||
}; | ||
geometricBrownianMotion.random = function () { | ||
if (!arguments.length) { | ||
return random; | ||
} | ||
random = arguments.length <= 0 ? undefined : arguments[0]; | ||
geometricBrownianMotion.random = function () { | ||
if (!arguments.length) { | ||
return random; | ||
} | ||
random = arguments.length <= 0 ? undefined : arguments[0]; | ||
return geometricBrownianMotion; | ||
}; | ||
return geometricBrownianMotion; | ||
}; | ||
} | ||
return geometricBrownianMotion; | ||
}; | ||
var createReboundMethod = (function (target, source, name) { | ||
var method = source[name]; | ||
if (typeof method !== 'function') { | ||
throw new Error('Attempt to rebind ' + name + ' which isn\'t a function on the source object'); | ||
} | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
var createReboundMethod = (function (target, source, name) { | ||
var method = source[name]; | ||
if (typeof method !== 'function') { | ||
throw new Error('Attempt to rebind ' + name + ' which isn\'t a function on the source object'); | ||
} | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var value = method.apply(source, args); | ||
return value === source ? target : value; | ||
}; | ||
}); | ||
var value = method.apply(source, args); | ||
return value === source ? target : value; | ||
}; | ||
}); | ||
var createTransform = function createTransform(transforms) { | ||
return function (name) { | ||
return transforms.reduce(function (name, fn) { | ||
return name && fn(name); | ||
}, name); | ||
var createTransform = function createTransform(transforms) { | ||
return function (name) { | ||
return transforms.reduce(function (name, fn) { | ||
return name && fn(name); | ||
}, name); | ||
}; | ||
}; | ||
}; | ||
var rebindAll = (function (target, source) { | ||
for (var _len = arguments.length, transforms = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
transforms[_key - 2] = arguments[_key]; | ||
} | ||
var rebindAll = (function (target, source) { | ||
for (var _len = arguments.length, transforms = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
transforms[_key - 2] = arguments[_key]; | ||
} | ||
var transform = createTransform(transforms); | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
var transform = createTransform(transforms); | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = Object.keys(source)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var name = _step.value; | ||
try { | ||
for (var _iterator = Object.keys(source)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var name = _step.value; | ||
var result = transform(name); | ||
if (result) { | ||
target[result] = createReboundMethod(target, source, name); | ||
var result = transform(name); | ||
if (result) { | ||
target[result] = createReboundMethod(target, source, name); | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} | ||
return target; | ||
}); | ||
return target; | ||
}); | ||
function functor(v) { | ||
return typeof v === 'function' ? v : function () { | ||
return v; | ||
}; | ||
} | ||
function functor(v) { | ||
return typeof v === 'function' ? v : function () { | ||
return v; | ||
}; | ||
} | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var financial = function () { | ||
var startDate = new Date(); | ||
var startPrice = 100; | ||
var interval = d3Time.timeDay; | ||
var intervalStep = 1; | ||
var unitInterval = d3Time.timeYear; | ||
var unitIntervalStep = 1; | ||
var filter = null; | ||
var volume = function volume() { | ||
var normal = d3Random.randomNormal(1, 0.1); | ||
return Math.ceil(normal() * 1000); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var gbm = geometricBrownianMotion(); | ||
var getOffsetPeriod = function getOffsetPeriod(date) { | ||
var unitMilliseconds = unitInterval.offset(date, unitIntervalStep) - date; | ||
return (interval.offset(date, intervalStep) - date) / unitMilliseconds; | ||
}; | ||
function financial () { | ||
var startDate = new Date(); | ||
var startPrice = 100; | ||
var interval = d3Time.timeDay; | ||
var intervalStep = 1; | ||
var unitInterval = d3Time.timeYear; | ||
var unitIntervalStep = 1; | ||
var filter = null; | ||
var volume = function volume() { | ||
var normal = d3Random.randomNormal(1, 0.1); | ||
return Math.ceil(normal() * 1000); | ||
}; | ||
var gbm = geometricBrownianMotion(); | ||
var calculateOHLC = function calculateOHLC(start, price) { | ||
var period = getOffsetPeriod(start); | ||
var prices = gbm.period(period)(price); | ||
var ohlc = { | ||
date: start, | ||
open: prices[0], | ||
high: Math.max.apply(Math, prices), | ||
low: Math.min.apply(Math, prices), | ||
close: prices[gbm.steps()] | ||
var getOffsetPeriod = function getOffsetPeriod(date) { | ||
var unitMilliseconds = unitInterval.offset(date, unitIntervalStep) - date; | ||
return (interval.offset(date, intervalStep) - date) / unitMilliseconds; | ||
}; | ||
ohlc.volume = volume(ohlc); | ||
return ohlc; | ||
}; | ||
var getNextDatum = function getNextDatum(ohlc) { | ||
var date = void 0, | ||
price = void 0, | ||
filtered = void 0; | ||
do { | ||
date = ohlc ? interval.offset(ohlc.date, intervalStep) : new Date(startDate.getTime()); | ||
price = ohlc ? ohlc.close : startPrice; | ||
ohlc = calculateOHLC(date, price); | ||
filtered = filter && !filter(ohlc); | ||
} while (filtered); | ||
return ohlc; | ||
}; | ||
var calculateOHLC = function calculateOHLC(start, price) { | ||
var period = getOffsetPeriod(start); | ||
var prices = gbm.period(period)(price); | ||
var ohlc = { | ||
date: start, | ||
open: prices[0], | ||
high: Math.max.apply(Math, prices), | ||
low: Math.min.apply(Math, prices), | ||
close: prices[gbm.steps()] | ||
}; | ||
ohlc.volume = volume(ohlc); | ||
return ohlc; | ||
}; | ||
var makeStream = function makeStream() { | ||
var latest = void 0; | ||
var stream = {}; | ||
stream.next = function () { | ||
var ohlc = getNextDatum(latest); | ||
latest = ohlc; | ||
var getNextDatum = function getNextDatum(ohlc) { | ||
var date = void 0, | ||
price = void 0, | ||
filtered = void 0; | ||
do { | ||
date = ohlc ? interval.offset(ohlc.date, intervalStep) : new Date(startDate.getTime()); | ||
price = ohlc ? ohlc.close : startPrice; | ||
ohlc = calculateOHLC(date, price); | ||
filtered = filter && !filter(ohlc); | ||
} while (filtered); | ||
return ohlc; | ||
}; | ||
stream.take = function (numPoints) { | ||
return stream.until(function (d, i) { | ||
return !numPoints || numPoints < 0 || i === numPoints; | ||
}); | ||
}; | ||
stream.until = function (comparison) { | ||
var data = []; | ||
var index = 0; | ||
var ohlc = getNextDatum(latest); | ||
var compared = comparison && !comparison(ohlc, index); | ||
while (compared) { | ||
data.push(ohlc); | ||
var makeStream = function makeStream() { | ||
var latest = void 0; | ||
var stream = {}; | ||
stream.next = function () { | ||
var ohlc = getNextDatum(latest); | ||
latest = ohlc; | ||
ohlc = getNextDatum(latest); | ||
index += 1; | ||
compared = comparison && !comparison(ohlc, index); | ||
} | ||
return data; | ||
return ohlc; | ||
}; | ||
stream.take = function (numPoints) { | ||
return stream.until(function (d, i) { | ||
return !numPoints || numPoints < 0 || i === numPoints; | ||
}); | ||
}; | ||
stream.until = function (comparison) { | ||
var data = []; | ||
var index = 0; | ||
var ohlc = getNextDatum(latest); | ||
var compared = comparison && !comparison(ohlc, index); | ||
while (compared) { | ||
data.push(ohlc); | ||
latest = ohlc; | ||
ohlc = getNextDatum(latest); | ||
index += 1; | ||
compared = comparison && !comparison(ohlc, index); | ||
} | ||
return data; | ||
}; | ||
return stream; | ||
}; | ||
return stream; | ||
}; | ||
var financial = function financial(numPoints) { | ||
return makeStream().take(numPoints); | ||
}; | ||
financial.stream = makeStream; | ||
var financial = function financial(numPoints) { | ||
return makeStream().take(numPoints); | ||
}; | ||
financial.stream = makeStream; | ||
if (typeof Symbol !== 'function' || _typeof(Symbol.iterator) !== 'symbol') { | ||
throw new Error('d3fc-random-data depends on Symbol. Make sure that you load a polyfill in older browsers. See README.'); | ||
} | ||
if (typeof Symbol !== 'function' || _typeof(Symbol.iterator) !== 'symbol') { | ||
throw new Error('d3fc-random-data depends on Symbol. Make sure that you load a polyfill in older browsers. See README.'); | ||
} | ||
financial[Symbol.iterator] = function () { | ||
var stream = makeStream(); | ||
return { | ||
next: function next() { | ||
return { | ||
value: stream.next(), | ||
done: false | ||
}; | ||
financial[Symbol.iterator] = function () { | ||
var stream = makeStream(); | ||
return { | ||
next: function next() { | ||
return { | ||
value: stream.next(), | ||
done: false | ||
}; | ||
} | ||
}; | ||
}; | ||
financial.startDate = function () { | ||
if (!arguments.length) { | ||
return startDate; | ||
} | ||
startDate = arguments.length <= 0 ? undefined : arguments[0]; | ||
return financial; | ||
}; | ||
}; | ||
financial.startPrice = function () { | ||
if (!arguments.length) { | ||
return startPrice; | ||
} | ||
startPrice = arguments.length <= 0 ? undefined : arguments[0]; | ||
return financial; | ||
}; | ||
financial.interval = function () { | ||
if (!arguments.length) { | ||
return interval; | ||
} | ||
interval = arguments.length <= 0 ? undefined : arguments[0]; | ||
return financial; | ||
}; | ||
financial.intervalStep = function () { | ||
if (!arguments.length) { | ||
return intervalStep; | ||
} | ||
intervalStep = arguments.length <= 0 ? undefined : arguments[0]; | ||
return financial; | ||
}; | ||
financial.unitInterval = function () { | ||
if (!arguments.length) { | ||
return unitInterval; | ||
} | ||
unitInterval = arguments.length <= 0 ? undefined : arguments[0]; | ||
return financial; | ||
}; | ||
financial.unitIntervalStep = function () { | ||
if (!arguments.length) { | ||
return unitIntervalStep; | ||
} | ||
unitIntervalStep = arguments.length <= 0 ? undefined : arguments[0]; | ||
return financial; | ||
}; | ||
financial.filter = function () { | ||
if (!arguments.length) { | ||
return filter; | ||
} | ||
filter = arguments.length <= 0 ? undefined : arguments[0]; | ||
return financial; | ||
}; | ||
financial.volume = function () { | ||
if (!arguments.length) { | ||
return volume; | ||
} | ||
volume = functor(arguments.length <= 0 ? undefined : arguments[0]); | ||
return financial; | ||
}; | ||
financial.startDate = function () { | ||
if (!arguments.length) { | ||
return startDate; | ||
} | ||
startDate = arguments.length <= 0 ? undefined : arguments[0]; | ||
rebindAll(financial, gbm); | ||
return financial; | ||
}; | ||
financial.startPrice = function () { | ||
if (!arguments.length) { | ||
return startPrice; | ||
} | ||
startPrice = arguments.length <= 0 ? undefined : arguments[0]; | ||
return financial; | ||
}; | ||
financial.interval = function () { | ||
if (!arguments.length) { | ||
return interval; | ||
} | ||
interval = arguments.length <= 0 ? undefined : arguments[0]; | ||
return financial; | ||
}; | ||
financial.intervalStep = function () { | ||
if (!arguments.length) { | ||
return intervalStep; | ||
} | ||
intervalStep = arguments.length <= 0 ? undefined : arguments[0]; | ||
return financial; | ||
}; | ||
financial.unitInterval = function () { | ||
if (!arguments.length) { | ||
return unitInterval; | ||
} | ||
unitInterval = arguments.length <= 0 ? undefined : arguments[0]; | ||
return financial; | ||
}; | ||
financial.unitIntervalStep = function () { | ||
if (!arguments.length) { | ||
return unitIntervalStep; | ||
} | ||
unitIntervalStep = arguments.length <= 0 ? undefined : arguments[0]; | ||
return financial; | ||
}; | ||
financial.filter = function () { | ||
if (!arguments.length) { | ||
return filter; | ||
} | ||
filter = arguments.length <= 0 ? undefined : arguments[0]; | ||
return financial; | ||
}; | ||
financial.volume = function () { | ||
if (!arguments.length) { | ||
return volume; | ||
} | ||
volume = functor(arguments.length <= 0 ? undefined : arguments[0]); | ||
return financial; | ||
}; | ||
} | ||
rebindAll(financial, gbm); | ||
function skipWeekends (datum) { | ||
var day = datum.date.getDay(); | ||
return !(day === 0 || day === 6); | ||
} | ||
return financial; | ||
}; | ||
exports.randomFinancial = financial; | ||
exports.randomGeometricBrownianMotion = geometricBrownianMotion; | ||
exports.randomSkipWeekends = skipWeekends; | ||
var skipWeekends = function (datum) { | ||
var day = datum.date.getDay(); | ||
return !(day === 0 || day === 6); | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.randomFinancial = financial; | ||
exports.randomGeometricBrownianMotion = geometricBrownianMotion; | ||
exports.randomSkipWeekends = skipWeekends; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
})); |
@@ -6,2 +6,10 @@ # Change Log | ||
<a name="3.0.9"></a> | ||
## [3.0.9](https://github.com/d3fc/d3fc/compare/@d3fc/d3fc-random-data@3.0.8...@d3fc/d3fc-random-data@3.0.9) (2019-08-12) | ||
**Note:** Version bump only for package @d3fc/d3fc-random-data | ||
<a name="3.0.8"></a> | ||
@@ -8,0 +16,0 @@ ## 3.0.8 (2019-05-28) |
{ | ||
"name": "@d3fc/d3fc-random-data", | ||
"version": "3.0.8", | ||
"version": "3.0.9", | ||
"description": "Components for generating random data series based on stochastic processes", | ||
@@ -27,10 +27,8 @@ "license": "MIT", | ||
"scripts": { | ||
"bundle": "d3fc-scripts bundle", | ||
"test": "d3fc-scripts test" | ||
"bundle": "npx rollup -c ../../scripts/rollup.config.js", | ||
"test": "npx jasmine --config=../../scripts/jasmine.json", | ||
"lint": "npx eslint src/**/*.js" | ||
}, | ||
"devDependencies": { | ||
"@d3fc/d3fc-scripts": "^2.0.5" | ||
}, | ||
"dependencies": { | ||
"@d3fc/d3fc-rebind": "^5.0.7", | ||
"@d3fc/d3fc-rebind": "^5.0.8", | ||
"d3-random": "^1.0.0", | ||
@@ -37,0 +35,0 @@ "d3-time": "^1.0.0" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
0
0
40685
15
688
Updated@d3fc/d3fc-rebind@^5.0.8