marketflows.analysis.metrics
Metric calculations for analysis.
Computes normalized series (by base asset and first valid record), optional EMAs, derivatives (growth/inflection), optional smoothing, and optional unit scaling.
Functions
|
Calculate metrics for groups of or single assets. |
|
Calculate metrics for market cap ranges. |
- marketflows.analysis.metrics.calculate_group_metrics(*, base_assets, df_base=None, df_groups, analysis_config)
Calculate metrics for groups of or single assets.
Given a dataframe of assets or groups of assets, normalize with base currency, normalize with time, calculate EMAs, calculate derivatives, and smooth with EMA (10 by default). The original data is normalized with the base assets. The derivatives are not normalized with the base assets.
- Parameters:
base_assets (
list[str]) – list of assets that will be used as base currency (us-dollar is default since all data points are in terms of USD)df_groups (
DataFrame) – dataframe with the groups or individual assets for which we are calculating metricsdf_base (
DataFrame|None, default:None) – dataframe with all base token dataanalysis_config (
AnalysisConfig) – configuration parameters for analysis module
- Return type:
DataFrame- Returns:
dataframe with all columns necessary for plotting
- Raises:
ValueError – if base_assets are not in df_base
TypeError – if diff_orders are not all integers
- marketflows.analysis.metrics.calculate_range_metrics(*, df_master=None, df_ranges, df_long=None, provider_config, analysis_config)
Calculate metrics for market cap ranges.
Given a dataframe of market cap ranges (each range is specified by its lower limit e.g. df_ranges.columns = [1e9, 1e10, 1e11]), normalize with base currency, normalize with time, calculate up to 2nd derivative, and smooth with EMAs. The data (original, 1st derivative, or 2nd derivative) is normalized with the original data for each base asset.
- Parameters:
df_master (
DataFrame|None, default:None) – dataframe with all individual asset datadf_ranges (
DataFrame) – dataframe with the market cap ranges for which we are calculating metricsdf_long (
DataFrame|None, default:None) – market caps for all the assets with one master datetime index organized into blocks of one asset after anotherprovider_config (
ProviderConfig) – configuration parameters for provider moduleanalysis_config (
AnalysisConfig) – configuration parameters for analysis module
- Return type:
DataFrame- Returns:
dataframe with all columns necessary for plotting
Notes
If the first valid time is not a valid time for a column (this can happen when the valid records do not coincide for the base asset and the asset, causing a mostly missing record column), the first valid time for that column is used instead of the first valid time for all columns