As the installation of solar-photovoltaic and wind-generation systems continue to grow, the location must be strategically selected to maintain a reliable grid. However, such strategies are commonly subject to system adequacy constraints, while system security constraints (e.g., frequency stability, voltage limits) are vaguely explored. This may lead to inaccuracies in the optimal placement of the renewables, and thus maximum benefits may not be achieved. In this context, this paper proposes an optimization-based mathematical framework to design a robust distributed generation system, able to keep system stability in a desired range under system perturbance. The optimum placement of wind and solar renewable energies that minimizes the impact on system stability in terms of the standard frequency deviation is obtained through particle swarm optimization, which is developed in Python and executed in PowerFactory-DIgSILENT. The results reveal that the proposed approach has the potential to reduce the influence of disturbances, enhancing critical clearance time before frequency collapse and supporting secure power system operation.