IIRC, the problem isn't that the vessels are armed on the open sea, but that the weapons are banned in most ports of call. If a merchant vessel can't dock because of the .50 cals on board, they have a hard time doing business, especially in some third world port where a bribe can get their cargo seized for "weapons smuggling".
I read a science fiction story once, set in the near future, where large shipping companies had a problem with piracy. They solved it by "renting" sovereignity from some nation that is a collection of coral atolls. The tiny nation had neither the money, nor the interest, to combat pirates, so the merchant companies paid it to put its flags on armed ships the merchants equipped. Presto, you don't have an illegally armed merchamt ship, but a warship from Tinynesia.