No, you can not choose a swarm as an animal companion
The simplest argument is that the Ranger must choose a beast, singular, not a swarm of beasts, plural. Rules designer Jeremy Crawford even supports this interpretation in an unofficial tweet from January 2016 (although the tweet is responding to a question to the druid's Wild Shape feature).
In addition to Jeremy Crawford's tweet, there is now an official ruling in the Sage Advice Compendium (as of October 2020) that says a swarm is not an option for the conjure animals spell:
Can conjure animals summon a swarm?
No. Conjure animals summons individual creatures, and swarms are groups of creatures.
The spell conjure animals refers to being able to summon a specified number of beasts, and the Wild Shape feature lets a druid turn into a single beast, just as a Beast Master gains a single beast as an animal companion. As such, the similar logic would suggest that the same restrictions apply.
Natural vs. unnatural
There are also additional arguments to be made against a swarm being a valid option. For example, consider the description of the Beast type, in the introduction to the Monster Manual (p. 6)
Beasts are nonhumanoid creatures that are a natural part of the
fantasy ecology.
And then look at the sidebar titled "The Nature of Swarms" in the section listing various types of swarms (Monster Manual, p. 377; emphasis mine):
The swarms presented here aren't ordinary or benign assemblies of
little creatures. They form as a result of some sinister or
unwholesome influence.
A creature with the beast type is a natural creature. A swarm is something that does not occur naturally.
Buyer beware
Of course, your DM may choose to allow you to choose a swarm. However, be wary of making such a choice. Each swarm, including the Swarm of Ravens, includes the following text in its Swarm trait:
The swarm can't regain hit points or gain temporary hit points.
Not being able to heal your swarm is likely going to cause you issues, especially given the relative squishiness of the animal companion in general.