npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stock-data-generator

v0.0.8

Published

Mock share market data generator

Downloads

25

Readme

Note - This is just a program which generates random price data based on the parameters provided. Real-world stock market data is much more complex and involves many more factors than just random fluctuations. Use it at your own discretion

This library exposes Two methods

|Method | | --- | | generateRandomFlatData(config) | | generateCandleStickData(config, interval, flatData (optional)) |

Config

| Key | sample value |value | required| | --- | --- | --- | --- | |startDateTime | "2000-01-01T09:15:00.000Z" |Date string | required| | startPrice | 180|start price of the stock | required| | noOfDays | 8 | Number of days |required| | tradeHoursPerDay| 6 | Number of trading hours | required| | changeBy| 0.05 |Share's minimum price change (per day)| required| |maxDailyChangePercent| {min: 1.5, max: 3.5} | Expects a range, between which, a day's change would be picked by random, with sample value a day's change would be something like 1.6%, 2.4%, 3.1% etc., | optional (when skipped range becomes random) | |volumeRange|{min: 10000, max:10000}|Expects a range, between which, a day's change would be picked by random|optional (when skipped results will not include volume)

More Description

| Key | sample value |value | | --- | --- | --- | | changeBy| 0.05 | This is kind of minimum step change, lets say if price is $10 considering 0.05 sample value $10.05, $10.10 are valid increments and decrements | | maxDailyChangePercent | { min: 1.5, max: 3.5} | Expects a range, between which day's change would be picked by random | | volumeRange | {min: 10000, max:10000} | A random value will be picked in the provided range, and it is a daily volume. i.e., summation of volume by date in the candle stick data will fall with in the range |

Interval param for generateCandleStickData(config, interval)

| Interval | Description| | --- | --- | | 1m | 1 minute | | 5m | 5 minute | | 15m | 15 minute | | 30m | 30 minute | | 1h | 1 hour | | 1d | 1 day |

Example:

const { generateRandomFlatData, generateCandleStickData } = require("stock-data-generator")

// sample config object
const config = {
  startDateTime: "2000-01-01T09:15:00.000Z",
  startPrice: 180, // start price of the stock
  noOfDays: 3, // Number of days
  tradeHoursPerDay: 6,
  changeBy: 0.05, // share's minimum price change
  maxDailyChangePercent: {
    min: 1.5,
    max: 3.5,
  }, // Daily percentage of stock, in this case share price can vary from 1.5% to 3.5%
  volumeRange: {
    min: 30000,
    max: 31000
  }, // VolumeRange is optional, if range is not provided then volume will be skipped from candle stick results
}

const randomFlatData = generateRandomFlatData(config)
// prints seconds wise price change
console.log(randomFlatData)

// Sample output
// [
//   { date: 2000-01-01T09:15:00.000Z, price: 180 },
//   { date: 2000-01-01T09:15:01.000Z, price: 179.95 },
//   { date: 2000-01-01T09:15:02.000Z, price: 179.9 },
//   { date: 2000-01-01T09:15:03.000Z, price: 179.9 },
//   { date: 2000-01-01T09:15:04.000Z, price: 179.9 },
//   { date: 2000-01-01T09:15:05.000Z, price: 179.95 },
//   ...
// ]

// accepted interval = 1m, 5m 15m 30m 1h 1d
const result = generateCandleStickData(config, "5m")
or
const result = generateCandleStickData(config, "5m", randomFlatData)

// prints the candle stick data with given interval
console.log(result)

// sample output
// [
//   {
//     dateTime: '2000-01-01T11:14:59.000Z',
//     open: 180.1,
//     close: 180.15,
//     high: 182.15,
//     low: 179.65,
//     change: 1.37
//   },
//   ...
// ]