portfolio_toolkit.utils.period package
Submodules
portfolio_toolkit.utils.period.get_current_month module
- portfolio_toolkit.utils.period.get_current_month.get_current_month() Period [source]
Returns information about the current month as a Period object.
- Returns:
Period object representing the current month
- Return type:
Example
For July 27, 2025: Period(“July 2025”, date(2025, 7, 1), date(2025, 7, 31))
portfolio_toolkit.utils.period.get_current_period module
- portfolio_toolkit.utils.period.get_current_period.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’)
portfolio_toolkit.utils.period.get_current_quarter module
- portfolio_toolkit.utils.period.get_current_quarter.get_current_quarter() Period [source]
Returns information about the current financial quarter as a Period object.
- Returns:
Period object representing the current quarter
- Return type:
Example
For July 27, 2025: Period(“Q3 2025”, date(2025, 7, 1), date(2025, 9, 30))
portfolio_toolkit.utils.period.get_current_week module
- portfolio_toolkit.utils.period.get_current_week.get_current_week() Period [source]
Returns information about the current ISO week as a Period object.
- Returns:
Period object representing the current ISO week
- Return type:
Example
For July 27, 2025 (which is in ISO week 30): Period(“W30 2025”, date(2025, 7, 21), date(2025, 7, 27))
portfolio_toolkit.utils.period.get_current_year module
portfolio_toolkit.utils.period.get_last_months module
- portfolio_toolkit.utils.period.get_last_months.get_last_months(n=4) List[Period] [source]
Returns the last n completed months as Period objects (excluding current month).
For n=4 in July 2025, returns: [Period(“March 2025”, date(2025, 3, 1), date(2025, 3, 31)),
Period(“April 2025”, date(2025, 4, 1), date(2025, 4, 30)), Period(“May 2025”, date(2025, 5, 1), date(2025, 5, 31)), Period(“June 2025”, date(2025, 6, 1), date(2025, 6, 30))]
portfolio_toolkit.utils.period.get_last_periods module
- portfolio_toolkit.utils.period.get_last_periods.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.period.get_last_quarters module
- portfolio_toolkit.utils.period.get_last_quarters.get_last_quarters(n=4) List[Period] [source]
Returns the last n completed quarters as Period objects (excluding current quarter).
Financial quarters: Q1 (Jan-Mar), Q2 (Apr-Jun), Q3 (Jul-Sep), Q4 (Oct-Dec)
For n=4 in Q3 2025, returns: [Period(“Q3 2024”, date(2024, 7, 1), date(2024, 9, 30)),
Period(“Q4 2024”, date(2024, 10, 1), date(2024, 12, 31)), Period(“Q1 2025”, date(2025, 1, 1), date(2025, 3, 31)), Period(“Q2 2025”, date(2025, 4, 1), date(2025, 6, 30))]
portfolio_toolkit.utils.period.get_last_weeks module
- portfolio_toolkit.utils.period.get_last_weeks.get_last_weeks(n=4) List[Period] [source]
Returns the last n completed weeks as Period objects (excluding current week).
For n=4 in week 30 of 2025, returns: [Period(“W26 2025”, date(2025, 6, 23), date(2025, 6, 29)),
Period(“W27 2025”, date(2025, 6, 30), date(2025, 7, 6)), Period(“W28 2025”, date(2025, 7, 7), date(2025, 7, 13)), Period(“W29 2025”, date(2025, 7, 14), date(2025, 7, 20))]
portfolio_toolkit.utils.period.get_last_years module
- portfolio_toolkit.utils.period.get_last_years.get_last_years(n=4) List[Period] [source]
Returns the last n years as Period objects.
For n=4 in year 2025, returns: [Period(“2022”, date(2022, 1, 1), date(2022, 12, 31)),
Period(“2023”, date(2023, 1, 1), date(2023, 12, 31)), Period(“2024”, date(2024, 1, 1), date(2024, 12, 31)), Period(“2025”, date(2025, 1, 1), date(2025, 12, 31))]
portfolio_toolkit.utils.period.period module
- class portfolio_toolkit.utils.period.period.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))
Module contents
- portfolio_toolkit.utils.period.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’)
- portfolio_toolkit.utils.period.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)
- class portfolio_toolkit.utils.period.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))