fractal.loaders package
Subpackages
- fractal.loaders.simulations package
- Submodules
- fractal.loaders.simulations.constant_fundings module
- fractal.loaders.simulations.lp_ml_simulated module
LPMLSimulatedStatesLoader
LPMLSimulatedStatesLoader.pool_history
LPMLSimulatedStatesLoader.price_history
LPMLSimulatedStatesLoader._data
LPMLSimulatedStatesLoader._simulated_data
LPMLSimulatedStatesLoader.trajectories_number
LPMLSimulatedStatesLoader._dump_filename
LPMLSimulatedStatesLoader._random
LPMLSimulatedStatesLoader._np_random
LPMLSimulatedStatesLoader._seed
LPMLSimulatedStatesLoader.delete_dump_file()
LPMLSimulatedStatesLoader.extract()
LPMLSimulatedStatesLoader.load()
LPMLSimulatedStatesLoader.read()
LPMLSimulatedStatesLoader.transform()
LPSimulatedStates
- fractal.loaders.simulations.monte_carlo module
MonteCarloHourPriceLoader
MonteCarloHourPriceLoader.price_history
MonteCarloHourPriceLoader.trajectories_number
MonteCarloHourPriceLoader.loader_type
MonteCarloHourPriceLoader.seed
MonteCarloHourPriceLoader.extract()
MonteCarloHourPriceLoader.transform()
MonteCarloHourPriceLoader.load()
MonteCarloHourPriceLoader.run()
MonteCarloHourPriceLoader.delete_dump_file()
MonteCarloHourPriceLoader.extract()
MonteCarloHourPriceLoader.load()
MonteCarloHourPriceLoader.read()
MonteCarloHourPriceLoader.transform()
- Module contents
ConstantFundingsLoader
LPMLSimulatedStatesLoader
LPMLSimulatedStatesLoader.pool_history
LPMLSimulatedStatesLoader.price_history
LPMLSimulatedStatesLoader._data
LPMLSimulatedStatesLoader._simulated_data
LPMLSimulatedStatesLoader.trajectories_number
LPMLSimulatedStatesLoader._dump_filename
LPMLSimulatedStatesLoader._random
LPMLSimulatedStatesLoader._np_random
LPMLSimulatedStatesLoader._seed
LPMLSimulatedStatesLoader.delete_dump_file()
LPMLSimulatedStatesLoader.extract()
LPMLSimulatedStatesLoader.load()
LPMLSimulatedStatesLoader.read()
LPMLSimulatedStatesLoader.transform()
LPSimulatedStates
MonteCarloHourPriceLoader
MonteCarloHourPriceLoader.price_history
MonteCarloHourPriceLoader.trajectories_number
MonteCarloHourPriceLoader.loader_type
MonteCarloHourPriceLoader.seed
MonteCarloHourPriceLoader.extract()
MonteCarloHourPriceLoader.transform()
MonteCarloHourPriceLoader.load()
MonteCarloHourPriceLoader.run()
MonteCarloHourPriceLoader.delete_dump_file()
MonteCarloHourPriceLoader.extract()
MonteCarloHourPriceLoader.load()
MonteCarloHourPriceLoader.read()
MonteCarloHourPriceLoader.transform()
- fractal.loaders.thegraph package
- Subpackages
- Submodules
- fractal.loaders.thegraph.base_graph_loader module
- fractal.loaders.thegraph.lido module
- Module contents
ArbitrumGraphLoader
ArbitrumUniswapV3Loader
BaseGraphLoader
EthereumUniswapV2Loader
EthereumUniswapV2PoolDataLoader
EthereumUniswapV3Loader
GraphLoaderException
StETHLoader
UniswapV3ArbitrumPoolDayDataLoader
UniswapV3ArbitrumPoolHourDataLoader
UniswapV3ArbitrumPricesLoader
UniswapV3EthereumPoolDayDataLoader
UniswapV3EthereumPoolHourDataLoader
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
- read(with_run: bool = False) LendingHistory [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
fractal.loaders.binance module
- class fractal.loaders.binance.BinanceDayPriceLoader(ticker: str, loader_type: LoaderType, inverse_price: bool = False)[source]
Bases:
Loader
- 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:
- class fractal.loaders.binance.BinanceFundingLoader(ticker: str, loader_type: LoaderType = LoaderType.CSV, start_time: datetime = None, end_time: datetime = None)[source]
Bases:
Loader
- 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
- read(with_run: bool = False) FundingHistory [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
- 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
- read(with_run: bool = False) PriceHistory [source]
fractal.loaders.gmx_v1 module
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.
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
- class fractal.loaders.BinanceDayPriceLoader(ticker: str, loader_type: LoaderType, inverse_price: bool = False)[source]
Bases:
Loader
- 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:
- class fractal.loaders.BinanceFundingLoader(ticker: str, loader_type: LoaderType = LoaderType.CSV, start_time: datetime = None, end_time: datetime = None)[source]
Bases:
Loader
- 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
- read(with_run: bool = False) FundingHistory [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
- 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
- read(with_run: bool = False) PriceHistory [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.
- class fractal.loaders.EthereumUniswapV2PoolDataLoader(api_key: str, pool: str, fee_tier: float, loader_type: LoaderType)[source]
Bases:
EthereumUniswapV2Loader
Loader for Uniswap V2 PoolData
- read(with_run: bool = False) PoolHistory [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
- read(with_run: bool = False) FundingHistory [source]
- 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:
- price_history
The price history data.
- Type:
- _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
- read(with_run: bool = False) List[LPSimulatedStates] [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
- 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:
- trajectories_number
The number of trajectories to simulate.
- Type:
int
- loader_type
The type of loader used to save and load data.
- Type:
- seed
The seed value used for random number generation.
- Type:
int
- 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.
- read(with_run: bool = False) List[PriceHistory] [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'
- read(with_run: bool = False) RateHistory [source]
- class fractal.loaders.UniswapV3ArbitrumPoolDayDataLoader(api_key: str, pool: str, loader_type: LoaderType)[source]
Bases:
ArbitrumUniswapV3Loader
- read(with_run: bool = False) PoolHistory [source]
- class fractal.loaders.UniswapV3ArbitrumPoolHourDataLoader(api_key: str, pool: str, loader_type: LoaderType)[source]
- class fractal.loaders.UniswapV3ArbitrumPricesLoader(api_key: str, pool: str, loader_type: LoaderType, **kwargs)[source]
Bases:
ArbitrumUniswapV3Loader
- read(with_run: bool = False) PriceHistory [source]
- class fractal.loaders.UniswapV3EthereumPoolDayDataLoader(api_key: str, pool: str, loader_type: LoaderType)[source]
Bases:
EthereumUniswapV3Loader
- read(with_run: bool = False) PoolHistory [source]
- class fractal.loaders.UniswapV3EthereumPoolHourDataLoader(api_key: str, pool: str, loader_type: LoaderType)[source]