Considering the randomness of distributed generation (DG), time-variance of load, the constrains of grid network operation and the maximum action number of compensator, this paper proposes a reactive power optimization model to promise the maximum overall revenue in one day which comprehensive consideration the investment maintenance cost of DG and cost of compensator. Using power loss rate to control the compensator action or not when the time load change. In order to improve the calculation speed, elitist strategy is used to improve generation algorithm when solve the optimization model in this paper. The simulating results on IEEE 33-node system shows the proposed method and calculation are effective on reducing power loss, and realize dynamic reactive power optimization.