fractal.loaders package

Subpackages

Submodules

fractal.loaders.aave module

class fractal.loaders.aave.AaveLoader(reserve_id: str, loader_type: LoaderType, url: str, start_time: datetime = None, resolution: int = 1)[source]

Bases: Loader

extract()[source]
load()[source]
read(with_run: bool = False) LendingHistory[source]
transform()[source]
class fractal.loaders.aave.AaveV2EthereumLoader(asset_address: str, loader_type: LoaderType, start_time: datetime = None, resolution: int = 1)[source]

Bases: AaveLoader

class fractal.loaders.aave.AaveV3ArbitrumLoader(asset_address: str, loader_type: LoaderType, start_time: datetime = None, resolution: int = 1)[source]

Bases: AaveLoader

fractal.loaders.base_loader module

class fractal.loaders.base_loader.Loader(loader_type: LoaderType, *args, **kwargs)[source]

Bases: ABC

abstract extract()[source]
file_path(*args)[source]
abstract load()[source]
abstract read(with_run: bool = False) DataFrame[source]
run()[source]
abstract transform()[source]
class fractal.loaders.base_loader.LoaderType(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

CSV = 1
JSON = 2
PICKLE = 4
SQL = 3

fractal.loaders.binance module

class fractal.loaders.binance.BinanceDayPriceLoader(ticker: str, loader_type: LoaderType, inverse_price: bool = False)[source]

Bases: Loader

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

Reads the price history data from the Binance loader.

Parameters:

with_run (bool, optional) – If True, runs the loader before reading the data. Defaults to False.

Returns:

The price history data.

Return type:

PriceHistory

transform()[source]
class fractal.loaders.binance.BinanceFundingLoader(ticker: str, loader_type: LoaderType = LoaderType.CSV, start_time: datetime = None, end_time: datetime = None)[source]

Bases: Loader

extract()[source]
get_funding_rates(ticker: str, start_time: datetime = None, end_time: datetime = None) list[source]

Get funding rate history

Parameters:
  • ticker – str

  • start_time – datetime

  • end_time – datetime

Returns:

List of funding rates

Return type:

list

load()[source]
read(with_run: bool = False) FundingHistory[source]
transform()[source]
class fractal.loaders.binance.BinanceHourPriceLoader(ticker: str, loader_type: LoaderType = LoaderType.CSV, start_time: datetime = None, end_time: datetime = None, inverse_price: bool = False)[source]

Bases: Loader

extract()[source]
get_klines(ticker: str, start_time: datetime = None, end_time: datetime = None) list[source]

Get Kline/Candlestick Data Klines are uniquely identified by their open time.

Parameters:
  • ticker – str

  • start_time – datetime

  • end_time – datetime

Returns:

List of klines

Return type:

list

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

fractal.loaders.gmx_v1 module

class fractal.loaders.gmx_v1.GMXV1FundingLoader(token_address: str, loader_type: LoaderType)[source]

Bases: Loader

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

fractal.loaders.structs module

class fractal.loaders.structs.FundingHistory(rates: array, time: array)[source]

Bases: DataFrame

Funding history data structure.

class fractal.loaders.structs.LendingHistory(lending_rates: array, borrowing_rates: array, time: array)[source]

Bases: DataFrame

Lending/borrowing history data structure.

class fractal.loaders.structs.PoolHistory(tvls: array, volumes: array, fees: array, liquidity: array, time: array, prices: array | None = None)[source]

Bases: DataFrame

Pool data structure.

class fractal.loaders.structs.PriceHistory(prices: array, time: array)[source]

Bases: DataFrame

Price history data structure.

class fractal.loaders.structs.RateHistory(rates: array, time: array)[source]

Bases: DataFrame

Staking rate history data structure.

Module contents

class fractal.loaders.AaveV2EthereumLoader(asset_address: str, loader_type: LoaderType, start_time: datetime = None, resolution: int = 1)[source]

Bases: AaveLoader

class fractal.loaders.AaveV3ArbitrumLoader(asset_address: str, loader_type: LoaderType, start_time: datetime = None, resolution: int = 1)[source]

Bases: AaveLoader

class fractal.loaders.ArbitrumGraphLoader(api_key: str, subgraph_id: str, loader_type: LoaderType)[source]

Bases: BaseGraphLoader

Graph Loader with arbitrum gateway

ROOT_URL = 'https://gateway-arbitrum.network.thegraph.com/api'
class fractal.loaders.BaseGraphLoader(root_url: str, api_key: str, subgraph_id: str, loader_type: LoaderType)[source]

Bases: Loader

Base class for The Graph loaders.

Each graph loader should inherit from this class. It should have the following attributes: - subgraph_id: The ID of the subgraph - root_url: The root URL of the graph - api_key: The API key to access

_make_request()[source]

Make a request to the graph with a given query

class fractal.loaders.BinanceDayPriceLoader(ticker: str, loader_type: LoaderType, inverse_price: bool = False)[source]

Bases: Loader

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

Reads the price history data from the Binance loader.

Parameters:

with_run (bool, optional) – If True, runs the loader before reading the data. Defaults to False.

Returns:

The price history data.

Return type:

PriceHistory

transform()[source]
class fractal.loaders.BinanceFundingLoader(ticker: str, loader_type: LoaderType = LoaderType.CSV, start_time: datetime = None, end_time: datetime = None)[source]

Bases: Loader

extract()[source]
get_funding_rates(ticker: str, start_time: datetime = None, end_time: datetime = None) list[source]

Get funding rate history

Parameters:
  • ticker – str

  • start_time – datetime

  • end_time – datetime

Returns:

List of funding rates

Return type:

list

load()[source]
read(with_run: bool = False) FundingHistory[source]
transform()[source]
class fractal.loaders.BinanceHourPriceLoader(ticker: str, loader_type: LoaderType = LoaderType.CSV, start_time: datetime = None, end_time: datetime = None, inverse_price: bool = False)[source]

Bases: Loader

extract()[source]
get_klines(ticker: str, start_time: datetime = None, end_time: datetime = None) list[source]

Get Kline/Candlestick Data Klines are uniquely identified by their open time.

Parameters:
  • ticker – str

  • start_time – datetime

  • end_time – datetime

Returns:

List of klines

Return type:

list

load()[source]
read(with_run: bool = False) PriceHistory[source]
transform()[source]
class fractal.loaders.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.EthereumUniswapV2PoolDataLoader(api_key: str, pool: str, fee_tier: float, loader_type: LoaderType)[source]

Bases: EthereumUniswapV2Loader

Loader for Uniswap V2 PoolData

extract()[source]
load()[source]
read(with_run: bool = False) PoolHistory[source]
transform()[source]
class fractal.loaders.FundingHistory(rates: array, time: array)[source]

Bases: DataFrame

Funding history data structure.

class fractal.loaders.GMXV1FundingLoader(token_address: str, loader_type: LoaderType)[source]

Bases: Loader

extract()[source]
load()[source]
read(with_run: bool = False) FundingHistory[source]
transform()[source]
exception fractal.loaders.GraphLoaderException[source]

Bases: Exception

class fractal.loaders.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.LPSimulatedStates(tvls: array, volumes: array, fees: array, liquidity: array, time: array, prices: array)[source]

Bases: DataFrame

Pool data structure.

class fractal.loaders.LendingHistory(lending_rates: array, borrowing_rates: array, time: array)[source]

Bases: DataFrame

Lending/borrowing history data structure.

class fractal.loaders.Loader(loader_type: LoaderType, *args, **kwargs)[source]

Bases: ABC

abstract extract()[source]
file_path(*args)[source]
abstract load()[source]
abstract read(with_run: bool = False) DataFrame[source]
run()[source]
abstract transform()[source]
class fractal.loaders.LoaderType(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

CSV = 1
JSON = 2
PICKLE = 4
SQL = 3
class fractal.loaders.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]
class fractal.loaders.PoolHistory(tvls: array, volumes: array, fees: array, liquidity: array, time: array, prices: array | None = None)[source]

Bases: DataFrame

Pool data structure.

class fractal.loaders.PriceHistory(prices: array, time: array)[source]

Bases: DataFrame

Price history data structure.

class fractal.loaders.RateHistory(rates: array, time: array)[source]

Bases: DataFrame

Staking rate history data structure.

class fractal.loaders.StETHLoader(api_key: str, loader_type: LoaderType)[source]

Bases: ArbitrumGraphLoader

StETH (Lido) Loader. https://thegraph.com/explorer/subgraphs/Sxx812XgeKyzQPaBpR5YZWmGV5fZuBaPdh7DFhzSwiQ?view=Query&chain=arbitrum-one

SUBGRAPH_ID: Sxx812XgeKyzQPaBpR5YZWmGV5fZuBaPdh7DFhzSwiQ

SUBGRAPH_ID = 'Sxx812XgeKyzQPaBpR5YZWmGV5fZuBaPdh7DFhzSwiQ'
extract()[source]
load()[source]
read(with_run: bool = False) RateHistory[source]
transform()[source]
class fractal.loaders.UniswapV3ArbitrumPoolDayDataLoader(api_key: str, pool: str, loader_type: LoaderType)[source]

Bases: ArbitrumUniswapV3Loader

extract()[source]
load()[source]
read(with_run: bool = False) PoolHistory[source]
transform()[source]
class fractal.loaders.UniswapV3ArbitrumPoolHourDataLoader(api_key: str, pool: str, loader_type: LoaderType)[source]

Bases: UniswapV3ArbitrumPoolDayDataLoader

transform()[source]
class fractal.loaders.UniswapV3ArbitrumPricesLoader(api_key: str, pool: str, loader_type: LoaderType, **kwargs)[source]

Bases: ArbitrumUniswapV3Loader

extract()[source]
load()[source]
read(with_run: bool = False) PriceHistory[source]
transform()[source]
class fractal.loaders.UniswapV3EthereumPoolDayDataLoader(api_key: str, pool: str, loader_type: LoaderType)[source]

Bases: EthereumUniswapV3Loader

extract()[source]
load()[source]
read(with_run: bool = False) PoolHistory[source]
transform()[source]
class fractal.loaders.UniswapV3EthereumPoolHourDataLoader(api_key: str, pool: str, loader_type: LoaderType)[source]

Bases: UniswapV3EthereumPoolDayDataLoader

transform()[source]