Optical absorption and electron energy loss spectra of single-walled carbon nanotubes