Portfolio optimization is the process that aims to make a profitable asset distribution and minimize the risk of loss. Usually, portfolio optimization is performed by a human analyst through technical analysis; a process subjective to the analyst's background and confined to a reduced group of assets, limiting choices, and, consequently, the possibility of better results. This work proposes the Stock Network Portfolio Allocation (SNP A) algorithm for the automatic recommendation of a stock portfolio for the next period. SNPA especially applies to conditions where there is a possibly large number of assets to consider. It works by modeling the set of assets as a complex network, in which nodes represent assets and the edges between them are established by the correlation between their returns. The choice of assets is carried out through a random walk in the network, selecting, in the end, the assets represented by the most visited nodes. We present SNPA in two forms, differing in the way they define the transition probabilities based on return: (1) SNP Ar algorithm uses the cumulative wealth over a period and (2) SNP Ah is a hybrid algorithm that employs a forecasting model to estimate the asset returns. Both variants are compared to six portfolio algorithms and three market indices. Investment simulations were carried out from January 2019 to December 2020 considering three stock markets, the Brazilian market share (BRB3), the S&P 500 index (SP500), and the Russell Top 200 index (EQ200). Results show a predominance performance of the proposed algorithm in all three data sets. Specifically, the SNP Ah algorithm demonstrated a cumulative wealth of 267%, 308%, and 98.8%, in the 24 months, for the markets BRB3, EQ200, and SP500, respectively. In addition to these values, which are expressive for the period, the algorithm obtained the best values for the Sharpe Ratio.