Overview
The equally weighted trader puts and equal dollar amount into each asset at each trading period. As the weights of the portfolio change due to price movements, the weights are rebalanced back to equal weights.
Implementation
The following function takes a price record for the current period, and a current net asset value (NAV) and calculates the number of units of each asset to hold in order to acheive equal weights.
function equallyWeighted(price, nav){
let portfolio = {};
let total = 0;
for(let id in price){
if(id !== 'date') total += 1;
}
for(let id in price){
if(id !== 'date') portfolio[key] = nav/(total * price[id])
}
return portfolio;
}
Try it!
Running a Equally Weighted Strategy
let traders = await import('/lib/finance/trading/v1.0.0/traders.js');
let trades = traders.equallyWeighted(prices);