Gold and Bitcoin are volatile assets traded in two markets. Since the Bitcoin transaction, its high yield, high volatility, free supervision and tax exemption have made it a big hit in the financial field. However, how to optimize the portfolio and maximize the return on asset investment is still a major problem to be solved. This paper plans the initial portfolio we have through the construction of dynamic programming model. Firstly, the change of gold and bitcoin trading in the next three days is taken as the decision variable, and the highest Sharpe ratio in the next three days is taken as the objective function. Through the assumption that the amount of assets after trading is greater than zero, combined with the premise that gold is only traded on the market trading day, the constraint conditions are obtained. Then, according to the constraints, particle swarm optimization algorithm is used to solve. In order to avoid the premature termination of particle swarm optimization due to local optimal solution, we introduce simulated annealing algorithm to optimize it. At the same time, according to the personality characteristics of investors, different weights are given to risks and benefits, so as to obtain investment strategies under different investor personalities. Three daily investment plans for character investors were subsequently obtained. Finally, the sensitivity test is carried out for the applied model. The results show that the investment scheme selected in this paper is the local optimal value, which indicates that the scheme is accurate and effective.