The problem you describe has been solved by actuaries many, many years ago in the form of predictive rating models. These typically use a number of rating factors that are empirically adjusted based on historical data.
What you have not considered is that there are correlations between different rating factors. Age and sex are (weakly) correlated, for instance. The marginal risk probabilities do not obey assumptions of independence; e.g., the probability of a 50 year old male driver having an accident is not the product of the individual probabilities for a 50-year old having an accident, and a male having an accident. Instead, if a book of business is large enough, the insurer can directly estimate the risk factors for this subset of policyholders by looking at their historical loss experience. For those combinations that are not well-represented by a sufficiently large cohort, other methods are used, typically looking at a larger subset and extrapolating the risk through a (semi)parametric model; e.g., proportional hazards.
Insurers can specify a set of rules, or tables of rating factors, to instruct a regulator how a book of business is rated. In the present day, these are programmed into a computer system. Such tables may be hundreds of pages of output, covering every combination of every rating factor.
So, how are these tables created? As I pointed out, they are based off historical loss data. More recent data is weighted more heavily than older data. A commonly employed rating mechanism in personal lines auto insurance is the "bonus-malus" system. The scope of this topic is too broad to cover in a single answer, and is not particularly on-topic for this site; therefore you would be best advised to research the topic of "insurance ratemaking" online.