Stocks closed little changed on Friday as investors capped a strong week of gains amid optimism around a potential coronavirus vaccine and the U.S. reopening its economy. 

The S&P 500 rose 0.2% to 2,955.45 while the Dow Jones Industrial Average slipped 8.96 points, or less than 0.1%, to 24,465.16. The Nasdaq Composite outperformed, rising 0.4% to 9,324.59.

For the week, Dow gained 3.3% to post its best weekly performance since April 9. The S&P 500 and Nasdaq also rose more than 3% this week. The Russell 2000, which tracks small-cap stocks, trounced the large-cap indexes this week with a more than 7% jump. 

News about a potential vaccine from Moderna sent equities flying earlier in the week, with the Dow surging more than 900 points on Monday. Moderna said all 45 participants in its vaccine trial had developed coronavirus antibodies. Reuters reported Friday, citing scientists leading the program, the U.S. is working on a effort involving more than 100,000 volunteers to test promising vaccine candidates. 

"This week started off really strong and put us on a good trajectory," said Matt Stucky, equity portfolio manager at Northwestern Mutual. "There's an increasing probability that something more permanent in nature is going to fix the problem, and that should be discounted in a positive way."

On Friday, Dr. Anthony Fauci, director of the National Institute of Allergy and Infectious Diseases, told NPR that Moderna's vaccine  data looked "promising." Moderna shares rose more than 2% on those comments. 

Fauci later told CNBC's "Halftime Report" he is "enthusiastic" about the economy reopening. 

"We can't stay locked down for such a considerable period of time that you might do irreparable damage and have unintended consequences, including consequences for health," said Fauci. "It's for that reason that the guidelines have been put forth so that the cities and states can start to reenter an reopen."

Retailers such as TJX and Gap were among the best-performing stocks this week, bolstered by optimism over states reopening their economies. TJX rallied 13.2% for the week while Gap advanced 8%. Citigroup, JPMorgan Chase and Wells Fargo all climbed more than 3% this week. 

"The future remains uncertain, and thus, we are not confident in saying a second wave cannot happen -- but the good news, there has yet to be a second wave in re-opened economies," said Tom Lee, founder and head of research at Fundstrat Global Advisors, in a note. "We remain in the half-full camp and believe stocks offer pretty good risk/reward, even here."

The S&P 500  ended the week about 35% above an intraday low set on March 23. 

Enthusiasm over a coronavirus vaccine and the economy reopening was kept in check on Friday, however, as tensions between China and the U.S. rose.

Overnight, China released draft legislation over new national security measures on Hong Kong after last year's burst of anti-government protests in the city. That law is expected to increase Beijing's hold over Hong Kong. China also opted against setting a GDP target for 2020 as the coronavirus batters the second-largest economy in the world. 

That proposal was unveiled after the Senate passed a bill earlier in the week that would potentially delist Chinese stocks from U.S. exchanges.

Ed Mills, Washington policy analyst at Raymond James, said the bill is moving at "warp speed," noting: "We believe there will be a significant push for the legislation to be taken up in the coming weeks, and we believe it is only a matter of time before this bill (or something similar) is signed into law."

Click here for the latest coronavirus news.

Subscribe to CNBC PRO for exclusive insights and analysis, and live business day programming from around the world.