Stocks have been soaring in recent months, with indexes reaching new all-time highs.

The tech industry, in particular, has experienced especially staggering returns. The Vanguard Information Technology ETF (VGT 0.24%) has surged by a whopping 46% since April, as of this writing on July 21, compared with the S&P 500's 27% returns in that time.

However, this also makes it an incredibly expensive time to buy. This ETF's price has surged from $470 per share in April to around $686 per share currently. While soaring stock prices make some investors optimistic, others are worried that the market can only go down from here.

To be clear, nobody can say for certain what the market will do over the coming weeks or months. However, here's what history says about investing in funds like the Vanguard Information Technology ETF right now.

person using a laptop displaying graphs.

Image source: Getty Images.

History says there's never a bad time to invest

First, it's important to note that past performance does not guarantee future returns. Even if a particular stock or fund has performed well historically, that doesn't necessarily mean it will continue to thrive over time.

That said, when it comes to general market trends, record prices shouldn't scare investors away from buying. In the best-case scenario, the market continues surging, and buying now will result in immediate gains. However, even if stocks plunge soon, your investment will likely recover and still experience positive long-term returns.

For example, say you had invested in the Vanguard Information Technology ETF in January 2022. Stocks were at record highs at the time, but they were about to sink into a nearly year-long bear market. This ETF was hit particularly hard, plummeting by more than 34% in just 10 months.

VGT Chart

VGT data by YCharts

In the near term, your portfolio would have taken a serious hit. However, when investing in the stock market, you don't technically lose any money unless you sell your investments for less than you paid for them.

In this case, if you'd simply held your ETF through all the market's rough patches, you'd have earned total returns of more than 50% by today -- in spite of the major slump we've already faced so far this year.

VGT Chart

VGT data by YCharts

The Vanguard Information Technology ETF can be a particularly good fund to hold for the long term, as it contains a mix of blue chip industry leaders as well as smaller corporations with the potential for explosive growth.

Nvidia, Apple, and Microsoft are the fund's top three holdings, and together they make up close to 45% of the entire ETF. However, this fund also contains an additional 316 holdings from all areas of the tech sector -- providing more diversification than if you were to invest in individual stocks.

Because juggernaut companies like Nvidia and Apple are more likely to survive economic downturns, that can help limit risk. But with hundreds of smaller stocks in your portfolio too, that can set you up for significant gains if even one of them becomes a superstar performer.

One major risk factor to consider right now

The biggest risk to consider when investing at peak prices is that you might see significant short-term volatility. Tech stocks and ETFs tend to be hit harder during periods of volatility, and those downturns can be stomach-churning at times.

For example, earlier this year when the stock market dipped substantially, the Vanguard Information Technology ETF sank by nearly 27% in less than two months -- compared with the S&P 500's 19% drop in that time.

VGT Chart

VGT data by YCharts

While nobody knows when the next downturn will hit, be prepared for more significant volatility when you invest in a tech ETF. Again, strong investments are still likely to thrive over the long term. But if you choose to buy now, it's wise to avoid investing any cash you might need in the next several years.

Market uncertainty can make right now a daunting time to invest. But if history shows us anything, it's that those who are willing to stick it out through tough times are likely to reap the biggest rewards.