We formulate a framework to solve the distributionally robust optimization problem. We allow the true probability measure to be inside a Wasserstein ball that is specified by the empirical data and the given confidence level. We transform the robust optimization into a non-robust optimization with a penalty term and provide an appropriate selection of the Wasserstein ambiguity set’s size. Then we apply the framework to some portfolio optimization problems, such as the mean-CVaR in risk management and the multiperiod mean-variance in portfolio management. Moreover, the numerical experiments of the US stock market showed the impressive results for our robust models compared to other popular strategies.