LOS ANGELES (TNS) — John Templeton, the late investing guru, once said bull markets in stocks "mature on optimism" before they eventually "die on euphoria."

Chalk up 2017 as another year of maturity for the current bull market _ on a record scale.

Defying speculation 12 months ago that the years-long rally would be sorely tested during President Donald Trump's first year in office, the stock market has been riding a wave of continued optimism to repeatedly reach new highs.

Analysts give Trump some credit for the gains, mainly for pushing the tax bill passed by Congress last week, and for reducing regulations. But market trackers give most of the credit to several other factors, including global economic growth, stronger corporate profits, continued low inflation and rising consumer confidence.

"Looking at the economy and financial markets, it really doesn't get much better than where we are right now," Brad McMillan, chief investment officer at investment firm Commonwealth Financial Network, said in a note to clients last week.

Or, as outgoing Federal Reserve Chair Janet Yellen said this month about the economy: "There's less to lose sleep about now than there's been for quite some time."

Threats nonetheless remain, including ongoing political and trade tensions overseas, possible increases in interest rates and inflation, and the midterm elections that could change the outlook for stock prices.

But most analysts see nothing on the horizon that would cause the optimism to substantially fade or develop into such euphoria as to cause a market bubble that bursts. Many predict that the market _ as measured by the benchmark Standard & Poor's 500-stock index _ should rise more in 2018.

"I expect double-digit returns for the S&P 500 again next year (including dividends) with continued corporate earnings improvement" even though "we may be in store for some turbulence along the way," Chris Zaccarelli, chief investment officer at investment firm Independent Advisor Alliance, said in an email.

The market's surge this year has provided near-weekly achievements:

–– The Dow Jones industrial average has set record highs 70 times_the most times that's ever happened in a calendar year _ as it has gained nearly 5,000 points, or 25 percent, while closing in on 25,000. It ended the week at 24,754.06. The Dow's top gainers this year have been Boeing Co. (up 90 percent), Caterpillar Inc. (up 68 percent) and Apple Inc. (up 51 percent).

–– The broader S&P 500 has set record highs 53 times, the most since 1995, as it climbed 20 percent to 2,683.34 with a week left in 2017. The index also is poised to be "higher every month this year on a total return basis, with dividends, and that's never happened," said Ryan Detrick, senior market strategist at the investment firm LPL Financial.

–– The tech-heavy Nasdaq composite index also has repeatedly set new highs, and has shot up 29 percent as it closes in on 7,000. The index closed Friday at 6,959.96.

The gains mean the current bull market_now nearly 9 years old, with a gain of nearly 300 percent _ is now the second-strongest bull rally since World War II, trailing only the 417 percent surge between October 1990 and March 2000, according to data compiled by LPL Financial and FactSet Research Systems Inc.

As the market continues setting new records, Trump has kept touting the mileposts as evidence that his economic agenda is bearing fruit. Last Monday, for instance, Trump said on Twitter: "We have NEVER had 70 Dow Records in a one year period. Wow!"

The Twitter post was no surprise to Jim Paulsen, chief investment strategist at Leuthold Group, who said that when markets are rising, "that's the way every president handles the situation, and Trump is doing it no differently" even if Trump is using the more novel method of social media.

"As far as him taking credit, that's what every president does," Paulsen said.

Paulsen also said it was unlikely that the new tax law would generate significant added gains for stock prices because "it's already baked into (investors') expectations." Anticipation of the bill, especially its cut in the corporate tax rate to 21 percent from 35 percent, "has been around for quite a while now and well-vetted by the market," he said.

A variety of other factors drove equity prices higher this year.

Economies worldwide have shown growth and "this is the first year since 2010 that you had positive growth from the U.S., the emerging markets and the developed markets like Europe and Japan" all at once, Detrick said. "It suggests the overall global economy is on firm footing and expanding."

That has been reflected in foreign stock markets as well, with major indexes in Hong Kong, India and Brazil showing even stronger gains than the S&P 500.

In the United States, corporate earnings _ always a key factor in stock prices _ have continued to increase and the gains have kept stocks from becoming wildly expensive, analysts said.

The S&P 500 is now trading 18 to 19.5 times its companies' average trailing earnings for the past 12 months, which is well above the historical average of 15.5 but not a bubble-type valuation.

Inflation and short-term interest rates have remained relatively low. The Federal Reserve Board has lifted its key short-term rate by a full percentage point this year, but to a still-low target range of 1.25 percent to 1.5 percent.

The yield on the 10-year Treasury note stands at 2.5 percent, about where it started the year.

"Increased earnings, restrained inflation and low interest rates" provide the "basis for U.S. stocks to still trend higher," Terry Sandven, chief equity strategist at U.S. Bank Wealth Management, said in a recent note.

Even so, investors will have plenty to worry about next year, analysts said.

There is uncertainty about the direction to be taken by new Fed Chairman Jerome Powell, who replaces Yellen in February. A decision to accelerate rate increases in the face of rising inflation could chill Wall Street. Other possible show-stoppers include ongoing U.S. tension with North Korea and Iran; a Democratic wave in the midterm elections that might pull back some of Trump's pro-business policies; potential trade disputes as the United States renegotiates the North American Free Trade Agreement; and fears that a sudden sell-off by rapid-fire, computerized program traders could snowball into a major correction of 20 percent or more in stock prices.