Problems of nonparametric ltering arises frequently in engineering and nancial economics. Nonparametric lters often involve some ltering parameters to choose. These parameters can be chosen to optimize the performance locally at each time point or globally over a time interval. In this article, the ltering parameters are chosen via minimizing the prediction error for a large class of lters. Under a general martingale setting, with mild conditions on the time series structure and virtually no assumption on lters, we show that the adaptive lter with ltering parameter chosen by historical data performs nearly as well as the one with the ideal lter in the class, in terms of ltering errors. The theoretical result is also veri ed via intensive simulations. Our approach is also useful for choosing the orders of parametric models such as AR or GARCH processes. It can also be applied to volatility estimation in nancial economics. We illustrate the proposed methods by estimating the volatility of the returns of the S&P500 index and the yields of the three-month Treasury bills.