Are stock-market investors overpricing or underpricing a potential coronavirus vaccine?

The stock market’s rally back to all-time highs might not have been possible without optimism over a COVID-19 vaccine. And that means progress and setbacks toward that goal could continue to drive the market in the weeks and months ahead.

Analysts at UBS rolled back the market tape to take a look at how stocks have reacted to positive and negative vaccine-related news since the coronavirus pandemic hit. They concluded that optimism around vaccine developments added around 6.5 percentage points to the S&P 500’s return since May.

If so, that certainly helped the S&P 500 SPX, +0.34% to take back the ground it lost during the stock market’s pandemic-inspired plunge. The U.S. benchmark closed at record highs this past week, including in Friday’s session, returning to trade above levels seen before falling nearly 34% from a Feb. 19 record to its March 23 low as the spread of COVID-19 forced the near-shutdown of the U.S. and global economy.

The UBS analysts calculated the impact by measuring the number of “shock” days, in which the S&P 500 moved up or down by at least one standard deviation versus its average daily movement in reaction to positive or negative vaccine-related news. Using their model, which gauges how much positive vaccine news contributed to a fall in a closely followed economic policy uncertainty index, they concluded that investors had priced in a 33% to 40% probability of a vaccine.

On an industry level, however, it appears prospects for a vaccine are less priced in, the analysts said. They noted that shares of companies with the most to gain — such as hard-hit hospitality and leisure stocks — from a vaccine have barely outperformed the S&P 500 since May, suggesting a vaccine isn’t really priced in across industries, they wrote.

Several companies are working toward a vaccine. The Wall Street Journal on Thursday reported that Johnson & Johnson JNJ, +0.88% plans to launch what could be the largest clinical trial of a COVID-19 vaccine seen so far, enlisting up to 60,000 people world-wide. That would be double the size of other pivotal studies that have started or are expected to begin soon for vaccines developed by Moderna Inc. MRNA, -2.00%, Pfizer Inc. PFE, +0.41% and AstraZeneca PLC AZN, -1.38%.