We analyze the financial risk in a defined benefit pension scheme, applying dynamic programming to find optimal asset allocations for the scheme. Taiwan public employees retirement system is studied for illustration. The simulations show the impacts of parameters to the optimal asset allocations. The following are the main results. 1. Above a return level, the higher is return on a high-risk asset, the more conservative is the asset allocation. 2. The higher is risk on the high-risk asset, the more conservative is the asset allocation in the long run. 3. The relationship between correlation and the asset allocation is not clear. 4. The shorter is the amortization period, the more conservative is the asset allocation. 5. The lower is the fund ratio, the more aggressive is the asset allocation. 6. The more important is the short-term risk, the more conservative is the asset allocation in the short run. 7. The higher is the target fund ratio, the more aggressive is the asset allocation.