I have three corporate bonds with maturities 2,3 and 5 years. They pay annual fixed coupons. I know their yield to maturities. How to compute their z spreads?
To calculate a Z-spread similar to Bloomberg's, you calculate (numerically) how much the swap curve needs to be shifted in parallel in order for the bond cash flows discounted with the shifted swap curve to match the bond's dirty price.
Note that you need to know the bond's cash flows in order to discount them, and in order to calculate the price from the yield that you are given. You have the coupon payment frequency (annual), but you need to know how the coupon rate as well.
If you don't have the coupon rates that you need to do this precisely, then you can estimate the Z-spread by subtracting a risk-free rate from the bond yield - maybe with some conversion for frequencies. It's a rough approximation and I doubt that you're expected to do this.