We develop a general framework for applying the Kelly criterion to stock markets. By supplying an arbitrary probability distribution modeling the future price movement of a set of stocks, the Kelly fraction for investing each stock can be calculated by inverting a matrix involving only first and second moments. The framework works for one or a portfolio of stocks and the Kelly fractions can be efficiently calculated. For a simple model of geometric Brownian motion of a single stock we show that our calculated Kelly fraction agrees with existing results. We demonstrate that the Kelly fractions can be calculated easily for other types of probabilities such as the Gaussian distribution and correlated multivariate assets.