Suppose you have some security A, and the suppose the following:
Initial amount of security bought: 100
Initial price: $10
Suppose after some time:
Sold qty: 10
Sold at: 11
Then you buy some again:
More bought: 20
At the price: 15
And then you sell some again:
Sold: 40
At the price: 11
And also suppose that you want to know unrealized and realized and a total percentage return for each of the days that security is traded, and not just when you rebalance. I tried to Google this, but can't seem to find anything, nor can I figure out how to calculate the return in this setting myself.