Add a function/job to recalculate the daily value of one or more portfolios for a period of time.
Parameters should be - portfolio (with option for all), start date, finish date
Just thinking about how to do this efficiently. I think we need a loop for every day from the start date to the finish date and then for that date loop through every holding in the portfolio and using
holding_movements
work out how many shares are held on that day. Then multiply that number by thestock_prices
record for that day and you have the value of that holding. Then sum all of the holding values.If this is implemented like this it may take some time. But let's do the simplest approach first and then worry about performance.
I've created a Jupyter notebook called
scripts/recalculate_portfolio_values.ipynb
to work through the solution.
Where do we start calculating values from? I'm thinking that I should retrofit a
creation_date
attribute to thePortfolio
model so that I don't calculate values for dates that don't apply.The alternate approach is to work out the date of the earliest
holding_movements
record for the portfolio.
Moved to Jira - https://halfcooked.atlassian.net/browse/PF-6