The possibility and expediency of forecasting in the stock markets are analyzed analytically using the methods and approaches of statistical mechanics. The apparatus of statistical mechanics is used to analyze and forecast one of the most important indicators of the market – the distribution of its logarithmic profitability. The Lotka-Volterra model used in ecology to describe systems of the "predator-prey" type was used as the initial model. It approximates market dynamics adequately. In the article, its Hamiltonian property is used, which makes it possible to apply the apparatus of statistical mechanics. The apparatus of statistical mechanics (using the principle of maximum entropy) makes it possible to implement a probabilistic approach that is adapted to the conditions of stock market uncertainty. The canonical variables of the Hamiltonian are presented as logarithms of stock and bond prices, the joint probability distribution function of stock and bond prices is obtained as a Gibbs distribution. The Boltzmann factor, included in the Gibbs distribution, allows us to estimate the probability of the occurrence of certain stock and bond prices and obtain an analytical expression for calculating the logarithmic return, which gives more accurate results than the widely used normal (Gaussian) distribution. According to its characteristics, the resulting distribution resembles the Laplace distribution. The main characteristics of the resulting distribution are calculated – the mean value, variance, asymmetry, and kurtosis. Mathematical results are presented graphically. An explanation is given of the cause-and-effect mechanism that causes a change in the profitability of the market. For this, the idea of Theodore Modis about the competition between stocks and bonds for the attention and money of investors is developed (by analogy with the turnover of biomass in models of the "predator-prey" type in biology). The results of the study are of interest to investors, theorists, and practitioners of the stock market. They allow us to make thoughtful and balanced investment decisions due to a more realistic idea of the expected return and a more adequate assessment of investment risk.