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:
  • 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

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)