{"id":29565507,"url":"https://github.com/tim55667757/pricegenerator","last_synced_at":"2025-07-18T21:32:00.605Z","repository":{"id":45021366,"uuid":"326965391","full_name":"Tim55667757/PriceGenerator","owner":"Tim55667757","description":"PriceGenerator is the platform for generating prices similar to real stock prices, but you can control the statistics of their distribution. Use PriceGenerator to generate synthetic data to test your trading strategy.","archived":false,"fork":false,"pushed_at":"2023-11-25T14:34:45.000Z","size":1656,"stargazers_count":47,"open_issues_count":2,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-01T07:53:34.441Z","etag":null,"topics":["analysis","analytics","candlestick","candlesticks","csv","forex","generated-prices","generator","history","parser","price-outliers","prices","statistics","stock","technical-analysis","testdata","testing"],"latest_commit_sha":null,"homepage":"https://t.me/tgilmullin_blog","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tim55667757.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-01-05T10:34:42.000Z","updated_at":"2025-04-08T22:48:28.000Z","dependencies_parsed_at":"2023-02-09T04:00:50.295Z","dependency_job_id":"d8772b79-075d-46f5-9c06-cbd605fa1c3a","html_url":"https://github.com/Tim55667757/PriceGenerator","commit_stats":{"total_commits":190,"total_committers":1,"mean_commits":190.0,"dds":0.0,"last_synced_commit":"728398e06ceefcf1021544788b9900e0bc9137a4"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/Tim55667757/PriceGenerator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tim55667757%2FPriceGenerator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tim55667757%2FPriceGenerator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tim55667757%2FPriceGenerator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tim55667757%2FPriceGenerator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tim55667757","download_url":"https://codeload.github.com/Tim55667757/PriceGenerator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tim55667757%2FPriceGenerator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265837538,"owners_count":23836557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analysis","analytics","candlestick","candlesticks","csv","forex","generated-prices","generator","history","parser","price-outliers","prices","statistics","stock","technical-analysis","testdata","testing"],"created_at":"2025-07-18T21:30:34.186Z","updated_at":"2025-07-18T21:32:00.551Z","avatar_url":"https://github.com/Tim55667757.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PriceGenerator\n\n**[PriceGenerator](https://github.com/Tim55667757/PriceGenerator)** is the platform for generating prices similar to real stock prices, but you can control the statistics of their distribution. Generates chain of candlesticks with predefined statistical parameters, return Pandas DataFrame or saving as .CSV-file with OHLCV-candlestick in every string. Use PriceGenerator to generate synthetic data to test your trading strategy.\n\n[![Build Status](https://travis-ci.com/Tim55667757/PriceGenerator.svg?branch=master)](https://travis-ci.com/Tim55667757/PriceGenerator)\n[![pypi](https://img.shields.io/pypi/v/PriceGenerator.svg)](https://pypi.python.org/pypi/PriceGenerator)\n[![license](https://img.shields.io/pypi/l/PriceGenerator.svg)](https://github.com/Tim55667757/PriceGenerator/blob/master/LICENSE)\n[![release-notes](https://badgen.net/badge/release/notes/orange)](https://github.com/Tim55667757/PriceGenerator/blob/develop/CHANGELOG.md)\n[![ru-doc](https://badgen.net/badge/russian/readme/pink)](https://github.com/Tim55667757/PriceGenerator/blob/master/README_RU.md)\n[![api-doc](https://badgen.net/badge/api-doc/PriceGenerator/blue)](https://tim55667757.github.io/PriceGenerator/docs/pricegenerator/PriceGenerator.html)\n[![gift](https://badgen.net/badge/gift/donate/green)](https://yoomoney.ru/fundraise/BxB9DQNvJnk.230111)\n\n* 🇷🇺 [Документация и примеры на русском (see documentation in russian here)](https://github.com/Tim55667757/PriceGenerator/blob/master/README_RU.md)\n* ⚙️ [PriceGenerator API-documentation](https://tim55667757.github.io/PriceGenerator/docs/pricegenerator/PriceGenerator.html)\n* 📚 [Release notes](https://github.com/Tim55667757/PriceGenerator/blob/develop/CHANGELOG.md)\n* 🎁 Support the project with a donation to our yoomoney-wallet: [410015019068268](https://yoomoney.ru/fundraise/BxB9DQNvJnk.230111)\n\n**Contents**\n\n1. [Introduction](#Introduction)\n   - [Price generation method](#Price-generation-method)\n2. [Setup](#Setup)\n3. [Usage examples](#Usage-examples)\n   - [Command line](#Command-line)\n     - [Reference](#Reference)\n     - [Generating prices with default parameters](#Generating-prices-with-default-parameters)\n     - [Generating prices, getting statistics and drawing a chart](#Generating-prices-getting-statistics-and-drawing-a-chart)\n     - [Statistics and chart from saved prices](#Statistics-and-chart-from-saved-prices)\n     - [Statistics and chart on a simple template](#Statistics-and-chart-on-a-simple-template)\n     - [Overriding parameters](#Overriding-parameters)\n     - [Split data by some trends](#Split-data-by-some-trends)\n   - [Module import](#Module-import)\n\n\n## Introduction\n\nSometimes, for testing automated trading algorithms, it is necessary to obtain a dataset with exchange prices. Usually traders and analysts use a price model like OHLCV-candlesticks (open, high, low, close, volume), the so-called Japanese candlesticks. One line of such data is a set of prices for constructing one Japanese candlestick: the opening date, the opening price, the highest price, the lowest price, the closing price at a given time interval and the value of the trading volume.\n\n**PriceGenerator** is a simple library that can be used as a python module or run from the command line and generate random price data that is as close as possible to \"real prices\", but with predefined statistical characteristics. You can set the price interval, timeframe, maximum and minimum values for the price range, maximum size of candles, probability of direction for the next candle, probability of price outliers, the number of generated candles, and some other parameters.\n\nFor further statistical analysis of prices in python, the Pandas library is very often used. Prices stored as a Pandas DataFrame might look something like this:\n```text\n                    datetime   open   high    low  close  volume\n95 2021-02-03 11:00:00+03:00  76.82  78.43  76.21  78.13   33652\n96 2021-02-03 12:00:00+03:00  78.13  78.37  78.12  78.36    9347\n97 2021-02-03 13:00:00+03:00  78.36  78.40  78.05  78.07   27250\n98 2021-02-03 14:00:00+03:00  78.07  78.61  75.72  76.42   22979\n99 2021-02-03 15:00:00+03:00  76.42  77.37  76.25  77.16   30845\n```\n\nThe PriceGenerator library allows you to:\n- save generated prices in .csv-format (example: [./media/test.csv](./media/test.csv));\n- save the generated prices to a Pandas DataFrame variable for further use in automation scripts;\n- automatically calculate some statistical and probabilistic characteristics of the generated prices and save them in Markdown format (example: [./media/index.html.md](./media/index.html.md));\n- load the prices of real instruments according to the OHLCV-candlesticks model from the .csv file and carry out their statistical analysis;\n- draw a chart of generated or loaded real prices and save it in html-format (example: [./media/index.html](./media/index.html));\n  - generated prices, a chart and some data on price behavior can be saved as a regular png-image (example: [./media/index.html.png](./media/index.html.png)):\n\n    ![](./media/index.html.png)\n\n    In additionally, you can enable on the chart some popular indicators (moving averages, Bollinger bands, ZigZag and others).\n\n### Price generation method\n\nA set of candles of a given length `horizon` is generated according to the following (simplified) algorithm:\n1. The open price of the first candlestick is determined or randomly generated in the specified range [`minClose`, `maxClose`].\n2. Randomly, depending on the value of the probability of the next candlestick `upCandlesProb` (50% by default), the direction of the candlestick is determined. If `random () ≤ upCandlesProb`, then an up candle (with `open ≤ close`) will be generated, otherwise a down candle (with `open \u003e close`) will be generated.\n3. After determining the direction, the `close` value of the candlestick is randomly generated and for the candle's \"body\" must be `|open - close| ≤ maxCandleBody`.\n4. Randomly, depending on the probability of price outliers of the `maxOutlier` candlestick (default is 3%), the candlestick's `high` and `low` values ​​are generated. If `random () ≤ maxOutlier`, then a candlestick with price outliers will be generated: the \"tails\" of the candlestick may turn out to be large enough to simulate real price \"outliers\" in the market. If the candlestick is without anomalies, then \"tails\" will be generated in the range of no more than half of the candlestick body.\n5. The close value of the generated candle becomes the open price of the next candle.\n6. Then steps 2-5 are repeated until the entire price chain of the specified length `horizon` is generated.\n\nAll parameters can be set after initializing an instance of the `PriceGenerator()` class. The result of price generation is saved in the `self.prices` field in the Pandas DataFrame format and can be used for further analysis.\n\n\n## Setup\n\nThe easiest way is to install via PyPI:\n```commandline\npip install pricegenerator\n```\n\nAfter that, you can check the installation with the command:\n```commandline\npip show pricegenerator\n```\n\n\n## Usage examples\n\n### Command line\n\n#### Reference\n\nGet help:\n```commandline\npricegenerator --help\n```\n\nOutput:\n```text\nusage: \n/as module/ python PriceGenerator.py [some options] [one command]\n/as CLI tool/ pricegenerator [some options] [one command]\n\nPriceGenerator is the platform for generating prices similar to real stock\nprices, but you can control the statistics of their distribution. Generates\nchain of candlesticks with predefined statistical parameters, return Pandas\nDataFrame or saving as .CSV-file with OHLCV-candlestick in every string. Use\nPriceGenerator to generate synthetic data to test your trading strategy. See\nexamples: https://tim55667757.github.io/PriceGenerator\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --ticker TICKER       Option: some fake ticker name, 'TEST' by default.\n  --precision PRECISION\n                        Option: precision is count of digits after comma, 2 by default.\n  --timeframe TIMEFRAME\n                        Option: time delta between two neighbour candles in\n                        minutes, 60 (1 hour) by default.\n  --start START         Option: start time of 1st candle as string with format\n                        'year-month-day hour:min', e.g. '2021-01-02 12:00'.\n  --horizon HORIZON     Option: candlesticks count. Default: 30.\n  --split-trend SPLIT_TREND\n                        Option: set different trends, e.g. `--split-trend=/\\-`\n                        means that generated candles has uptrend at first\n                        part, next downtrend and then no trend. Used only\n                        together with `--split-count` key. Also, you can use\n                        words: `up`, `down`, `no` or chars: `u`, `d`, `n` with\n                        the hyphen symbol as separator, e.g. `--split-\n                        trend=up-down-no-up`, `--split-trend=u-d-n-u` etc. Default:\n                        empty string, mean that will be used random trend directions.\n  --split-count SPLIT_COUNT [SPLIT_COUNT ...]\n                        Option: set candles count in different trends, e.g.\n                        `--split-count 5 10 15` means that generated candles\n                        has 3 trends with 5, 10 and 15 candles in chain, with\n                        sum must be equal to `--horizon` value. Used only\n                        together with `--split-trend` key. Default: [], empty\n                        list mean that will be used random candles count in trends.\n  --max-close MAX_CLOSE\n                        Option: maximum of all close prices.\n  --min-close MIN_CLOSE\n                        Option: minimum of all close prices.\n  --init-close INIT_CLOSE\n                        Option: generator started 1st open price equal to this\n                        last close price.\n  --max-outlier MAX_OUTLIER\n                        Option: maximum of outlier size of candle tails, by\n                        default used (max_close - min_close) / 10.\n  --max-body MAX_BODY   Option: maximum of candle body sizes:\n                        abs(open - close), by default used max_outlier * 0.9.\n  --max-volume MAX_VOLUME\n                        Option: maximum of trade volumes.\n  --up-candles-prob UP_CANDLES_PROB\n                        Option: float number in [0; 1] is a probability that\n                        next candle is up, 0.5 by default.\n  --outliers-prob OUTLIERS_PROB\n                        Option: float number in [0; 1] is an outliers\n                        probability (price tails), 0.03 by default.\n  --trend-deviation TREND_DEVIATION\n                        Option: relative deviation for trend detection, 0.005\n                        mean ±0.005 by default. No trend if\n                        (1st_close - last_close) / 1st_close \u003c= trend_deviation.\n  --zigzag ZIGZAG       Option: relative deviation to detection points of\n                        Zig-Zag indicator, 0.03 by default.\n  --sep SEP             Option: separator in CSV-file, if None then auto-\n                        detecting enable.\n  --dark                Option: if key present, then will be used dark theme\n                        for the `--render-bokeh` key. `False` by default for\n                        light theme.\n  --debug-level DEBUG_LEVEL\n                        Option: showing STDOUT messages of minimal debug level,\n                        e.g., 10 = DEBUG, 20 = INFO, 30 = WARNING, 40 = ERROR,\n                        50 = CRITICAL.\n  --load-from LOAD_FROM\n                        Command: load .cvs-file to Pandas DataFrame. You can\n                        draw chart in additional with `--render-bokeh` or\n                        `--render-google` key.\n  --generate            Command: generates chain of candlesticks with\n                        predefined statistical parameters and save stock\n                        history as Pandas DataFrame or .CSV-file if `--save-\n                        to` key is defined. You can draw chart in additional\n                        with `--render-bokeh` or `--render-google` keys.\n  --save-to SAVE_TO     Command: save generated or loaded dataframe to .CSV-\n                        file. You can draw chart in additional with `--render-bokeh`\n                        or `--render-google` keys.\n  --render-bokeh RENDER_BOKEH\n                        Command: show chain of candlesticks as interactive\n                        Bokeh chart. Used only together with `--load-from` or `--generate` keys.\n  --render-google RENDER_GOOGLE\n                        Command: show chain of candlesticks as non-interactive\n                        Google Candlestick chart. Used only together with\n                        `--load-from` or `--generate` keys.\n```\n\n#### Generating prices with default parameters\n\nLet's try to generate random price data (key `--generate`) with all default parameters and save them to the file `test.csv` (key `--save-to csv_file_name`). The command might look like this:\n```commandline\npricegenerator --debug-level 10 --generate --save-to test.csv\n```\n\nYou should get the output of logs similar to the following:\n```text\nPriceGenerator.py   L:605  DEBUG   [2021-01-31 17:52:49,954] =--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--=\nPriceGenerator.py   L:606  DEBUG   [2021-01-31 17:52:49,954] PriceGenerator started: 2021-01-31 17:52:49\nPriceGenerator.py   L:367  INFO    [2021-01-31 17:52:49,954] Generating prices...\nPriceGenerator.py   L:368  DEBUG   [2021-01-31 17:52:49,954] - Ticker name: TEST\nPriceGenerator.py   L:369  DEBUG   [2021-01-31 17:52:49,954] - Interval or timeframe (time delta between two neighbour candles): 1:00:00\nPriceGenerator.py   L:370  DEBUG   [2021-01-31 17:52:49,954] - Horizon length (candlesticks count): 100\nPriceGenerator.py   L:371  DEBUG   [2021-01-31 17:52:49,954] - Start time: 2021-01-31--17-00-00\nPriceGenerator.py   L:372  DEBUG   [2021-01-31 17:52:49,955]   |-\u003e end time: 2021-02-04--21-00-00\nPriceGenerator.py   L:373  DEBUG   [2021-01-31 17:52:49,955] - Maximum of close prices: 79.21\nPriceGenerator.py   L:374  DEBUG   [2021-01-31 17:52:49,955] - Minimum of close prices: 67.69\nPriceGenerator.py   L:375  DEBUG   [2021-01-31 17:52:49,955] - Maximum of candle body sizes: 3.08\nPriceGenerator.py   L:376  DEBUG   [2021-01-31 17:52:49,955] - Maximum of candle tails outlier sizes: 3.42\nPriceGenerator.py   L:377  DEBUG   [2021-01-31 17:52:49,955] - Init close (1st open price in chain): 71.49\nPriceGenerator.py   L:378  DEBUG   [2021-01-31 17:52:49,955] - Maximum of volume of one candle: 42340\nPriceGenerator.py   L:379  DEBUG   [2021-01-31 17:52:49,955] - Probability that next candle is up: 50.0%\nPriceGenerator.py   L:380  DEBUG   [2021-01-31 17:52:49,955] - Statistical outliers probability: 3.0%\nPriceGenerator.py   L:397  INFO    [2021-01-31 17:52:49,958] Showing last 5 rows as Pandas DataFrame:\nPriceGenerator.py   L:399  INFO    [2021-01-31 17:52:49,963]                     datetime   open   high    low  close  volume\nPriceGenerator.py   L:399  INFO    [2021-01-31 17:52:49,963] 95 2021-02-03 11:00:00+03:00  76.82  78.43  76.21  78.13   33652\nPriceGenerator.py   L:399  INFO    [2021-01-31 17:52:49,963] 96 2021-02-03 12:00:00+03:00  78.13  78.37  78.12  78.36    9347\nPriceGenerator.py   L:399  INFO    [2021-01-31 17:52:49,963] 97 2021-02-03 13:00:00+03:00  78.36  78.40  78.05  78.07   27250\nPriceGenerator.py   L:399  INFO    [2021-01-31 17:52:49,963] 98 2021-02-03 14:00:00+03:00  78.07  78.61  75.72  76.42   22979\nPriceGenerator.py   L:399  INFO    [2021-01-31 17:52:49,963] 99 2021-02-03 15:00:00+03:00  76.42  77.37  76.25  77.16   30845\nPriceGenerator.py   L:173  INFO    [2021-01-31 17:52:49,963] Saving [100] rows of Pandas DataFrame with columns: ['date', 'time', 'open', 'high', 'low', 'close', 'volume']...\nPriceGenerator.py   L:174  DEBUG   [2021-01-31 17:52:49,963] Delimeter: ,\nPriceGenerator.py   L:181  INFO    [2021-01-31 17:52:49,976] Pandas DataFrame saved to .csv-file [./test.csv]\nPriceGenerator.py   L:645  DEBUG   [2021-01-31 17:52:49,976] All PriceGenerator operations are finished success (summary code is 0).\nPriceGenerator.py   L:650  DEBUG   [2021-01-31 17:52:49,976] PriceGenerator work duration: 0:00:00.022938\nPriceGenerator.py   L:651  DEBUG   [2021-01-31 17:52:49,976] PriceGenerator work finished: 2021-01-31 17:52:49\n```\n\nAlso next to it will be saved the file `test.csv`, an example of which can be found here: [./media/test.csv](./media/test.csv).\n\n#### Generating prices, getting statistics and drawing a chart\n\nIn the next example, let's not only generate a file with price data, but also get some statistical parameters of prices, as well as draw prices on the chart (the key `--render-bokeh html_file_name`). The command might be something like this:\n```commandline\npricegenerator --debug-level 20 --generate --save-to test.csv --render-bokeh index.html\n```\n\nIf successful, you will receive a log output similar to this:\n```text\nPriceGenerator.py   L:367  INFO    [2021-01-31 18:00:31,711] Generating prices...\nPriceGenerator.py   L:397  INFO    [2021-01-31 18:00:31,714] Showing last 5 rows of Pandas generated dataframe object:\nPriceGenerator.py   L:399  INFO    [2021-01-31 18:00:31,719]                     datetime   open   high    low  close  volume\nPriceGenerator.py   L:399  INFO    [2021-01-31 18:00:31,719] 95 2021-02-03 11:00:00+03:00  76.82  78.43  76.21  78.13   33652\nPriceGenerator.py   L:399  INFO    [2021-01-31 18:00:31,719] 96 2021-02-03 12:00:00+03:00  78.13  78.37  78.12  78.36    9347\nPriceGenerator.py   L:399  INFO    [2021-01-31 18:00:31,719] 97 2021-02-03 13:00:00+03:00  78.36  78.40  78.05  78.07   27250\nPriceGenerator.py   L:399  INFO    [2021-01-31 18:00:31,719] 98 2021-02-03 14:00:00+03:00  78.07  78.61  75.72  76.42   22979\nPriceGenerator.py   L:399  INFO    [2021-01-31 18:00:31,719] 99 2021-02-03 15:00:00+03:00  76.42  77.37  76.25  77.16   30845\nPriceGenerator.py   L:173  INFO    [2021-01-31 18:00:31,719] Saving [100] rows of Pandas DataFrame with columns: ['date', 'time', 'open', 'high', 'low', 'close', 'volume']...\nPriceGenerator.py   L:181  INFO    [2021-01-31 18:00:31,731] Pandas DataFrame saved to .csv-file [./test.csv]\nPriceGenerator.py   L:410  INFO    [2021-01-31 18:00:31,731] Rendering Pandas DataFrame as Bokeh chart...\nPriceGenerator.py   L:300  INFO    [2021-01-31 18:00:31,740] Some statistical info:\n## Summary\n\n| Parameter                                    | Value\n|----------------------------------------------|---------------\n| Candles count:                               | 100\n| Timeframe:                                   | 1:00:00\n| Precision (signs after comma):               | 2\n| Close first:                                 | 71.49\n| Close last:                                  | 77.16\n| Close max:                                   | 79.21\n| Close min:                                   | 67.69\n| Diapason (between max and min close prices): | 11.52\n| Trend (between close first and close last:   | UP trend\n| - Trend deviation parameter:                 | ±0.5%\n\n## Some statistics\n\n| Statistic                                    | Value\n|----------------------------------------------|---------------\n| Up candles count:                            | 53 (53.0%)\n| Down candles count:                          | 47 (47.0%)\n| Max of up candles chain:                     | 7\n| Max of down candles chain:                   | 5\n| Max delta (between High and Low prices):     | 3.08\n| Min delta (between High and Low prices):     | 0.0\n| Delta's std. dev.:                           | 0.86\n| - 99 percentile:                             | ≤ 2.99\n| - 95 percentile:                             | ≤ 2.89\n| - 80 percentile:                             | ≤ 2.2\n| - 50 percentile:                             | ≤ 1.15\n| Cumulative sum of volumes:                   | 1777314\nPriceGenerator.py   L:563  INFO    [2021-01-31 18:00:32,290] Pandas DataFrame rendered as html-file [./index.html]\n```\n\nAfter running the command above, you will get three files:\n- `test.csv` — .csv-file containing a random set of prices similar to the real ones (example: [./media/test.csv](./media/test.csv));\n- `index.html` — price chart and statistics drawn using the Bokeh library and saved to an .html-file (example: [./media/index.html](./media/index.html));\n- `index.html.md` — statistics as simple text, saved in Markdown format (example: [./media/index.html.md](./media/index.html.md)).\n\n#### Statistics and chart from saved prices \n\nIf you need to get statistics on already generated or real prices, you can simply load the file (key `--load-from csv_file_name`) and draw the chart (key `--render-bokeh html_file_name`):\n```commandline\npricegenerator --debug-level 20 --load-from test.csv --render-bokeh index.html\n``` \n\nAs a result of executing the command, you will get a similar graph in `index.html` and statistics in `index.html.md`.\n\n#### Statistics and chart on a simple template\n\nIn the examples above, you can use a simple, non-interactive chart. For this, the Google Candlestick chart library and the simplest jinja2 template are used. Let's load the prices again (key `--load-from csv_file_name`), but render the chart through the Google library (key `--render-google html_file_name`):\n```commandline\npricegenerator --debug-level 20 --load-from test.csv --render-google index_google.html\n``` \n\nAs a result of executing the command, you will receive a chart [./media/index_google.html](./media/index_google.html)) and statistics in the Markdown file. It will look something like this:\n\n![](./media/index_google.html.png)\n\n#### Overriding parameters\n\nLet's change some default parameters that affect price generation and draw our own unique chart:\n```commandline\npricegenerator --debug-level 10 --ticker \"MY_PRICES\" --precision 2 --timeframe 240 --start \"2020-01-01 00:00\" --horizon 150 --max-close 18000 --min-close 14000 --init-close 15000 --max-outlier 1000 --max-body 500 --max-volume 400000 --up-candles-prob 0.48 --outliers-prob 0.05 --trend-deviation 0.03 --zigzag 0.03 --generate --render-bokeh index_custom.html\n``` \n\nParameters mean:\n- `--ticker \"MY_PRICES\"` — set chart title for price as MY_PRICES;\n- `--precision 2` — set precision, that means count of digits after comma;\n- `--timeframe 240` — one candlestick should reflect the price change in 4 hours (240 minutes);\n- `--start \"2020-01-01 00:00\"` — date and time of the first candle is 2020-01-01 00:00;\n- `--horizon 150` — generate 150 candles;\n- `--max-close 18000` — the maximum closing price of any candle should be no more than 18000;\n- `--min-close 14000` — the minimum closing price of any candle should be no more than 14000;\n- `--init-close 15000` — the closing price of the \"previous\" and, accordingly, the opening price of the first generated candle should be equal to 15000;\n- `--max-outlier 1000` — if the candle has \"outliers\" and \"tails\" then they size should be no more than 1000;\n- `--max-body 500` — the maximum size of the \"body\" of the candle should be no more than 500;\n- `--max-volume 400000` — the maximum trading volume for each candle should be no more than 400000;\n- `--up-candles-prob 0.48` — set the probability that the next candlestick will be up, equal to 0.48 (48%);\n- `--outliers-prob 0.05` — set the probability of outliers to 0.05 (5%);\n- `--trend-deviation 0.03` — to determine the trend, the relative change in the closing prices of the first and last candles should differ by ± 0.03 (3%);\n- `--zigzag 0.03` — relative difference between two points of ZigZag indicator;\n- `--generate` — begin to price generate;\n- `--render-bokeh index_custom.html` — save the generated prices in the index_custom.html file and open it in the default browser.\n\nChart style is light by default. If you are using `--render-bokeh` key, also you can add to the command above `--dark` key. In this case chart will be shown with dark-mode style:\n\n![](./media/index_custom.html.png)\n\nAs a result of executing the command, you will get your own unique chart of random prices with redefined basic generator parameters. We got next artifacts:\n- prices chart [./media/index_custom.html.png](./media/index_custom.html.png);\n- price chart and statistics [./media/index_custom.html](./media/index_custom.html);\n- statistics in Markdown file [./media/index_custom.html.md](./media/index_custom.html.md).\n\n#### Split data by some trends\n\nThis feature is in the newest dev-version than `pricegenerator\u003e=1.2.dev53` or than `pricegenerator\u003e=1.2.56`.  \n\nIt was implemented two additional keys: `--split-trend` and `--split-count`. These keys affect the appearance of the trend and the number of candles in each trend.\n\nThe `--split-trend` key shows trends movements, e.g. `--split-trend=/\\-` means that generated candles has up trend at first part, next down trend and then no trend.\n\nSince PriceGenerator v1.3.* ability to specify directions with words or chars was added. Words may be next: `up`, `down`, `no` or chars: `u`, `d`, `n` for the `--split-trend` key, in addition to the existing ability to set up of the trend with symbols `/\\-`. To separate words or chars use the hyphen symbol, e.g. `--split-trend=up-down-no-up`, `--split-trend=u-d-n-u` etc.\n\nThe `--split-count` key set count of candles of difference periods, e.g. `--split-count 5 10 15` means that generated candles has 3 trends with 5, 10 and 15 candles in chain.\n\nTo understand how it works, try one of these examples:\n\n```commandline\npricegenerator --horizon 300 --render-bokeh index.html --split-trend=\"/\\-\" --split-count 50 100 150 --generate\npricegenerator --horizon 300 --render-bokeh index.html --split-trend=\"\\/\\\" --split-count 50 100 150 --generate\npricegenerator --horizon 300 --render-bokeh index.html --split-trend=\"\\-/\" --split-count 50 100 150 --generate\npricegenerator --horizon 100 --render-bokeh index.html --split-trend=\"/\\/\\\" --split-count 20 30 30 20 --generate\n```\n\nFor the last example, you can get a picture like this:\n\n![index_with_trends html](./media/index_with_trends.html.png)\n\n\n### Module import\n\nLet's look at an example of generating prices with some predefined parameters, save them to Pandas DataFrame and draw a chart. Just save and run the following script:\n```python\nfrom pricegenerator.PriceGenerator import PriceGenerator, uLogger\nfrom datetime import datetime, timedelta\n\n# Disable logging:\nuLogger.setLevel(0)\n\n# --- Initialize an instance of the generator class and set some parameters:\npriceModel = PriceGenerator()\npriceModel.precision = 1  # how many decimal places should be in generated prices\npriceModel.ticker = \"MY_GENERATED_PRICES\"  # random name (ticker) of generated prices\npriceModel.timeframe = timedelta(days=1)  # time interval between generated candles, 1 hour by default\npriceModel.timeStart = datetime.today()  # from what date to start generating candles, by default from the current time\npriceModel.horizon = 60  # how many candles to generate, there must be at least 5, by default 100\npriceModel.maxClose = 16000  # the highest candlestick closing price in the entire price chain\n                             # by default, it is generated randomly in the interval (70, 90), it is similar to the current prices of USDRUB\npriceModel.minClose = 13800  # the lowest candlestick closing price in the entire price chain\n                             # by default, it is generated randomly in the interval (60, 70), it is similar to the current prices of USDRUB\npriceModel.initClose = 14400  # if a price is specified, it will be the closing price like the \"previous\" candlestick, and at the same time the opening price of the first candlestick in the generated chain\n                              # None by default means that the opening price of the first candle will be generated randomly in the interval (minClose, maxClose)\npriceModel.maxOutlier = 500  # The maximum value for the price outlier of the \"tails\" of the candles.\n                             # None by default means that outliers will be no more than (maxClose - minClose) / 10\npriceModel.maxCandleBody = 300  # maximum value for the size of candlestick bodies abs(open - close)\n                                # None by default means that the candlestick body can be no more than 90% of the outlier size: maxOutlier * 90%\npriceModel.maxVolume = 400000  # the maximum trading volume for one candle, by default it is taken randomly from the interval (0, 100000)\npriceModel.upCandlesProb = 0.46  # probability that the next generated candlestick will be up, 50% by default\npriceModel.outliersProb = 0.11  # the probability that the next generated candlestick will have a price \"outlier\", 3% by default\npriceModel.trendDeviation = 0.005  # price fluctuations between close prices of the first and last candlesticks defining the trend. “NO trend” if the difference is less than this value, by default ± 0.005 or ± 0.5%\npriceModel.zigzag = 0.05  # relative difference between two points of ZigZag indicator, default is 0.03\npriceModel._chartTitle = \"\"  # chart title, usually generated automatically\n\n# Prices have not yet been generated and not loaded, let's check this:\nprint(\"Current prices:\\n{}\".format(priceModel.prices))\n\n# We launch the price generator, and they will be saved in the\n# priceModel.prices field in the Pandas DataFrame format:\npriceModel.Generate()\n\n# Make sure the prices are generated:\nprint(\"Generated prices as Pandas DataFrame:\\n{}\".format(priceModel.prices))\n\n# The dictionary with the calculated statistics is saved to a field self.stat:\nprint(\"Dict with statistics:\\n{}\".format(priceModel.stat))\n\n# Saving OHLCV-prices into .csv-file:\npriceModel.SaveToFile(fileName=\"test.csv\")\n\n# Saving the price chart to a html-file and immediately opening it in the default browser.\n# The statistics will be automatically saved in a markdown file named fileName + \".md\".\npriceModel.RenderBokeh(fileName=\"index.html\", viewInBrowser=True)\n\n# Instead of the Bokeh library, you can use simple, non-interactive chart,\n# via the Google Candlestick chart library. Just uncomment the next lines.\n# Before calling priceModel.RenderGoogle(), you can set your custom template in self.j2template\n# priceModel.j2template = \"google_template_example.j2\"  # file or multi-string variable with jinja2-template\n# priceModel.RenderGoogle(fileName=\"index.html\", viewInBrowser=True)\n```\n\nWhen you run the script, you will receive a similar output to the logs, three files: `test.csv`,` index.html` and `index.html.md`. As well as the html-file with the price chart will be immediately opened in the browser. You can independently experiment with the parameters of the `PriceGenerator()` class to generate prices suitable for your conditions.\n\nAlso, you can manipulate with chart and adding lines or markers to the main chart. Use `markers` and `lines` parameters for it.\n\n`markers` is a Pandas DataFrame with additional markers will place on main series. `None` by default. One marker is a custom symbol, e.g. ×, ↓ or ↑ or anyone else. Markers dataframe must contain at least two columns. There are `datetime` with date and time and some markers columns (`markersUpper`, `markersCenter` or `markersLower`). Length of markers dataframe must be equal to the length of main candle series.\n\n`lines` is a list of Pandas DataFrames with additional chart-lines will place on main series. `None` by default. Every line data must contain at least two columns. There are `datetime` with date and time and `custom_line_name` with y-coordinates. Length of the chart-line dataframes must be equal to the length of main candle series.\n\nExample:\n\n```python\nfrom pricegenerator.PriceGenerator import PriceGenerator, uLogger\nfrom datetime import datetime, timedelta\nimport pandas as pd\n\nuLogger.setLevel(0)  # Disable logging messages.\n\n# Initialize PriceGenerator:\npriceModel = PriceGenerator()\npriceModel.ticker = \"TEST_PRICES\"\npriceModel.precision = 0\npriceModel.timeframe = timedelta(days=1)\npriceModel.timeStart = datetime.today()\npriceModel.horizon = 75\npriceModel.maxClose = 140\npriceModel.minClose = 40\npriceModel.initClose = 50\npriceModel.maxOutlier = 35\npriceModel.maxCandleBody = 15\npriceModel.maxVolume = 400000\npriceModel.upCandlesProb = 0.51\npriceModel.outliersProb = 0.1\npriceModel.trendDeviation = 0.005\npriceModel.trendSplit = \"/\\/\"\npriceModel.splitCount = [40, 10, 25]\n\npriceModel.Generate()  # Generate main candles series.\n\n# Let's draw new average line on the main chart and set markers on the top, center and bottom of candles:\npriceModel.prices[\"avg\"] = priceModel.prices.low + (priceModel.prices.high - priceModel.prices.low) / 2\npriceModel.prices[\"markersUpper\"] = pd.Series([\"↓\"] * len(priceModel.prices.high))\npriceModel.prices[\"markersCenter\"] = pd.Series([\"×\"] * len(priceModel.prices.avg))\npriceModel.prices[\"markersLower\"] = pd.Series([\"↑\"] * len(priceModel.prices.low))\npriceModel.RenderBokeh(\n    fileName=\"index1.html\",\n    viewInBrowser=True,\n    darkTheme=True,  # Set `False` for light theme.\n    markers=priceModel.prices[[\"datetime\", \"markersUpper\", \"markersCenter\", \"markersLower\"]],\n    lines=[priceModel.prices[[\"datetime\", \"avg\"]]],\n    showStatOnChart=True,\n    showControlsOnChart=True,\n    inline=False,  # Set `True` if script runs in Jupyter Notebook.\n)\n```\n\nOutput:\n\n![Marked chart](./media/marked_dark.png)\n\nThat's all! Good luck for you in automating and testing stock trading! ;)\n\n[![gift](https://badgen.net/badge/gift/donate/green)](https://yoomoney.ru/fundraise/BxB9DQNvJnk.230111)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftim55667757%2Fpricegenerator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftim55667757%2Fpricegenerator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftim55667757%2Fpricegenerator/lists"}