His middle name is Edward. That’s where Ted comes from.
His father’s name is Rafael, so that’s why.
What are the reasons for the adopted or nicknames? I had one growing up, lost it as adult. I know people with them, others without them. No big deal overall. It is funny though when they do it for political reasons. Edward or Ted is more electable than Rafael, Robert is fine. Beto is apparently a childhood nickname that stuck.