A command-line tool to backtest possible asset allocations in an investment portfolio given historical data sample with periodic (e.g. yearly) returns for each asset class.
Node.js installed.
npm start ./data/<data-file>.json ./data/<params-file>.json <resultsLimit>Example of a JSON data file with historical yearly returns. Each array element contains an object where key is an asset name and value is change of the asset's price value in percent.
[
{
"year": 1972,
"stocks": 18.76,
"bonds": 11.41,
"gold": 42.57
},
{
"year": 1973,
"stocks": -14.31,
"bonds": 4.32,
"gold": 66.96
}
// ...
]Params file contains several options:
-
sortBy- how results are sorted; the options are:Return,MaxDrawdownandSortino -
resultsLimit- a number that defines the amount of top results printed out -
minimalAcceptableReturn- used to calculate Sortino Ratio -
allocationLimits- defines allocation combinations for each asset via allocation limits and change step; the key of each asset should be equal to the respective header in the Data file.
Example of the params file:
{
"sortBy": "Return",
"resultsLimit": 10,
"minimalAcceptableReturn": 0.3,
"allocationLimits": {
"stocks": { "min": 0.5, "max": 1, "step": 0.1 },
"bonds": { "min": 0.1, "max": 0.5, "step": 0.1 },
"gold": { "min": 0.2, "max": 0.6, "step": 0.1 }
}
}In the example above, the algorithm will test the following allocations for gold: 0.2, 0.3, 0.4, 0.5, 0.6.