fractal.loaders.simulations package

Submodules

fractal.loaders.simulations.constant_fundings module

class fractal.loaders.simulations.constant_fundings.ConstantFundingsLoader(rate: float = -0.001, freq: str = 'D', start: str = '2020-01-01', end: str = '2025-01-01')[source]

Bases: Loader

Generates a constant funding rate for a given period.

extract()[source]
load()[source]
read(with_run: bool = False)[source]
transform()[source]

fractal.loaders.simulations.lp_ml_simulated module

class fractal.loaders.simulations.lp_ml_simulated.LPMLSimulatedStatesLoader(price_history: PriceHistory, pool_history: PoolHistory, trajectories_number: int = 100, loader_type: LoaderType = LoaderType.PICKLE, seed: int = 420, random_filename: bool = True)[source]

Bases: Loader

A loader class for generating simulated states

using machine learning models.

Generates pool stated (with price_history) for LP strategies. Prices generates as GBM process with drift and volatility,

which are calculated from the historical data in rolling windows.

The pool data is generated using CatBoostRegressor models,

using the price data, log returns, realized volatility, momentum, and moving average difference as predictors.

After prediction, the residuals are added to the predictions,

as samples from the residuals distribution.

The residuals distribution is estimated using the histogram. Also, pool data is smoothed using a rolling mean.

Parameters:
  • price_history (PriceHistory) – The price history data.

  • pool_history (PoolHistory) – The pool data.

  • trajectories_number (int, optional) – The number of trajectories to generate. Defaults to 100.

  • loader_type (LoaderType, optional) – The type of loader. Defaults to LoaderType.PICKLE.

  • seed (int, optional) – The seed for random number generation. Defaults to 420.

  • random_filename (bool, optional) – Whether to use a random filename for saving the data. Defaults to True.

pool_history

The pool data.

Type:

PoolHistory

price_history

The price history data.

Type:

PriceHistory

_data

The merged data of price_history and pool data.

Type:

pd.DataFrame

_simulated_data

The list of simulated data.

Type:

List[pd.DataFrame]

trajectories_number

The number of trajectories to generate.

Type:

int

_dump_filename

The filename for saving the data.

Type:

str

_random

The random number generator.

Type:

random.Random

_np_random

The numpy random number generator.

Type:

numpy.random.Generator

_seed

The seed for random number generation.

Type:

int

delete_dump_file()[source]
extract()[source]
load()[source]
read(with_run: bool = False) List[LPSimulatedStates][source]
transform()[source]
class fractal.loaders.simulations.lp_ml_simulated.LPSimulatedStates(tvls: array, volumes: array, fees: array, liquidity: array, time: array, prices: array)[source]

Bases: DataFrame

Pool data structure.

fractal.loaders.simulations.monte_carlo module

class fractal.loaders.simulations.monte_carlo.MonteCarloHourPriceLoader(price_history: PriceHistory, trajectories_number: int = 100, loader_type: LoaderType = LoaderType.PICKLE, seed: int = 420)[source]

Bases: Loader

A class that represents a Monte Carlo hour price loader.

This loader performs Monte Carlo simulation on the price data, obtained from a base loader.

Generates prices using a GBM process with volatility,

and without drift.

Length of the simulation is equal to the length of the base loader data.

price_history

The price history data.

Type:

PriceHistory

trajectories_number

The number of trajectories to simulate.

Type:

int

loader_type

The type of loader used to save and load data.

Type:

LoaderType

seed

The seed value used for random number generation.

Type:

int

extract()[source]

Extracts the price data from the base loader.

transform()[source]

Performs Monte Carlo simulation on the price data.

load()[source]

Saves the simulated price data using the specified loader type.

read(with_run

bool = False): Reads the simulated price data from the saved file.

run()

Executes the entire process of extracting, transforming, and loading the data.

delete_dump_file()[source]
extract()[source]
load()[source]
read(with_run: bool = False) List[PriceHistory][source]
transform()[source]

Module contents

class fractal.loaders.simulations.ConstantFundingsLoader(rate: float = -0.001, freq: str = 'D', start: str = '2020-01-01', end: str = '2025-01-01')[source]

Bases: Loader

Generates a constant funding rate for a given period.

extract()[source]
load()[source]
read(with_run: bool = False)[source]
transform()[source]
class fractal.loaders.simulations.LPMLSimulatedStatesLoader(price_history: PriceHistory, pool_history: PoolHistory, trajectories_number: int = 100, loader_type: LoaderType = LoaderType.PICKLE, seed: int = 420, random_filename: bool = True)[source]

Bases: Loader

A loader class for generating simulated states

using machine learning models.

Generates pool stated (with price_history) for LP strategies. Prices generates as GBM process with drift and volatility,

which are calculated from the historical data in rolling windows.

The pool data is generated using CatBoostRegressor models,

using the price data, log returns, realized volatility, momentum, and moving average difference as predictors.

After prediction, the residuals are added to the predictions,

as samples from the residuals distribution.

The residuals distribution is estimated using the histogram. Also, pool data is smoothed using a rolling mean.

Parameters:
  • price_history (PriceHistory) – The price history data.

  • pool_history (PoolHistory) – The pool data.

  • trajectories_number (int, optional) – The number of trajectories to generate. Defaults to 100.

  • loader_type (LoaderType, optional) – The type of loader. Defaults to LoaderType.PICKLE.

  • seed (int, optional) – The seed for random number generation. Defaults to 420.

  • random_filename (bool, optional) – Whether to use a random filename for saving the data. Defaults to True.

pool_history

The pool data.

Type:

PoolHistory

price_history

The price history data.

Type:

PriceHistory

_data

The merged data of price_history and pool data.

Type:

pd.DataFrame

_simulated_data

The list of simulated data.

Type:

List[pd.DataFrame]

trajectories_number

The number of trajectories to generate.

Type:

int

_dump_filename

The filename for saving the data.

Type:

str

_random

The random number generator.

Type:

random.Random

_np_random

The numpy random number generator.

Type:

numpy.random.Generator

_seed

The seed for random number generation.

Type:

int

delete_dump_file()[source]
extract()[source]
load()[source]
read(with_run: bool = False) List[LPSimulatedStates][source]
transform()[source]
class fractal.loaders.simulations.LPSimulatedStates(tvls: array, volumes: array, fees: array, liquidity: array, time: array, prices: array)[source]

Bases: DataFrame

Pool data structure.

class fractal.loaders.simulations.MonteCarloHourPriceLoader(price_history: PriceHistory, trajectories_number: int = 100, loader_type: LoaderType = LoaderType.PICKLE, seed: int = 420)[source]

Bases: Loader

A class that represents a Monte Carlo hour price loader.

This loader performs Monte Carlo simulation on the price data, obtained from a base loader.

Generates prices using a GBM process with volatility,

and without drift.

Length of the simulation is equal to the length of the base loader data.

price_history

The price history data.

Type:

PriceHistory

trajectories_number

The number of trajectories to simulate.

Type:

int

loader_type

The type of loader used to save and load data.

Type:

LoaderType

seed

The seed value used for random number generation.

Type:

int

extract()[source]

Extracts the price data from the base loader.

transform()[source]

Performs Monte Carlo simulation on the price data.

load()[source]

Saves the simulated price data using the specified loader type.

read(with_run

bool = False): Reads the simulated price data from the saved file.

run()

Executes the entire process of extracting, transforming, and loading the data.

delete_dump_file()[source]
extract()[source]
load()[source]
read(with_run: bool = False) List[PriceHistory][source]
transform()[source]