portfolio_toolkit.utils package
Subpackages
- portfolio_toolkit.utils.period package
- Submodules
- portfolio_toolkit.utils.period.get_current_month module
- portfolio_toolkit.utils.period.get_current_period module
- portfolio_toolkit.utils.period.get_current_quarter module
- portfolio_toolkit.utils.period.get_current_week module
- portfolio_toolkit.utils.period.get_current_year module
- portfolio_toolkit.utils.period.get_last_months module
- portfolio_toolkit.utils.period.get_last_periods module
- portfolio_toolkit.utils.period.get_last_quarters module
- portfolio_toolkit.utils.period.get_last_weeks module
- portfolio_toolkit.utils.period.get_last_years module
- portfolio_toolkit.utils.period.period module
- Module contents
Submodules
portfolio_toolkit.utils.correlation module
- portfolio_toolkit.utils.correlation.calculate_correlation(returns1, returns2)[source]
Calculates the correlation between two return series.
- Parameters:
returns1 (pd.Series) – The first return series.
returns2 (pd.Series) – The second return series.
- Returns:
The correlation between the two return series.
- Return type:
portfolio_toolkit.utils.log_returns module
Module contents
- portfolio_toolkit.utils.get_last_periods(n=4, period_type='weeks', include_current=False) List[Period] [source]
Returns the last n periods as Period objects.
- Parameters:
- Returns:
List of Period objects representing each period
- Return type:
List[Period]
Example
# 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 [source]
Returns the current period as a Period object based on the specified type.
- Parameters:
period_type (str) – Type of period (‘year’, ‘quarter’, ‘month’, ‘week’)
- Returns:
Period object representing the current period
- Return type:
- Raises:
ValueError – If period_type is not supported
Example
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)[source]
Bases:
object
Represents a time period with a label and start/end dates.
- start_date
Start date of the period
- Type:
date
- end_date
End date of the period
- Type:
date
Example
quarter = Period(“Q3 2025”, date(2025, 7, 1), date(2025, 9, 30)) month = Period(“July 2025”, date(2025, 7, 1), date(2025, 7, 31))