Home

Awesome

PortfolioAllocation (Changelog)

npm Travis Build Status Feature Requests

PortfolioAllocation is a JavaScript library designed to help constructing financial portfolios made of several assets: bonds, commodities, cryptocurrencies, currencies, exchange traded funds (ETFs), mutual funds, stocks...

When constructing such portfolios, one of the main problems faced is to determine the proportion of the different assets to hold.

PortfolioAllocation solves this problem using mathematical optimization algorithms.

Do not hesitate to report any bug / request additional features !

Foreword / Project Status

I initially developed the PortfolioAllocation library to allow the optimization of financial portfolios within Google Sheets.

Unfortunately, I quickly noticed two issues:

For these reasons, I decided to stop developing the "vanilla" PortfolioAllocation library and replaced it with Portfolio Optimizer, a Web API to analyze and optimize financial portfolios.

As the integration of a Web API inside Google Sheets is much easier than the integration of a third party JavaScript library, this proved a wise choice.

TL;RD: If you need a software library to optimize financial portfolios within Google Sheets, please use the Portfolio Optimizer Web API.

Features

Usage

Usage in Google Sheets

Note: Examples of how to integrate PortfolioAllocation in Google Sheets are provided in this spreadsheet.

First, make the PortfolioAllocation functions available in your spreadsheet script:

Then, you can call these functions your preferred way in your spreadsheet script.

Here is an example through a wrapper function, to which spreadsheet data ranges (e.g. A1:B3) can be provided directly:

function computeERCPortfolioWeights(covarianceMatrix) {
  // Note: The input range coming from the spreadsheet is directly usable.
    
  // Compute the ERC portfolio weights
  var ercWeights = PortfolioAllocation.equalRiskContributionWeights(covarianceMatrix);
  
  // Return them to the spreadsheet
  return ercWeights;
}

Usage in a browser

Note: PortfolioAllocation is delivered through the CDN jsDelivr, at this URL.

Include PortfolioAllocation minified source file in an HTML page, and you are done:

<script src="https://cdn.jsdelivr.net/npm/portfolio-allocation/dist/portfolio_allocation.dist.min.js" type="text/javascript"></script>
<script type="text/javascript">
  var w = PortfolioAllocation.riskBudgetingWeights([[0.1,0], [0,0.2]], [0.25, 0.75]);
</script>

Usage with Node.js

Note: PortfolioAllocation is delivered as the npm package portfolio-allocation.

First, declare PortfolioAllocation as a dependency in your project's package.json file, using the package name portfolio-allocation.

Then, this is standard Node.js:

var PortfolioAllocation = require('portfolio-allocation');
var w = PortfolioAllocation.riskBudgetingWeights([[0.1,0], [0,0.2]], [0.25, 0.75]);

Included algorithms

Portfolio allocation and optimization algorithms

Misc. other algorithms

Documentation

The code is heavily documented, using JSDoc.

That being said, the documentation is rather for developer's usage, so that in case of trouble to use any algorithm, do not hesitate to ask for support !

Contributing

Fork the project from Github...

Install the Grunt dependencies and command line

npm install
npm install -g grunt-cli

Develop...

Compile and test

grunt deliver-dev
grunt deliver-dist
grunt deliver-gs

Submit a pull-request...

License

MIT License