The first method is dollar balancingneutral and the second one is beta balancingbased on the relationship of price movement between two assets.
For the first case: Dollar balancingmethod of dollar neutral
Let's say you have $1000 worth ofwant to keep the amount invested in stock A and stock B same. SimplyThen, simply divide this$1000 with the price of A and B. The number you get is the number of shares of A and B you need to short Bbuy/sell to dollar balance your portfolio. Themake the pair dollar balancing is a rough way to hedge a positionneutral.
For the second case: Beta balancing
Let's saymethod, you long 100 shares of stockneed to find the relationship between two stocks A and B. You needUse that to short 100calculate the spread. For example, the spread can be formed as 1 * hedge ratio(beta)stock A - slope * stock B. Where the slope of the line resulting from regressing A and b prices becomes the number of shares of stock b to rebalance your portfoliobuy for every 1 share of stock A.