~andy47/Portfolio#1: 
Retrospectively recalculate portfolio values

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

Status
RESOLVED CLOSED
Submitter
~andy47
Assigned to
No-one
Submitted
4 years ago
Updated
1 year, 3 months ago
Labels
In Progress

~andy47 1 year, 8 months ago

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 the stock_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.

~andy47 REPORTED CLOSED 1 year, 8 months ago

~andy47 CLOSED REPORTED 1 year, 8 months ago

~andy47 1 year, 8 months ago

I've created a Jupyter notebook called scripts/recalculate_portfolio_values.ipynb to work through the solution.

~andy47 1 year, 8 months ago*

Where do we start calculating values from? I'm thinking that I should retrofit a creation_date attribute to the Portfolio 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.

~andy47 REPORTED CLOSED 1 year, 3 months ago

Register here or Log in to comment, or comment via email.