Currently, electrical loads used by various consumers are non-linear in nature such as industrial, residential and commercial loads. All these nonlinear loads require harmonic current for their operation and the power quality of the electrical system decreases due to variation or distortion in the harmonic components of the load current. Efficiency of the power system network also gets reduced due to same harmonic component of line current. Basically, an active power shunt filter produces a harmonic current that is the same as a non-linear load, but in opposite phase. Proposed work is focused on the reduction of Total Harmonic Distortion (THD). In this work, simulation of Shunt Active Power Filter (SAPF) is done under different load conditions. Proportional Integral (PI) controller is the main block of the whole model. In order to determine the gain values of the PI block, optimization algorithm such as Ant Colony Optimization (ACO) algorithm and Genetic Algorithm (GA) are used. In this paper, comparative study for obtaining the Kp and Ki values of PI controller is explained using ACO and GA optimization. This work shows the effectiveness of the ACO algorithm to obtain the best values of Kp and Ki that leads to the minimum possible total harmonic distortion. This paper demonstrates the application of the proposed method for harmonic elimination under different load conditions simulated using MATLAB.