0.0.8 • Published 3 months ago

stock-data-generator v0.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

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

Keysample valuevaluerequired
startDateTime"2000-01-01T09:15:00.000Z"Date stringrequired
startPrice180start price of the stockrequired
noOfDays8Number of daysrequired
tradeHoursPerDay6Number of trading hoursrequired
changeBy0.05Share'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 randomoptional (when skipped results will not include volume)

More Description

Keysample valuevalue
changeBy0.05This 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)

IntervalDescription
1m1 minute
5m5 minute
15m15 minute
30m30 minute
1h1 hour
1d1 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
//   },
//   ...
// ]
0.0.8

3 months ago

0.0.7

3 months ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago