A Theory of Macroprudential Policies in the Presence of Nominal Rigidities