Coder Social home page Coder Social logo

spopt's Introduction

SPOpt: A flexible and hyperpersonalizable Stochastic Portfolio Optimization framework for individual investing

SPOpt is a framework aimed at solving the portfolio problem for individual investors in the most flexible but accurate way possible. It is based on stochastic linear programming and can be combined with many different modelling frameworks. Its basic implementation is based on PyOMO.

Basic overview

The portfolio problem for the individual investor is, in a very simple sense, how to allocate his wealth accross different assets in order to maximize returns and minimize risk.

In order to solve this problem, SPOpt combines three building blocks.

Return Modelling

The first step to invest in different assets is to understand their return distribution. This modelling can be done through anything from a very simple but not very accurate Normal distribution to Hidden Markov Models to Bayesian Models to many other types of formulations.

All modelling methods must have a .fit() and .predict() methods, used to infer parameters on historical data and to create the new predictions that will be used for the Asset Allocation step.

All models are located in the returns module. Currently, the implemented return models are:

  • LogNormalReturns: It models the asset logreturns as a multivariate normal distribution. It is fited with price data and outputs price simulations.

CashFlow Modelling

A fundamental aspect of the portfolio problem for the individual investor is the cashflows of the individual. That is, the expected income and expenses the investor will have. By incorporating these cashflows the proposed solution portfolio can be an integral solution for the individual, taking into account its exact needs and opportunities.

All models are located in the cashflows module. Currently, the implemented cashflow models are:

  • ZeroCashFlows: More of a helper function than a true model, it just provides a constant cashflow of 0.

  • NormalCashFlows: Models cashflows through a Normal distribution. This is the most simple model although not a very accurate one as it completely ignores seasonal information, trends, etc.

Asset Allocation

In this final step the allocation accross different assets is determined. The allocation method is multiperiod stochastic linear programming formulation. It works by first simulating many different paths (potential future scenarios) with the previously specified models. Then the optimal decisions for all periods are chosen taking into account all these potential future scenarios. When using this in production, the first step is executed and in the next timestep the optimization is solved again with updated information, in a way similar to Model Predictive Control.

By using this formulation, many issues of traditional asset allocation methods can be overcome:

  • Discrete investments: Only discrete amounts of shares can be bought, and when the individual's capital is not very large this greatly affects what assets can be bought and the real performance of the portfolio.
  • Trading fees: Through the multiperiod formulation trading fees are taken into account.
  • Arbitrary constraints: Many constraints on asset types, diversification, cash amounts, etc. can be included.
  • Personalizable objective function: By including the CVaR and Expectation a very comprehensive and realistic objective can be formulated.

All models are located in the optimization module. Currently, the implemented optimization models are:

  • om_discrete: In this model there are multiple assets for which the price evolution in each scenario is provided. Trading decisions as shares bought/sold are optimized for each period. Trading fees are included percentagewise on each buy/sell trade. Cash must be non negative for all scenarios. The objective funciton is the expected final wealth. This model does not allow margin or short investing, nor does it include a return for cash.
  • om_discrete_cvar: Equal to the previous model, but the objective function is a linear combination between the expected total final wealth and the CVaR on the total final wealth.
  • om_discrete_cvar_negativecash: Equal to the previous model, but it allows a certain percentage of scenarios to have cash below a certain threshold, including negative cash.

Any and all proposals and contributions are welcome!

spopt's People

Contributors

fcelya avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.