There are theories but as to which is "optimal" is anyone's guess.
Ben Graham said that in his experience, 45% equity and 55% bonds was the optimal and not to go below 25% equity and not above 80% equity. Claude Shannon at MIT demonstrated that if you model a balance between a "stock" modeled by a random walk and cash, the optimal balance would be 50 / 50. Markowitz graphed expected returns to risks in his efficient frontier and had a tangential method to extrapolate the optimal balance. All of these concepts suggest a moderate balance shy of 50% equity but if you are dedicated to contributing a portion of your income to your investments, the future contributions are basically the same as holding a bond that would make those contributions and you can even calculate the value of that "bond" if you have a reasonable market rate of return. Your employer's corporate bond yield would be a reasonable base line for such a rate of return as your job is dependent on the well being of your employer. Therefore, while you are young, it's reasonable to be more aggressive simply because you will be making more contributions to your portfolio.
A more detailed approach would be the geometric mean optimization, also known as the logarithmic approach or the Kelly Criterion. Basically this stems from Daniel Bernoulli's 1738 paper "Specimen theoriae novae de mensura sortis (Exposition of a New Theory on the Measurement of Risk)" where he used an ordinal utility of wealth that modeled the decreasing returns of wealth and avoided ruin, the utility he proposed was the log utility of wealth.
With a mean, SD and variance, you are trying to model the stock price with a Gaussian normal distribution. There are a couple of problems with that, you know that a normal distribution doesn't apply because stock prices can never be negative. This is why the Black Scholes equation uses a log normal distribution applying the normal distribution on the logarithms instead. Even then, it's known that the distribution of stock prices are not log normal as the extreme values are more prevalent then predicted and the normal values are less prevalent then expected. It's most likely an application of the T student distribution in the logarithmic domain, with the extreme case being the Cauchy distribution which models resonance and is often used in nuclear physics and electromagnetic radiation. A Cauchy distribution would be consistent with observations that there seems to be trends and support / resistance levels. However there is no SD for a Cauchy distribution as the variance is infinite, a scaling factor has to be fitted to the observed data.
Once you have a probability distribution that you are happy with, you can optimize for the product of the probability of a given price multiplied by the logarithm of what this does to the value of your total portfolio. This is actually the optimization that is done with digital communications to maximize bandwidth and has been extrapolated to simple binary scenarios in the Kelly Criterion. An Example of this would be if you had an opportunity that had a 60% chance of you tripling your investment but a 40% chance of losing your investment, the optimal balance between that opportunity and cash would be the one that maximizes the following:
e^( 0.6 * ln( 1 - x + 3 * x ) + 0.4 * ln( 1 - x ) )
You would actually replace these two outcomes by an integral of the probability distribution.
With these two simple outcomes, the percentage to wager with the opportunity would be x = 0.398 or 39.8%. Of course with multiple investments, the number of outcomes increase geometrically.
Economists such as Samuelson, criticizes this approach on the basis that the utility of wealth can not be cardinal, it must be ordinal therefore you can not express the optimum in an equation and therefore only human judgment suffices to define the level of reasonable risk. This has often been misinterpreted as saying that each investor must find their own tolerance levels for risk. However the logarithmic utility is risk averse and tends to optimize for the growth of your portfolio but it is hardly a perfect method. A logarithmic utility can be subverted by certain outcomes just as the central limit theorem can be circumvented by certain distributions such as the Cauchy distribution and of course, the probability distribution itself can only be estimated by historical data. It's not an easy method to follow but there are references on it and it provides a heuristic while you develop the experience needed to make the appropriate "human judgement" mentioned by Samuelson.
Of course, you should perhaps just take Ben Graham's advice and save yourself a lot of confusing calculations.