By Richard Leong

NEW YORK (Reuters) - Upbeat company earnings lifted U.S. and European stock prices on Wednesday, with the Dow and S&P 500 setting record highs, while the dollar reached a four-month peak on bets the U.S. Federal Reserve may raise interest rates by year-end.

The impressive run in major equity markets around the globe led investors to reduce their safe-haven positions in U.S. and German government debt, sending their yields higher.

Oil prices recovered from a two-month low after U.S. data showed a further drawdown in crude inventories, reducing worries about a domestic supply glut.

"The market has been rallying on the expectation of good earnings with some companies even providing decent forecasts," said Thomas Wilson, managing director of wealth advisory at Brinker Capital in Berwyn, Pennsylvania.

The Dow Jones industrial average <.DJI> unofficially closed up 36.02 points, or 0.19 percent, at 18,595.03, the S&P 500 <.SPX> ended up 9.24 points, or 0.43 percent, at 2,173.02 and the Nasdaq Composite <.IXIC> finished 53.56 points, or 1.06 percent, higher at 5,089.93.

The Dow and S&P 500 reached intraday record highs at 18,622.01 and 2,175.63, respectively, while Nasdaq touched its highest since Dec. 30.

Microsoft <MSFT.O> and Morgan Stanley <MS.N> were the latest U.S. companies whose quarterly results topped analyst estimates. Microsoft shares rose 5.3 percent while Morgan Stanley stock gained 2.1 percent.

Across the Atlantic, SAP <SAPG.DE>, Europe's largest software group, and ASML Holding <ASML.AS>, a supplier to semiconductor makers, reported quarterly results that beat forecasts.

They helped propel Europe's broad FTSEurofirst 300 index <.FTEU3> to close up 1 percent at 1,345.11 points.

The MSCI world equity index <.MIWD00000PUS>, which tracks shares in 45 nations, rose 1.92 points or 0.47 percent, to 412.75.

Earlier, Japan's Nikkei <.N225> broke a seven-day winning streak, falling 0.3 percent.

While most stock markets post gains, investors scaled back their holdings of government bonds, with U.S. and German yields near their highest levels since Britain's vote to leave the European Union on June 23.

The benchmark U.S. 10-year Treasury yield <US10YT=RR> was up 2 basis points at 1.58 percent, while 10-year German Bund yield <DE10YT=RR> moved up 2 basis points at -0.01 percent.

The dollar hit its strongest level in four months against a basket of currencies as lofty stock prices and encouraging economic data revived wagers the Fed would raise interest rates later this year.

The dollar index <.DXY> was last up fractionally at 97.095, trimming its earlier modest gains.

Oil prices rose as much as 1 percent, lifting U.S. crude from two-month lows, after the U.S. government reported a ninth straight week of crude inventory draws.

Brent crude <LCOc1> settled up 51 cents or 1.1 percent, at $47.17 per barrel. U.S. crude <CLc1> settled up 29 cents or 0.65 percent at $44.94 a barrel.

Gold declined to a three-week low on rising equity prices and the stronger dollar. It <XAU=> fell $17.20, or 1.29 percent, to $1,314.53 an ounce.

(Additional reporting by Lewis Krauskopf, Dion Rabouin, Barani Krishnan in New York; Nigel Stephenson, Anirban Nag and Atul Prakash in London; Shinichi Saoshiro in Tokyo; Editing by Nick Zieminski and Meredith Mazzilli)