Skip to content

Main content

Poisson Jump Process Simulator Source Code

Browse the implementation files for Poisson Jump Process Simulator.
tool.ts typescript
import { parseFiniteNumber } from '../../parse/number/tool';
import { createSeededRandom } from '../../random/seeded-number/tool';

export const simulatePoissonJumpProcess = (
	rateInput: unknown,
	durationInput: unknown,
	seedInput: unknown
): string => {
	const rate = parseFiniteNumber(rateInput);
	const duration = parseFiniteNumber(durationInput);
	if (
		rate === null ||
		rate <= 0 ||
		duration === null ||
		duration < 0 ||
		rate * duration > 1_000_000 ||
		typeof seedInput !== 'string' ||
		!seedInput.trim()
	)
		return '';
	const random = createSeededRandom(seedInput);
	const jumpTimes: number[] = [];
	let time = 0;
	while (true) {
		time +=
			-Math.log(Math.max(Number.EPSILON, 1 - random())) / rate;
		if (time > duration) break;
		jumpTimes.push(Number(time.toPrecision(10)));
	}
	return JSON.stringify(
		{
			duration,
			jumpCount: jumpTimes.length,
			jumpTimes,
			rate,
			seed: seedInput
		},
		null,
		2
	);
};

export const Tool: TypeTool = {
	name: 'Poisson Jump Process Simulator',
	slug: 'stochastic-process/poisson-jump-process',
	intro:
		'Simulate reproducible exponential interarrival times for a homogeneous Poisson process.',
	tool: simulatePoissonJumpProcess,
	i: [
		{
			example: '2',
			label: 'Event Rate',
			placeholder: 'Positive events per time unit',
			type: 'number'
		},
		{
			example: '10',
			label: 'Duration',
			placeholder: 'Nonnegative time horizon',
			type: 'number'
		},
		{
			example: 'tool.io',
			label: 'Seed',
			placeholder: 'Reproducible seed',
			type: 'text'
		}
	],
	o: [
		{
			example: '{ "jumpTimes": [0.2, 0.9] }',
			label: 'Jump Process',
			placeholder: 'Jump times will appear here...',
			render: 'textarea',
			type: 'text'
		}
	],
	rerunnable: true
};
export default Tool;

Description

Browse the implementation files for Poisson Jump Process Simulator.

References

  1. Tool.io on GitHub
  2. Tool.io TypeScript tools library

Similar or alternative tools