portfolio_toolkit.utils package

Subpackages

Submodules

portfolio_toolkit.utils.correlation module

portfolio_toolkit.utils.correlation.calculate_correlation(returns1, returns2)[fuente]

Calculates the correlation between two return series.

Parámetros:
  • returns1 (pd.Series) – The first return series.

  • returns2 (pd.Series) – The second return series.

Devuelve:

The correlation between the two return series.

Tipo del valor devuelto:

float

portfolio_toolkit.utils.log_returns module

portfolio_toolkit.utils.log_returns.calculate_log_returns(price_series)[fuente]

Calculates the logarithmic returns of a price series.

Parámetros:

price_series (pd.Series) – Series of prices.

Devuelve:

Series of logarithmic returns.

Tipo del valor devuelto:

pd.Series

Module contents

portfolio_toolkit.utils.get_last_periods(n=4, period_type='weeks', include_current=False) List[Period][fuente]

Returns the last n periods as Period objects.

Parámetros:
  • n (int) – Number of periods to return

  • period_type (str) – Type of period (“years”, “quarters”, “months”, “weeks”)

  • include_current (bool) – Whether to include the current period

Devuelve:

List of Period objects representing each period

Tipo del valor devuelto:

List[Period]

Ejemplo

# Get last 3 completed weeks get_last_periods(3, “weeks”, include_current=False)

# Get last 2 weeks + current week get_last_periods(2, “weeks”, include_current=True)

portfolio_toolkit.utils.get_current_period(period_type: str) Period[fuente]

Returns the current period as a Period object based on the specified type.

Parámetros:

period_type (str) – Type of period (“year”, “quarter”, “month”, “week”)

Devuelve:

Period object representing the current period

Tipo del valor devuelto:

Period

Muestra:

ValueError – If period_type is not supported

Ejemplo

current_week = get_current_period(“week”) current_quarter = get_current_period(“quarter”) current_year = get_current_period(“year”)

class portfolio_toolkit.utils.Period(label: str, start_date: date, end_date: date)[fuente]

Bases: object

Represents a time period with a label and start/end dates.

label

Human-readable name for the period (e.g., «Q3 2025», «July 2025»)

Type:

str

start_date

Start date of the period

Type:

date

end_date

End date of the period

Type:

date

Ejemplo

quarter = Period(«Q3 2025», date(2025, 7, 1), date(2025, 9, 30)) month = Period(«July 2025», date(2025, 7, 1), date(2025, 7, 31))

__init__(label: str, start_date: date, end_date: date) None
__post_init__()[fuente]

Validate that end_date is not before start_date.

__str__() str[fuente]

String representation of the period.

label: str
start_date: date
end_date: date