Electronic and optical properties of a nanoring in the presence of external magnetic field