Recent Releases of https://github.com/mbk-dev/okama

https://github.com/mbk-dev/okama - Okama 1.5.0

Rebalancing bands - new rebalancing strategies for investment portfolios.

  • Calendar-based rebalancing
  • Rebalancing bands (threshold-based)

Mean-variance optimization with rebalancing-strategy-adjusted Efficient Frontier and asset weight bounds.

rebalancing

New features

Rebalance - new class to define rebalancing strategies

Rebalancing strategies are now defined in both Portfolio and EfficientFrontierReb with Rebalance class. python rs = ok.Rebalance(period="year", abs_deviation=0.10, rel_deviation=0.30) pf = ok.Portfolio(['SPY.US', 'AGG.US'], rebalancing_strategy=rs) WARNING: The previous Portfolio class initialization method is now deprecated. ok.Portfolio(rebalancing_period="year") will not work anymore. However, as the default rebalancing strategy is monthly calendar-based. The simple definition without rebalancing strategy is still working: python ok.Portfolio(['SPY.US', 'AGG.US'], weights=[.6, .4])

Rebalance class

  • New Rebalance class has 3 parameters: period, absdeviation, reldeviation
  • Rebalance.wealth_ts() calculates wealth index time series of rebalanced portfolio (optionally with assets wealth time series)
  • Rebalance.assets_weights_ts() calculates assets weights monthly time series for rebalanced portfolio
  • Rebalance.return_ror_ts() returns monthly rate of return time series of rebalanced portfolio

New methods and properties in Portfolio class

  • new property rebalancing_strategy to configure rebalancing period, absolute and relative deviations
  • new property rebalancing_events returns time series of rebalancing events and type of rebalancing

Changes in PortoflioDCF class

  • PortfolioDCF.monte_carlo_wealth_pv calculates discounted random wealth indexes with cash flows
  • PortfolioDCF.monte_carlo_wealth_fv calculates not discounted (nominal) random wealth indexes with cash flows
  • PortfolioDCF.find_the_largest_withdrawals_size() now uses bisection method to find the largest withdrawals size.
  • PortfolioDCF.find_the_largest_withdrawals_size() has 3 possible goals: 'maintainbalancepv', 'maintainbalancefv' and 'survival_period'
  • PortfolioDCF.find_the_largest_withdrawals_size() new attribute withdrawals_range defines the possible range for withdrawals to speed up the calculations
  • PortfolioDCF.find_the_largest_withdrawals_size() has iter_max attribute to limit the intermediate steps when searching for resolution
  • PortfolioDCF.find_the_largest_withdrawals_size() returns Result class. If the solutions is not found it is still possible to see the intermediate steps

New methods and properties in EfficienFrontierReb class

EfficienFrontierReb class now uses rebalancing_strategy parameter for initialization (the same as Portfolio). It supports bounds to define the weight limitations for the assets.

  • new rebalancing_strategy parameter to define the rebalancing strategy
  • new bounds parameter defines the bounds for the assets weights
  • new EfficienFrontierReb.plot_pair_ef() method plots the Efficient Frontier of every pair of assets

Changes in EfficientFrontier class

  • EfficientFrontier.get_monte_carlo method generates random rebalanced portfolios with Monte Carlo simulation according to bounds limitations.

New Jupyter Notebook with examples for Rebalancing strategies

New Jupyter Notebook with examples of investment portfolios with different rebalancing strategies: 10 rebalancing portfolio.ipynb

- Jupyter Notebook
Published by chilango74 8 months ago

https://github.com/mbk-dev/okama - Okama 1.4.4

New examples for investment portfolios with cash flow in 04 investment portfolios with DCF.ipynb.

Several bugs in Portfolio and PortfolioDCF are fixed.

Fixed:

  • Portfolio.dcf.initial_investment_pv must return None if cash flow parameters are not defined
  • add use_discounted_values parameter to helpers.Frame.get_wealth_indexes_with_cashflow
  • use self.use_discounted_values = False in plot_forecast_monte_carlo for any value of backtest parameter
  • clean up Portfolio dat cache if symbol changed

- Jupyter Notebook
Published by chilango74 over 1 year ago

https://github.com/mbk-dev/okama - Okama 1.4.3

Okama 1.4.3 is dedicated to Cash Flow strategies and Monte Carlos simulations.

New features

3 new classes to set up Cash Flow strategies

Cash flow parameters for investment portfolios are now configured in the corresponding classes.

  • IndexationStrategy for strategies with regular indexed withdrawals / contributions
  • PercentageStrategy for strategies weith regualr fixed percentage withdrawals / contributions
  • TimeSeriesStrategy for strategies with user-defined withdrawals and contributions. Withdrawals, contributions, as well as their dates, are defined in the dictionary.

All 3 classes are inhereted from parent class CashFlow. Portfolio class does not have cash flow parameters (initial_amount, cashflow, discount_rate) anymore.

New class to set up Monte Carlo simulation parameters

MonteCarlos class has several properties:

  • distribution - the type of a distribution to generate random rate of return
  • period - forecast period in years for portfolio wealth index time series
  • number - number of random wealth indexes to generate with Monte Carlo simulation

All Monte Carlos properties are linked to PortfolioDCF instance and can be accessed by Portfolio().dcf.mc construction. For example the type of random distribution is available through Portfolio().dcf.mc.disctribution.

New methods and properties in PortfolioDCF

PortfolioDCF has a new parameter use_discounted_values (default is False). Id defines whether to use discounted values in backtesting wealth indexes (initial investments, withdrawal or contribution size). discount_rate parameter is shifted from Portfolio to PortfolioDCF.

  • find_the_largest_withdrawals_size - find the largest withdrawals size for Monte Carlo simulation according to Cashflow Strategy. This method works with IndexationStrategy and PercentageStrategy
  • initial_investment_fv property to calculate the future value (FV) of the initial investments at the end of forecast period.
  • initial_investment_pv property to calculate the discounted value (PV) of the initial investments at the historical first date
  • wealth_index_with_assets works as the same property of Portfolio but considers cash flow (contributions and withdrawals)
  • set_mc_parameters method is a shortcut to add Monte Carlo simulation parameters

Changes in methods and properties in PortfolioDCF

  • monte_carlo_survival_period, survival_date_hist and survival_period_hist methods have now new parameter threshold. The threshold defines the percentage of the initial investments when the portfolio balance considered voided
  • plot_forecast_monte_carlo number of parameters is reduced to: backtest and figsize

- Jupyter Notebook
Published by chilango74 over 1 year ago

https://github.com/mbk-dev/okama - Okama 1.4.1

Okama 1.4.1 adds custom exceptions for time period and Student's t distribution for Monte-Carlo methods in Portfolio and AssetList.

New features

Custom exceptions for time periods issues

  • ShortPeriodLengthError is raised when an asset has less then 3 months of history in AssetList, Portfolio and EfficentFrontier classes
  • RollingWindowLengthBelowOneYearError is raised when rolling windows size is below one year
  • LongRollingWindowLengthError is raised when rolling window size is more than data history depth

Student's t distribution in Monte-Carlo methods

  • set distr="t" in methods like Portfolio.dcf.monte_carlo_wealth or AssetList.kstest

Changes in existing methods & properties

  • Portfolio.dcf.monte_carlo_wealth uses initial_amount value by default.

Bugs fixed

  • wrong formula for 0 period rate of return in helpers.Rebalance.return_ror_ts

- Jupyter Notebook
Published by chilango74 over 1 year ago

https://github.com/mbk-dev/okama - Okama 1.4.0

Okama 1.4.0 introduces investment strategies with contributions and withdrawals in Portfolio class. New methods support discounted cash flows (DCF) and Monte Carlo simulation for portfolio longevity.

New features

DCF methods for contributions and withdrawals in Portfolio class

New Portfolio class attributes (all are optional): - initial_amount - Portfolio initial investment FV (at lastdate) - cashflow - portfolio monthly cash flow FV (at lastdate). Negative value corresponds to withdrawals. Positive value corresponds to contributions. Cash flow value is indexed each month by inflation. - discount_rate - cash flow discount rate required to calculate PV values.

New dcf. methods in Portfolio class: - dcf.plot_forecast_monte_carlo() method to plot Monte Carlo simulation for portfolio future wealth indexes optionally together with historical wealth index. - dcf.monte_carlo_survival_period() method to generate a survival period distribution for a portfolio with cash flows by Monte Carlo simulation. - dcf.wealth_index property to calculate wealth index time series for the portfolio with contributions and withdrawals. - dcf.survival_period property to calculate the period when the portfolio has positive balance considering withdrawals on the historical data. - dcf.survival_date property to get the date when the portfolio balance become negative considering withdrawals on the historical data. - dcf.cashflow_pv property to calculate the discounted value (PV) of the cash flow amount at the historical first_date. - dcf.initial_amount_pv property to calculate the discounted value (PV) of the initial investments at the historical first_date.

New properties in Portfolio class

  • assets_dividend_yield property to calculate last twelve months (LTM) dividend yield time series (monthly) for each asset
  • dividends_annual property to get calendar year dividends sum time series for each asset.

New methods and properties in AssetList class

  • get_rolling_risk_annual() method to calculate annualized risk rolling time series for each asset.
  • get_dividend_mean_yield() method to calculate the arithmetic mean for annual dividend yield over a specified period.
  • dividend_yield_annual property to calculate last twelve months (LTM) dividend yield annual time series.

Changes in existing methods & properties

  • Asset_List.risk_annual returns expanding risk time series (not float)
  • Portfolio.recovery_period returns time series of recovery periods over historical data (not a single period)
  • describe() method shows the rate of return arithmetic mean (expected return) in Portfolio, AssetList classes
  • new xy_text argument in plot_assets() method to position better point labels in Portofolio, AssetList classes

New Jupyter Notebooks with examples

Bugs fixed

  • Duplicate tickers in the assets are no longer allowed and are automatically corrected (AssetList, Portfolio, EfficientFrontier, EfficientFrontierReb)

- Jupyter Notebook
Published by chilango74 almost 2 years ago

https://github.com/mbk-dev/okama - Okama 1.3.2

Okama now supports Panadas 2.0.0 and further versions. There is no backward compatibility with previous Pandas versions.

New features:

  • New rebalancing periods for portfolios: "half-year" and "quarter"
  • new set_values_monthly() method in Inflation to forecast data and change previos values
  • new dividend_yield_annual property in AssetList calculates dividend yield time series for calendar years
  • new get_dividend_mean_yield() method in AssetList shows mean dividend yield for a given period
  • plot_cml() has new y_axe parameter to switch from CAGR to mean rate of returns in the plots
  • asset_dividend_yield property renamed to dividend_yield in AssetList

- Jupyter Notebook
Published by chilango74 about 2 years ago

https://github.com/mbk-dev/okama - Okama 1.3.1

okama works with Python 3.11 now.

FIX:

  • aliases symbols_in_namespace and no_dividends_namespaces were not imported in __init__.py

- Jupyter Notebook
Published by chilango74 almost 3 years ago

https://github.com/mbk-dev/okama - Okama 1.3.0

New features:

  • rollingwindow parameter in AssetList functions: `indexcorr(),indexbeta(),trackingerror()`
  • index_corr() and index_rolling_corr() are combined into a single function index_corr() in the AssetList
  • AssetList, Prtfolio, EfficentFrontier and EfficentFrontierReb are now sequences and has __getitem__, __iter__ methods.

Fix:

  • Avoid running get_namspaces() and other aliases in init.py (this resulted in the database requests during library import)
  • EfficientFrontier.plot_pair_ef() faled if inflation=False
  • Tickers with dot "." like BRK.B

- Jupyter Notebook
Published by chilango74 almost 3 years ago

https://github.com/mbk-dev/okama - Okama 1.2.3

The release uses runtime Python 3.8. This version is recomended for development. Previous versions of okama were using legacy Python 3.7.

New features:

  • EfficentFrontier().get_monte_carlo() method return risk, return and weights data for random portfolios.

Fix:

  • Columns order is lost in Portfolio().weights_ts
  • minor bugs

- Jupyter Notebook
Published by chilango74 over 3 years ago

https://github.com/mbk-dev/okama - Okama 1.2.2 (the last Python 3.7 compatible version)

Version 1.2.2 will be the last Python 3.7 release. In further development we will use Python 3.8.

Updated:

  • Update classes for new FOREX data format (AssetList, Portfolio and all ListMaker inherited classes are affected)

Fixed:

  • compatible issues with importlib-metadata package

- Jupyter Notebook
Published by chilango74 over 3 years ago

https://github.com/mbk-dev/okama - Okama 1.2.1

New features:

  • get_tangency_portfolio() can calculate tangency portfolio weights for CAGR (rate of return with geometric mean).

Fix:

  • base currency first_date and last_date were calculated wrong in AssetList, Portfolio and EfficientFrontier

- Jupyter Notebook
Published by chilango74 over 3 years ago

https://github.com/mbk-dev/okama - Okama 1.2.0

New Macroeconomic class Indicator

3 macroeconomic classes are available (and Documented):

  • Indicator : Macroeconomic indicators and ratios. (.RATIO NEW namespace)
  • Inflation : Inflation related data and methods (.INFL namespace)
  • Rates : Rates of central banks and banks (.RATE namesapce)

Cyclically adjusted price-to-earnings ratios (CAPE10) for 20+ countries are in the DataBase: USACAPE10.RATIO, CHNCAPE10.RATIO, CHN_CAPE10.RATIO etc.

Daily value time series for Macro classes

Rate class has .values_daily property which can be used with bak raters and some other symbols: ok.Rate("RUONIA.RATE").values_daily all Macro classes have .values_monthly property.

.describe() methods in all macroeconomic classes

.describe() methods show descriptive statistics for YTD and given periods:

  • arithmetic mean
  • median
  • max and min values

Inflation class .describe() method is different. It generates inflation-specific statistics:

  • YTD compound inflation
  • Annual inflation (geometric mean) for a given list of periods
  • max 12 months inflation for the periods
  • Annual inflation (geometric mean) for the whole history

Rolling tracking difference for stock indexes and ETFs

.tracking_difference() and tracking_difference_annualized() in AssetList class are now methods (where properties). Methods have rolling_window attribute to set wolling window size (in months). To calclulate 24 months movig tracking difference: x.tracking_difference(rolling_window=24)

Full Changelog: https://github.com/mbk-dev/okama/compare/v1.1.6...v1.2.0

- Jupyter Notebook
Published by chilango74 over 3 years ago

https://github.com/mbk-dev/okama - Okama 1.1.6

Introduce parallel computing for heavy calculations in multi-period portfolio optimization (Efficient Frontier).

Minor changes:

  • okama uses black for code formatting
  • development dependencies use Python 3.7 to stay compatible with Google Colab

- Jupyter Notebook
Published by chilango74 almost 4 years ago

https://github.com/mbk-dev/okama - Okama 1.1.5

Use new financial API (api.okama.io) for historical data requests.

- Jupyter Notebook
Published by chilango74 almost 4 years ago

https://github.com/mbk-dev/okama - Okama 1.1.4

Replace deprecated .append with .concat for new versions of panda package.

- Jupyter Notebook
Published by chilango74 almost 4 years ago

https://github.com/mbk-dev/okama - Okama 1.1.3

Add poetry as a dependency manager.

- Jupyter Notebook
Published by chilango74 almost 4 years ago

https://github.com/mbk-dev/okama - Okama 1.1.2

Sortino ratio and Diversification ratios:

  • get_sortiono_ratio() method is available in AssetList and Portfolio
  • diversification_ratio property is added to Portfolio
  • get_most_diversified_portfolio() method is added to EfficientFrontier
  • mdp_points property is added to EfficientFrontier

mdp_points is a DataFrame with the Most diversified portfolios points.

More examples in Jupyter Notebooks:

  • 08 financial database.ipynb has financial database queries examples

- Jupyter Notebook
Published by chilango74 about 4 years ago

https://github.com/mbk-dev/okama - Okama 1.1.1

New method in AssetList:

Fixed:

  • if the asset historical data period is too short there is an ValuError in initialization

Full Changelog: https://github.com/mbk-dev/okama/compare/v1.1.0...v1.1.1

- Jupyter Notebook
Published by chilango74 about 4 years ago

https://github.com/mbk-dev/okama - Okama 1.1.0

Sharpe Ratio, Tangency portfolio and Capital Market Line (CML): - .get_sharpe_ratio() method is available in Portfolio and AssetList - .get_tangency_portfolio() method in EfficientFrontier to optimize allocation with Sharpe Ratio as objective function - .plot_cml() method in EfficientFrontier to plot the Capital Market Line (CML) and Maximum Sharpe Ratio (MSR) point with the Efficient Frontier

Refactoring: - .plot_assets() method is at ListMaker abstract class and is available from: AssetList, Portfolio, EfficientFrontier and EfficientFrontierReb - .plot_pair_ef() method is at EfficientFrontier - .plot_transition_map() is at EfficientFrontier - Plots class discontinued

- Jupyter Notebook
Published by chilango74 over 4 years ago

https://github.com/mbk-dev/okama - Okama 1.0.2

Database Search improvements:

  • ok.search() accepts namespace as an argument
  • ok.search() and ok.symbols_in_namespace() return DataFrame (default) or json. It can be changed with response_format argument ('frame' or 'json')

Bugs fixed:

  • limit .inflation_ts by 'firstdate' and 'lastdate' in Portfolio and AssetList
  • np.nan and np.inf are replaced with 0 in AssetList.get_dividend_mean_grow()

- Jupyter Notebook
Published by chilango74 over 4 years ago

https://github.com/mbk-dev/okama - Okama 1.0.1

Documentation added for all methods and attributes in Assets, AssetList and Portfolio.

- Jupyter Notebook
Published by chilango74 over 4 years ago

https://github.com/mbk-dev/okama - Okama 1.0.0

Several important updates in Portfolio and AssetList classes: - Portfolio is an asset (like stocks, ETF or commodities) and can be included in the AssetList - Portfolio has a symbol (.PF namespace) - Rebalancing period is an attribute of Portfolio - Asset has .close and .adj_close properties (close time series) - Dividend time series are adjusted to the base currency in Portfolio and AssetList - .dividend_yield for Portfolio is a weighted sum of the assets dividend yields (adjusted to the base currency) - Portfolio has .dividends method (dividends history time series) - New notebook in examples for investment portfolios (examples/03 investment portfolios.ipynb)

- Jupyter Notebook
Published by chilango74 over 4 years ago

https://github.com/mbk-dev/okama - Okama 0.99

Several improvements to Portoflio and AssetList classes: - get_return_ts has rebalancingperiod parameter - `getrebalancedportfolioreturntsmethod in Portfolio is depreciated -getrollingcagrandgetrollingcumulativereturncould usereal=Trueoption to calculate real return values -getcagrandcumulativereturnhavereal` option - Several new docstrings in Portfolio and AssetLists classes

Project RoadMap and Contributing guidelines are added to GitHub repository.

- Jupyter Notebook
Published by chilango74 almost 5 years ago

https://github.com/mbk-dev/okama - Bugs fixed

Several bugs are fixed. New methods in Portfolio class: - getcagr (instead of cagr property) - getcumulativereturn - getrollingcumulativereturn

- Jupyter Notebook
Published by chilango74 almost 5 years ago

https://github.com/mbk-dev/okama - Fix setup.py building

setuptools builds correctly the package after updating setup.py.

- Jupyter Notebook
Published by chilango74 about 5 years ago

https://github.com/mbk-dev/okama - Fix the build in PyPi

- Jupyter Notebook
Published by chilango74 about 5 years ago

https://github.com/mbk-dev/okama - Portfolio class improvements

  • Portfolio .cagr property is replaced with .get_cagr() method taking: 'YTD', period length or no parameters.
  • Portfolio .describe shows dividend yield

minor changes: - EfficientFrontier.repr is fixed - only relative imports in the package - tests modules import okama as ok - several unit tests added

- Jupyter Notebook
Published by chilango74 about 5 years ago

https://github.com/mbk-dev/okama - Bugs fixed

  • get_cagr() works correctly in AssetList class
  • EffiecientFrontier was not awailable through init.py

- Jupyter Notebook
Published by chilango74 about 5 years ago

https://github.com/mbk-dev/okama - symbols_in_namespace() method

symbolsinnamespace() function added. It allows to get all available symbols from a namespace.

- Jupyter Notebook
Published by chilango74 about 5 years ago

https://github.com/mbk-dev/okama - Refactor & Bugs fix

  • currency 'curr' parameter is renamed to 'ccy' in AssetList and Portolio
  • namespaces information is obtained from API
  • New Jupyter notebook for multi-period Efficient Frontier
  • Bugs fixed in AssetList dividend_yield and Portfolio describe methods
  • code refactoring according Anton Pak suggestions

- Jupyter Notebook
Published by chilango74 about 5 years ago

https://github.com/mbk-dev/okama - get_monte_carlo method in EfficientFrontier

  • new getmontecarlo method in Efficient Frontier class
  • CAGR is calculated in Efficient Frontier / plot_assets instead of "CAGR by approximation"

- Jupyter Notebook
Published by chilango74 about 5 years ago

https://github.com/mbk-dev/okama - New methods to work with distributions

Kolmogorov-Smirnov test method (kstest) for Portfolio and AssetList.

New forecasting methods for Portfolio: - percentileinverse - percentilefromhistory - forecastwealthhistory - forecastmontecarlocagr - forecast_wealth

Some of the old forecasting methods are renamed.

New Plotting methods for forecasts in Portfolio: - plotforecast - plotforecastmontecarlo - plotplothistfit - plotpercentiles_fit

New notebooks with examples: 04 backtesting distribution.ipynb 05 forecasting.ipynb

- Jupyter Notebook
Published by chilango74 about 5 years ago

https://github.com/mbk-dev/okama - distribution backtesting

New methods for distribution backtesting in AssetList and Portfolio: - skewness - skewnessrolling - kurtosis - kurtsisroling - jarque_bera

- Jupyter Notebook
Published by chilango74 about 5 years ago

https://github.com/mbk-dev/okama - Index fund methods

New methods to compare ETFs with index (benchmarks) in AssetList: - tracking difference - tracking difference annualized - tracking error - index correlation - index rolling correlation - index beta

- Jupyter Notebook
Published by chilango74 about 5 years ago

https://github.com/mbk-dev/okama - technical release

- Jupyter Notebook
Published by chilango74 over 5 years ago

https://github.com/mbk-dev/okama - technical release

- Jupyter Notebook
Published by chilango74 over 5 years ago

https://github.com/mbk-dev/okama - numpy<=1.19.3

- Jupyter Notebook
Published by chilango74 over 5 years ago

https://github.com/mbk-dev/okama - verbose mode for EfficientFrontierReb

- Jupyter Notebook
Published by chilango74 over 5 years ago

https://github.com/mbk-dev/okama - updated requirements

- Jupyter Notebook
Published by chilango74 over 5 years ago

https://github.com/mbk-dev/okama - stable version

- Jupyter Notebook
Published by chilango74 over 5 years ago

https://github.com/mbk-dev/okama - First public version

- Jupyter Notebook
Published by chilango74 over 5 years ago