Does anyone know of any formula for converting a light frequency to an RGB value?
You're talking about converting from wave length to an RGB value.
Look here, will probably answer your question. Thy have an utility for doing this with the source code as well as some explanation.
WaveLengthToRGB