How can I calculate or approximate the amount of ships I should have with the "Hunt Pirates" mission in order to stop coastal raids?
The total number of guns of the ships is used to find the efficiency at which they hunt the pirates. The trade power of pirates is reduced by hunt pirate efficiency. 0%, when no fleet is hunting pirates, up to 99%, if the total number of guns from the hunting fleet is greater than or equal twice the total number of guns from pirating fleet.
In addition, it is helpful to know that this is also effective at stopping other nations from raiding your coasts.
So ideally you need twice as many guns as enemy fleet.
I didn't played or modded EU4 for a long time, but from what I recall (and it's not on wiki) naval raiding efficiency goes along with pirating efficiency. AI shouldn't raid when privateer efficiency is over 90%, but I'm not 100% sure about that. As a player you can raid even at 99% privateer efficiency, it's just not worth it.