Constant Proportion Portfolio Insurance (CPPI) is a strategy designed to give participation in a risky asset while protecting the invested capital. Some gap risk due to extreme events is often kept by the issuer of the product: a put option on the CPPI strategy is included in the product. In this paper we present a new method for the pricing of CPPIs and options on CPPIs, which is much faster and more accurate than the usual Monte-Carlo method. Provided the underlying follows a homogeneous process, the path-dependent CPPI strategy is reformulated into a Markov process in one variable, which allows to use efficient linear algebra techniques. Tail events, which are crucial in the pricing are handled smoothly. We incorporate in this framework linear thresholds, profit lock-in, performance coupons... The American exercise of open-ended CPPIs is handled naturally through backward propagation. Finally we use our pricing scheme to study the influence of various features on the gap risk of CPPI strategies.