# stock-data-generator

> Mock share market data generator

Latest version **0.0.8** (published 2024-02-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install stock-data-generator
pnpm add stock-data-generator
yarn add stock-data-generator
bun add stock-data-generator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2024-02-18 |
| First published | 2023-03-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Bhalaji Nagarajan |
| Maintainers | cyberfury10 |
| Keywords | mock data, share, fake, data generator, candle stick data, stock, stock candles, stockapi, finance, ticker, free data |

## Links

- npm: https://www.npmjs.com/package/stock-data-generator
- Repository: https://github.com/cyberfury10/stock-data-generator
- Issues: https://github.com/cyberfury10/stock-data-generator/issues
- npm.io page: https://npm.io/package/stock-data-generator

## Alternatives

- [pagerjs](https://npm.io/package/pagerjs.md) — 60 weekly downloads
- [whistle.savefor-mock](https://npm.io/package/whistle.savefor-mock.md) — 4 weekly downloads
- [@atlassian/atlaskit-feature-flags-mock](https://npm.io/package/@atlassian/atlaskit-feature-flags-mock.md) — 0 weekly downloads
- [@ohos-ports/snaplet-snapshot](https://npm.io/package/@ohos-ports/snaplet-snapshot.md) — 0 weekly downloads
- [@wiremark/core](https://npm.io/package/@wiremark/core.md) — 0 weekly downloads

## Recent versions

- 0.0.8 (latest) — 2024-02-18
- 0.0.7 — 2024-02-18
- 0.0.6 — 2023-03-15
- 0.0.5 — 2023-03-15
- 0.0.4 — 2023-03-15
- 0.0.3 — 2023-03-12
- 0.0.2 — 2023-03-12
- 0.0.1 — 2023-03-11

## README

<span style="color:red"> **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** </span>

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
//   },
//   ...
// ]
```

---
_Source: https://npm.io/package/stock-data-generator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
