Utilities#
- class portfolio_plan.utils.plot_lines(data: Series, scale_x: bool = True, periods: List[Period] | None = None, variant: Literal['main', 'moon', 'dawn'] = 'dawn')#
Bases:
- Parameters:
data (pd.Series) – Data in long form, with multiindex, first level “symbol”, second level “date”.
scale_x (bool) – Whether to include a date scale on the x axis For data which has uneven frequency, it is recommend to set to False and define the scale manually. Defaults to True
periods (List[Period] | None) – If a list of Period is provided, transparent rectangle will be drawn on each period.start, period.end Defaults to None
variant (Literal["main", "moon", "dawn"]) – Refer to
portfolio_plan.visualisation.theme_rose_pine
- class portfolio_plan.utils.plot_prices(data: Series, scale_x: bool = True)#
Bases:
A wrapper for
plot_lines()
- class portfolio_plan.utils.plot_returns(data: Series, scale_x: bool = True)#
Bases:
A wrapper for
plot_lines(), adds a facet layer. Each symbol is facetted in order to improve readability of the chart.
- class portfolio_plan.utils.plot_cumulative_returns(data: Series, scale_x: bool = True, periods=typing.Optional[typing.List[portfolio_plan.utils.Period]])#
Bases:
A wrapper for
plot_lines()
- class portfolio_plan.utils.plot_allocation(weights: Weights, variant: Literal['main', 'moon', 'dawn'] = 'dawn', base_size: int = 11)#
Bases:
Plot a single allocation.
- Parameters:
weights (Weights) – A dictionary representing the allocation of weights.
variant (Literal["main", "moon", "dawn"]) – The color variant to use for the plot.
- Returns:
A ggplot object representing the allocation.
- Return type:
ggplot
from portfolio_plan.utils import plot_allocation, plot_allocations, Period
from portfolio_plan import Weights
weights = Weights(A=0.2, B=0.8)
p = plot_allocation(weights)
from datetime import datetime
weights_list = [
Weights(A=0.4, B=0.3, C=0.3),
Weights(A=0.5, B= 0.2, C=0.3),
]
periods = [
Period(
start=datetime(2025, 1, 1),
end=datetime(2025, 6, 30),
frequency=None,
),
Period(
start=datetime(2025, 7, 1),
end=datetime(2025, 12, 31),
frequency=None
),
]
plot = plot_allocations(weights_list, periods, variant="dawn")
plot