utils
mainsequence.virtualfundbuilder.utils
build_markdown(root_class, persist=True, elements_to_exclude=None, children_to_exclude=None)
Builds standards portfolio configuration documentation Returns:
build_rolling_regression_from_df(x, y, rolling_window, column_names, threads=5)
Builds rolling regressions for multiple variables in parallel using a specified rolling window.
Args: x (NDArray): An array of independent variables. y (NDArray): An array of dependent variables. rolling_window (int): The size of the rolling window for each regression. column_names (list): Names of the dependent variables, used for labeling the output. threads (int): Number of threads to use for parallel processing.
Returns: pd.DataFrame: A DataFrame containing the regression results for all variables.
convert_to_binance_frequency(freq)
Converts a generic frequency format to a format compatible with Binance API requirements.
Args: freq (str): The generic frequency format (e.g., '1m', '1h').
Returns: str: A frequency string adapted for Binance API (e.g., '1m', '1h').
default_config_to_dict(default_config)
Convert the default configuration into a Python dictionary.
Args: default_config (dict): Default configuration from the VFB tool.
Returns: dict: Processed configuration dictionary.
do_single_regression(xx, XTX_inv_list, rolling_window, col_name, tmp_y, XTX_inv_diag)
Performs a single regression analysis on a sliding window of data points for a specific column.
Args: xx (NDArray): An array of independent variable data with a sliding window applied. XTX_inv_list (list): A list of precomputed inverse matrices of X.T @ X for each window. rolling_window (int): The number of observations per window. col_name (str): The name of the column being analyzed, used for labeling the output. tmp_y (NDArray): The dependent variable data. XTX_inv_diag (list): Diagonals of the precomputed inverse matrices, used for standard error calculation.
Returns: pd.DataFrame: A DataFrame containing the regression results with coefficients, R-squared, and t-statistics.
filter_assets(df, asset_list)
Filters a DataFrame to include only rows that have asset symbols contained in a given asset list.
get_last_query_times_per_asset(latest_value, metadata, asset_list, max_lookback_time, current_time, query_frequency)
Determines the last query times for each asset based on metadata, a specified lookback limit, and a query frequency.
Args: latest_value (datetime|None): Timestamp of the last value in the database for each asset. metadata (dict): Metadata containing previous query information for each coin. asset_list (List[Asset]): List of asset objects to process. max_lookback_time (datetime): Maximum historical lookback time allowed for the node. current_time (datetime): Current time to consider for the calculations. query_frequency (str): Query frequency as a pandas-parseable string to determine if new data needs fetching.
Returns: Dict[str, Optional[float]]: A dictionary mapping asset IDs to their respective last query times expressed in UNIX timestamp.
object_signature_to_markdown(root_dict, level=1, elements_to_exclude=None, children_to_exclude=None)
Convert a nested dictionary structure into a markdown formatted string.
Args: - root_dict (dict): The nested dictionary to convert. - level (int): The current markdown header level.
Returns: - str: The markdown formatted string.
object_signature_to_yaml(default_config)
Convert the default configuration dictionary to a YAML string.
Args: default_config (dict): Default configuration from the VFB tool.
Returns: str: YAML formatted string of the configuration.
reindex_df(df, start_time, end_time, freq)
Aligns two DataFrames on a new index based on a specified frequency, filling missing entries with the last known values.
Args: df (pd.DataFrame): Reference DataFrame used to determine the new index range. start_time (datetime): start of index end_time (datetime): end of index freq (str): Frequency string (e.g., '1T' for one minute) to define the interval of the new index.
Returns: pd.DataFrame: The df_to_align DataFrame reindexed to match the new timeline and filled with forward filled values.