Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed price without candle #16

Closed
maximedotair opened this issue Oct 21, 2022 · 2 comments
Closed

fixed price without candle #16

maximedotair opened this issue Oct 21, 2022 · 2 comments
Assignees
Labels
Question Further information is requested. How to ...
Milestone

Comments

@maximedotair
Copy link

is it possible to generate fixed price points over a period of time, without candle?

@Tim55667757 Tim55667757 self-assigned this Oct 21, 2022
@Tim55667757 Tim55667757 added the Question Further information is requested. How to ... label Oct 21, 2022
@Tim55667757
Copy link
Owner

Hello, @maximedotair! Thanks for the question.

There is no separate command or method for this right now, but I came up with 2 workarounds for you. See which of these is more easy for your task:

  1. Generate data as usual as candlesticks, and save it in csv-file. Then open the data in any editor, such as Excel or notepad++ and delete unnecessary columns. You can keep, for example, only closing prices and volumes.

  2. You can write a simple script and generate candles using the Generate() method, and then delete unnecessary columns in the pandas dataframe, keeps only datetime and close price columns (e. g. with pandas drop method: prices.drop(labels=["open", "high", "low", "volume"], axis=1)), or just edit PriceGenerator.csvHeaders = ["date", "time", "close"] and then save csv-file using PriceGenerator.SaveToFile() method.

Let me know if it helped you.


Let's try the 1st case. Here is an example of generate 20 candles with 15-min timeframe and started at 2022-10-22 12:00:

Command
pricegenerator --debug-level 10 --precision 2 --timeframe 15 --start "2022-10-22 12:00" --horizon 20 --generate --save-to test.csv

PriceGenerator.py   L:1263 DEBUG   [2022-10-22 19:11:33,591] =--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--=
PriceGenerator.py   L:1264 DEBUG   [2022-10-22 19:11:33,592] PriceGenerator started: 2022-10-22 19:11:33
PriceGenerator.py   L:692  INFO    [2022-10-22 19:11:33,594] Generating prices...
PriceGenerator.py   L:693  DEBUG   [2022-10-22 19:11:33,595] - Ticker name: TEST
PriceGenerator.py   L:694  DEBUG   [2022-10-22 19:11:33,595] - Precision: 2
PriceGenerator.py   L:695  DEBUG   [2022-10-22 19:11:33,596] - Interval or timeframe (time delta between two neighbour candles): 0:15:00
PriceGenerator.py   L:696  DEBUG   [2022-10-22 19:11:33,596] - Horizon length (candlesticks count): 20
PriceGenerator.py   L:701  DEBUG   [2022-10-22 19:11:33,597] - Start time: 2022-10-22 12:00:00
PriceGenerator.py   L:702  DEBUG   [2022-10-22 19:11:33,597]   |-> end time: 2022-10-22 17:00:00
PriceGenerator.py   L:703  DEBUG   [2022-10-22 19:11:33,597] - Maximum of close prices: 72.63
PriceGenerator.py   L:704  DEBUG   [2022-10-22 19:11:33,598] - Minimum of close prices: 61.78
PriceGenerator.py   L:705  DEBUG   [2022-10-22 19:11:33,599] - Maximum of candle body sizes: 0.98
PriceGenerator.py   L:706  DEBUG   [2022-10-22 19:11:33,599] - Maximum of candle tails outlier sizes: 1.09
PriceGenerator.py   L:707  DEBUG   [2022-10-22 19:11:33,599] - Init close (1st open price in chain): 64.37
PriceGenerator.py   L:708  DEBUG   [2022-10-22 19:11:33,599] - Maximum of volume of one candle: 42776
PriceGenerator.py   L:709  DEBUG   [2022-10-22 19:11:33,600] - Probability that next candle is up: 50.0%
PriceGenerator.py   L:710  DEBUG   [2022-10-22 19:11:33,600] - Statistical outliers probability: 3.0%
PriceGenerator.py   L:777  INFO    [2022-10-22 19:11:33,602] Showing last 5 rows of Pandas generated dataframe object:
PriceGenerator.py   L:779  INFO    [2022-10-22 19:11:33,609]                     datetime   open   high    low  close  volume
PriceGenerator.py   L:779  INFO    [2022-10-22 19:11:33,609] 15 2022-10-22 15:45:00+03:00  63.75  63.77  63.69  63.70   20073
PriceGenerator.py   L:779  INFO    [2022-10-22 19:11:33,609] 16 2022-10-22 16:00:00+03:00  63.70  64.02  63.64  63.92    3922
PriceGenerator.py   L:779  INFO    [2022-10-22 19:11:33,610] 17 2022-10-22 16:15:00+03:00  63.92  63.95  63.92  63.94   19201
PriceGenerator.py   L:779  INFO    [2022-10-22 19:11:33,610] 18 2022-10-22 16:30:00+03:00  63.94  65.01  63.74  64.88    3623
PriceGenerator.py   L:779  INFO    [2022-10-22 19:11:33,611] 19 2022-10-22 16:45:00+03:00  64.88  64.95  63.77  63.97    3869
PriceGenerator.py   L:435  INFO    [2022-10-22 19:11:33,611] Saving [20] rows of pandas dataframe with columns: ['date', 'time', 'open', 'high', 'low', 'close', 'volume']...
PriceGenerator.py   L:436  DEBUG   [2022-10-22 19:11:33,611] Delimeter: ,
PriceGenerator.py   L:443  INFO    [2022-10-22 19:11:33,617] Pandas dataframe saved to .csv-file [test.csv]
PriceGenerator.py   L:1354 DEBUG   [2022-10-22 19:11:33,618] All PriceGenerator operations are finished success (summary code is 0).
PriceGenerator.py   L:1359 DEBUG   [2022-10-22 19:11:33,618] PriceGenerator work duration: 0:00:00.026960
PriceGenerator.py   L:1360 DEBUG   [2022-10-22 19:11:33,621] PriceGenerator work finished: 2022-10-22 19:11:33

Here is generated .csv-data:

test.csv
2022-10-22,12:00:00,64.37,64.84,63.25,63.4,16857
2022-10-22,12:15:00,63.4,63.55,62.89,63.0,32186
2022-10-22,12:30:00,63.0,63.66,62.96,63.5,17629
2022-10-22,12:45:00,63.5,63.61,62.39,62.75,30496
2022-10-22,13:00:00,62.75,63.43,62.46,63.4,40621
2022-10-22,13:15:00,63.4,63.43,63.19,63.22,17227
2022-10-22,13:30:00,63.22,63.31,63.2,63.28,19176
2022-10-22,13:45:00,63.28,63.3,63.27,63.3,27833
2022-10-22,14:00:00,63.3,64.31,63.18,64.16,4023
2022-10-22,14:15:00,64.16,65.06,63.94,65.03,6730
2022-10-22,14:30:00,65.03,65.06,64.95,64.95,38035
2022-10-22,14:45:00,64.95,65.28,64.92,65.19,7644
2022-10-22,15:00:00,65.19,65.51,63.99,64.23,34083
2022-10-22,15:15:00,64.23,64.3,63.51,63.68,3340
2022-10-22,15:30:00,63.68,63.76,63.65,63.75,3513
2022-10-22,15:45:00,63.75,63.77,63.69,63.7,20073
2022-10-22,16:00:00,63.7,64.02,63.64,63.92,3922
2022-10-22,16:15:00,63.92,63.95,63.92,63.94,19201
2022-10-22,16:30:00,63.94,65.01,63.74,64.88,3623
2022-10-22,16:45:00,64.88,64.95,63.77,63.97,3869

And then delete some columns:

Screenshot

image


Let's try the 2nd case. Here is code example that generates 20 candles with 15-min timeframe and started at 2022-10-22 12:00 as in 1st scenario:

Code block
import pandas as pd
from pricegenerator.PriceGenerator import PriceGenerator, uLogger
from datetime import datetime, timedelta

uLogger.setLevel(10)  # set debug level

# --- generates 20 candles with 15-min timeframe and started at 2022-10-22 12:00:
# `--debug-level 10 --precision 2 --timeframe 15 --start "2022-10-22 12:00" --horizon 20 --generate --save-to test.csv`
priceModel = PriceGenerator()
priceModel.precision = 2
priceModel.timeframe = timedelta(minutes=15)
priceModel.timeStart = datetime.now().replace(year=2022, month=10, day=22, hour=12, minute=0, second=0, microsecond=0)
priceModel.horizon = 20

# Generating candles as pandas dataframe, after that class field `prices` contains columns: datetime open high low close volume
priceModel.Generate()

# 1) Edit dataframe if you want: keep only date, time and close columns:
priceModel.prices = priceModel.prices.drop(labels=["open", "high", "low", "volume"], axis=1)
uLogger.info("Keep only datetime and close columns:")
for line in pd.DataFrame.to_string(priceModel.prices[-5:], max_cols=20).split("\n"):
    uLogger.info(line)

# 2) Or just edit `csvHeaders` class field and then save csv-file, instead of using 1)
priceModel.csvHeaders = ["date", "time", "close"]  # control what columns are saved
priceModel.SaveToFile(fileName="closePrices.csv")

Run script.

Log
PriceGenerator.py   L:692  INFO    [2022-10-22 21:12:56,229] Generating prices...
PriceGenerator.py   L:777  INFO    [2022-10-22 21:12:56,232] Showing last 5 rows of Pandas generated dataframe object:
PriceGenerator.py   L:779  INFO    [2022-10-22 21:12:56,239]                     datetime   open   high    low  close  volume
PriceGenerator.py   L:779  INFO    [2022-10-22 21:12:56,239] 15 2022-10-22 15:45:00+03:00  80.98  81.55  78.83  79.53   12841
PriceGenerator.py   L:779  INFO    [2022-10-22 21:12:56,239] 16 2022-10-22 16:00:00+03:00  79.53  81.59  79.01  81.19   11276
PriceGenerator.py   L:779  INFO    [2022-10-22 21:12:56,240] 17 2022-10-22 16:15:00+03:00  81.19  81.45  80.50  80.55    3439
PriceGenerator.py   L:779  INFO    [2022-10-22 21:12:56,240] 18 2022-10-22 16:30:00+03:00  80.55  80.82  80.53  80.77   10492
PriceGenerator.py   L:779  INFO    [2022-10-22 21:12:56,240] 19 2022-10-22 16:45:00+03:00  80.77  81.67  80.47  81.60    9755
111.py              L:20   INFO    [2022-10-22 21:12:56,240] Keep only datetime and close columns:
111.py              L:22   INFO    [2022-10-22 21:12:56,242]                     datetime  close
111.py              L:22   INFO    [2022-10-22 21:12:56,243] 15 2022-10-22 15:45:00+03:00  79.53
111.py              L:22   INFO    [2022-10-22 21:12:56,243] 16 2022-10-22 16:00:00+03:00  81.19
111.py              L:22   INFO    [2022-10-22 21:12:56,243] 17 2022-10-22 16:15:00+03:00  80.55
111.py              L:22   INFO    [2022-10-22 21:12:56,243] 18 2022-10-22 16:30:00+03:00  80.77
111.py              L:22   INFO    [2022-10-22 21:12:56,243] 19 2022-10-22 16:45:00+03:00  81.60
PriceGenerator.py   L:435  INFO    [2022-10-22 21:12:56,243] Saving [20] rows of pandas dataframe with columns: ['date', 'time', 'close']...
PriceGenerator.py   L:443  INFO    [2022-10-22 21:12:56,249] Pandas dataframe saved to .csv-file [closePrices.csv]

Output csv-file:

closePrices.csv
2022-10-22,12:00:00,69.07
2022-10-22,12:15:00,69.45
2022-10-22,12:30:00,71.01
2022-10-22,12:45:00,72.74
2022-10-22,13:00:00,72.95
2022-10-22,13:15:00,74.06
2022-10-22,13:30:00,74.81
2022-10-22,13:45:00,76.41
2022-10-22,14:00:00,77.33
2022-10-22,14:15:00,78.87
2022-10-22,14:30:00,78.8
2022-10-22,14:45:00,80.4
2022-10-22,15:00:00,82.13
2022-10-22,15:15:00,81.91
2022-10-22,15:30:00,80.98
2022-10-22,15:45:00,79.53
2022-10-22,16:00:00,81.19
2022-10-22,16:15:00,80.55
2022-10-22,16:30:00,80.77
2022-10-22,16:45:00,81.6

Here is the result:

Screenshot

image

@Tim55667757 Tim55667757 added this to the release-1.3 milestone Jan 3, 2023
Tim55667757 added a commit that referenced this issue Jan 5, 2023
@Tim55667757
Copy link
Owner

Implement since build v1.3.dev78

Debug build: https://app.travis-ci.com/github/Tim55667757/PriceGenerator/builds/259412521
PyPI artifact for testing: https://pypi.org/project/pricegenerator/1.3.dev78/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Further information is requested. How to ...
Projects
None yet
Development

No branches or pull requests

2 participants