Electronic structure calculations of Na2 SbF5, BaMgF4, and BaZnF4 are performed from first principles based on a plane-wave pseudopotential method. The linear optical properties and the static second-harmonic generation coefficients are also calculated. Furthermore, a real-space atom-cutting method is employed to analyze the respective contributions of the anionic groups and cations in Na2 SbF5 to the optical response. The results show that the anionic groups (SbF5) 2- in the crystal are quite favorable for producing larger microscopic second-order susceptibilities.