The opportunity cost of an investment is the return you could have got if you’d put your money elsewhere.
For example, if I put £1,000 in shares, I give up the chance to invest in government bonds (gilts). Gilts offer a lower but safer return, reflecting the fact that the government is less likely to go bust than a firm. This is the return I sacrifice (the ‘opportunity cost’) if my shares then fall.
By extension, if I am willing to invest in shares at all, I should expect to make more than I could earn from gilts. This is the ‘equity risk premium’. So if a medium-term gilt yields 3%, my expected return on shares might be more like 8%. That’s the opportunity cost of not buying gilts (a 3% return) plus a 5% premium.