Write short rebalancing calculation code in Javascript or Php
$30-250 USD
Closed
Posted about 5 years ago
$30-250 USD
Paid on delivery
Write rebalancing calculation code in Javascript or Php.
The code must be data based: arrays / objects of data.
The goal of the project is to write a short rebalancing calculation code in Javascript or Php.
Rebalancing is when you define a portfolio of x% of stock A, y% of stock B, and z% of stock C.
After a while, stocks prices change, and we need to sell some stocks and buy others, to rebalance.
E.g:
We have 1000$.
Stock A - cost 10$, we want our portolio to have 20% of stock A - 20 stocks total value 200$.
Stock B - cost 15$, we want our portolio to have 30% of stock B - 20 stocks total value 300$.
Stock C - cost 50$, we want our portolio to have 50% of stock C - 10 stocks total value 500$.
a year has passed, now the prices are:
Stock A - 5$, worth 100$ (5*20).
Stock B - 15$, still worth 300$.
Stock C - 40$, worth 400$ (10*40).
Total worth: 800$.
Now, stock A is 12.5% of the portfolio, so we need to buy more of it to make it 20%.
stock B is 37.5% of the portfolio, so we need to sell some of it to make it 30%.
stock C is 50% which is the goal, so we need to do nothing.
Then another year will pass, and the same calculation again...