The larger companies produce so many games and have such a large infrastructure, that they can afford to absorb the costs if a particular game doesn't do well; from the profits their more successful titles make.
Smaller developers do what independent film studios, recording artists etc. do - use bank loans, external investors...
They have actuaries estimate sales and develop a budget from there. If they expect to make $30M they would probably budget $20M for the game's development,
same way that films work - you find someone willing to provide the capital to create. EA are fairly self sufficient these days, but a smaller company would have to find a bank or people to provide the money.
There is a house edge built into the games.