You are looking for the internal rate of return. You do have to be careful with it because there will be one root for every time a cash flow switches from an outflow to an inflow and back so if you had an outflow followed by an inflow followed by an outflow you may have two roots. If that is the case, you have to test both roots. You would use the actual dollar values and not returns. Days with no transactions would have zeros. Don't use an inbuilt function such as IRR in Excel as it is not guaranteed to be the true IRR, but instead the first root it found. It runs a search routine and offers you the chance to guess.
You can also do the modified internal rate of return, which assumes you have a fixed reinvestment rate.
There is no automatic algorithm to account for opportunity costs because there cannot be a market for opportunity costs as they are the things you did not do. In the absense of transactions, no market could form. Additionally, opportunity costs are purely subjective.
By chance, I used to belong to a credit union that happened to have the highest deposit rates in the United States of any financial institution as observed by Bank Rate Monitor in a particular set of weeks. As I was a member, my "risk free" rate was higher than almost any person in the US as it is backed by the full faith and credit of the United States. Unless you happened to live in that county, as it was a geographic credit union, then you could not avail yourself of those rates. As they happened to sit near the corprate investment grade bond rates, it was illogical for me to buy corporate bonds, up to the limit allowed. For a person in a low rate region, their opportunity costs are different.
Likewise, if one of your opportunities is a particular piece of real estate, most individuals will not have those same choices.
Even if, somehow, your opportunity costs were limited to traded assets, you could not use realized returns to measure your opportunity costs as you did not know them at the time you made your choice. You would have to perform estimates on your alternatives and then measure your excess gain given the change in risk.
Now, if your cash investments receive interest or you pay on margin, then the IRR will carry your opportunity costs in it in the implicit change in the amount of cash available at crediting dates. It will not fully reflect your total set of subjective opportunity costs.
You do need to remember, opportunity costs are forward facing and not retrospective. You should be calculating your opportunity costs before the transaction happens.
If you are working prospectively, then your hurdle rate should be your opportunity cost. You can then compare the realizations to your planned rate.