It is present electron optics optimization for terahertz radiation generation by a sequence of short electron bunches passing through the dielectric loaded waveguide. In this method the superposition of individual bunch wakefields is used to selectively excite high frequency TM0n modes in a slow-wave structure. The main problem of this scheme is the transverse beam instability that limits the length of THz radiation wave packet. The main goal of this paper is a new parameter optimization algorithm for the FODO focusing system. The numerical modelling of the beam dynamics was performed in the original code “Dielectric waveguide” which utilizes analytic expression of the Green’s function for the dielectric loaded waveguides with cylindrical and rectangular geometries.