refactored/extracted common member function accumulate(int end_of_period, double prize)
refine comments to make algorithm more clear