tensortrade.stochastic.utils.helpers module

tensortrade.stochastic.utils.helpers.convert_to_prices(param: tensortrade.stochastic.utils.parameters.ModelParameters, log_returns: numpy.array) → numpy.array[source]

Converts a sequence of log returns into normal returns (exponentiation) and then computes a price sequence given a starting price, param.all_s0.

Parameters
  • param (ModelParameters) – The model parameters.

  • log_returns (np.array) – The log returns.

Returns

np.array – The price sequence.

tensortrade.stochastic.utils.helpers.generate(price_fn: Callable[tensortrade.stochastic.utils.parameters.ModelParameters, numpy.array], base_price: int = 1, base_volume: int = 1, start_date: str = '2010-01-01', start_date_format: str = '%Y-%m-%d', times_to_generate: int = 1000, time_frame: str = '1h', params: tensortrade.stochastic.utils.parameters.ModelParameters = None) → pandas.core.frame.DataFrame[source]

Generates a data frame of OHLCV data based on the price model specified.

Parameters
  • price_fn (Callable[[ModelParameters], np.array]) – The price function generate the prices based on the chosen model.

  • base_price (int, default 1) – The base price to use for price generation.

  • base_volume (int, default 1) – The base volume to use for volume generation.

  • start_date (str, default '2010-01-01') – The start date of the generated data

  • start_date_format (str, default '%Y-%m-%d') – The format for the start date of the generated data.

  • times_to_generate (int, default 1000) – The number of bars to make.

  • time_frame (str, default '1h') – The time frame.

  • params (ModelParameters, optional) – The model parameters.

Returns

pd.DataFrame – The data frame containing the OHLCV bars.

tensortrade.stochastic.utils.helpers.get_delta(time_frame: str)float[source]

Gets the time delta for a given time frame.

Parameters

time_frame (str) – The time frame for generating. (e.g. 1h, 1min, 1w, 1d)

Returns

float – The time delta for the given time frame.

tensortrade.stochastic.utils.helpers.scale_times_to_generate(times_to_generate: int, time_frame: str)int[source]

Adjusts the number of times to generate the prices based on a time frame.

Parameters
  • times_to_generate (int) – The number of time to generate prices.

  • time_frame (str) – The time frame for generating. (e.g. 1h, 1min, 1w, 1d)

Returns

int – The adjusted number of times to generate.

Raises

ValueError – Raised if the time_frame provided does not match the correct format.