Summary
How do I create an OHLC dataframe using Numpy/Pandas
- which has an ATR or trading range of somewhere around
.0075
to.02
or range could be specified as a variable. Looking to see random price moves roughly within these boundaries. - with a
Close
value on first row at1.1904
(see example below). - and can use a seed value (i.e.
np.random.seed
) so the dataframe is reproducible.
Overview
I'm trying to generate mock forex data to create reproducible examples for pandas questions using Numpy/Pandas. This question covers similar data requirements but a Forex data example using Open, High, Low, Close Data could be useful and help avoid pasting large amounts of data into a question.
As an example of how the dataframe should look I see the euro/dollar rate on Friday was as follows:
eur = {"open" : 1.19160,
"high" : 1.19371,
"low" : 1.18739,
"close" : 1.1904}
pd.DataFrame(eur,index=['19/3/2021'])
What have I tried so far?
This is a fake/mock data example based on the previously mentioned question that gives an idea as to what I am looking for in terms of how the data is generated with np.random
. I have added a resample and converted to OHLC but not sure how to generate/control the data with Numpy.
periods = 250
eurusd = pd.DataFrame({
'ticker':np.repeat( ['eurusd'], periods ),
'date':np.tile( pd.date_range('1/1/2011', periods=periods, freq='H'), 1 ),
'price':(np.random.randn(periods).cumsum() + 10) })
eurusd.index = pd.to_datetime(eurusd.date)
eurusd.price.resample('D').ohlc()
Edit
I have updated my attempt to generate this data (see "What have I tried so far" below) by generating OHLC columns after resampling to Daily from hourly data. I am still working on the Numpy data generation element to generate a range of somewhere around .0075
each day.