# Hedge by shorting stock

Is it possible to explain to me why the formula is $r_A-hr_B$?

My interpretation is that, you short stock B (by selling it), and then you use the money to buy stock A. Thus we have a $r_A$ term there.

Then, we have to buy back stock B. so $r_A-hr_B$.

Is this interpretation correct?

The hedge portfolio is therefore this unit of stock A that you bought, minus $h$ units of stock B that you have short for the hedge. Of course, shorting stock B means that you will have to buy it back at some point, hence the "-" sign.
$$r_{port} = r_A - h r_B$$.
In the following, you want to minimize the risk of this hedging portfolio. In this framework, risk is determined by the variance of your portfolio, and the goal is to find the optimal number of shares $h$ of stock B you should own to reach this minimum variance (or optimal) portfolio.