Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Anyone know how to fix this efficiently? I'm calculating Realized gains but the output is ~ $120.
Because it's using the avg cost as the sales price of each share.
However what it should do sell the shares using FIFO.
But I can't think of how to efficiently track the purchase prices to use without replaying all the trades and tracking every single share that is bought and sold.
Like:
B1 100
S1 50
B2 100
B3 40
S2 70 (50 B1 20 B2)
rant