okama.TimeSeriesStrategy

class TimeSeriesStrategy(parent)

Bases: CashFlow

Cash flow strategy with user-defined withdrawals and contributions.

Withdrawals, contributions, as well as their dates, are defined in the dictionary.

Parameters:
parentPortfolio

Parent Portfolio instance.

Examples

>>> import matplotlib.pyplot as plt
>>> pf = ok.Portfolio(first_date="2015-01", last_date="2024-10")  # create Portfolio with default parameters
>>> # create simple dictionary with cash flow amounts and dates
>>> d = {"2018-02": 2_000, "2024-03": -4_000}
>>> ts = ok.TimeSeriesStrategy(pf)  # create TimeSeresStrategy linked to the portfolio
>>> ts.time_series_dic = d  # use the dictionary to set cash flow
>>> ts.initial_investment = 1_000  # add initial investments size (optional)
>>> # Assign the strategy to Portfolio
>>> pf.dcf.cashflow_parameters = ts
>>> # Plot wealth index with cash flow
>>> pf.dcf.wealth_index.plot()
>>> plt.show()
../_images/okama-TimeSeriesStrategy-1.png

Methods & Attributes

NAME

frequency

The frequency of regualr withdrawals or contributions in the strategy.

initial_investment

Portfolio initial investment FV size (at last_date).

time_series_dic

Cash flow time series in form of dictionary.

property frequency

The frequency of regualr withdrawals or contributions in the strategy.

Allowed values for frequency:

  • ‘none’ no frequency (default value)

  • ‘year’ annual cash flows

  • ‘half-year’ 6 months cash flows

  • ‘quarter’ 3 months cash flows

  • ‘month’ 1 month cash flows

Returns:
str

The frequency of withdrawals or contributions.

property initial_investment

Portfolio initial investment FV size (at last_date).

Initial investment must be positive.

Returns:
float

Portfolio initial investment.

NAME = 'time_series'
property time_series_dic

Cash flow time series in form of dictionary.

Negative number corresponds to withdrawals, positive number corresponds to contributions.

Examples

>>> import matplotlib.pyplot as plt
>>> pf = ok.Portfolio(first_date="2015-01", last_date="2024-10")  # create Portfolio with default parameters
>>> # create simple dictionary with cash flow amounts and dates
>>> d = {"2018-02": 2_000, "2024-03": -4_000}
>>> ts = ok.TimeSeriesStrategy(pf)  # create TimeSeresStrategy linked to the portfolio
>>> ts.time_series_dic = d  # use the dictionary to set cash flow
>>> ts.initial_investment = 1_000  # add initial investments size (optional)
>>> # Assign the strategy to Portfolio
>>> pf.dcf.cashflow_parameters = ts
>>> # Plot wealth index with cash flow
>>> pf.dcf.wealth_index.plot()
>>> plt.show()
../_images/okama-TimeSeriesStrategy-2.png