A surprise rally in crude oil and a series of positive earnings from the likes of Best Buy (BBY) - Get Report  helped push Wall Street into the green on Tuesday. 

The S&P 500 was up 0.20%, the Dow Jones Industrial Average climbed 0.10%, and the Nasdaq gained 0.30%. Nasdaq hit an intraday record high during the session.

Crude oil quickly turned higher halfway through the session after being down for most of the session. Oil changed direction after Reuters reported that Iran could possibly participate in discussions over a production freeze. The Organization of the Petroleum Exporting Countries will meet in September.

Oil snapped a seven-session winning streak on Monday after Morgan Stanley analysts threw doubt on whether an agreement between OPEC would come to passh. Analysts wrote in a note on Monday that a deal was "highly unlikely" as producers remain reluctant to give up market share.

West Texas Intermediate crude oil on Tuesday closed 1.27% higher at $48.01 a barrel on Tuesday.

In earnings news, Best Buy soared 19%, on track to close with its biggest one-day percentage gain since early 2001, after breezing past earnings estimates and reporting an unexpected increase in same-store sales. The electronics retailer earned an adjusted 57 cents a share in its July-ended quarter, above consensus of 43 cents. Sales at stores open for at least 12 months rose 0.8%, far better than an expected decline. Online sales drove momentum with the segment seeing 24% growth over the quarter.

Toll Brothers (TOL) - Get Report was 9% higher after clearing high quarterly expectations. The real-estate company reported a 24% jump in sales over the quarter to $1.27 billion, above consensus of $1.25 billion, as a recovery in the housing market benefited demand. Per-share profit of 61 cents a share rose from 36 cents in the year-ago quarter and met expectations.

JM Smucker (SJM) - Get Report fell 8% after posting a mixed first quarter. The owner of Jif peanut butter reported adjusted income of $1.86 a share, above estimates of $1.74. Revenue fell 7% to $1.8 billion, below expectations of $1.9 billion. The company also decreased its full-year comparable sales estimates, expecting growth to be flat or down 1% compared to a previous increase of 1%.

The second-quarter earnings season is drawing to a close with more than 96% of S&P 500 companies having reported their earnings. Most companies managed to clear lowered expectations over the quarter -- 71% of companies exceeded earnings estimates over the quarter, according to Thomson Reuters.

Investors were also looking ahead to the two-day annual Monetary Policy Symposium in Jackson Hole, Wyo., at the end of the week. A speech on Friday from Federal Reserve Chair Janet Yellen will provide important context to the markets' outlook for rates. Yellen's comments will likely remain dovish and conservative, pushing data dependency for any future rate moves.

The chances of a September rate hike currently sit at 18%, according to CME Group fed funds futures. A rate hike in November has better chances at 41%.

The number of newly constructed homes sold in the U.S. reached 654,000 in July, up 12.4% at a seasonally adjusted rate, according to the Commerce Department. The reading topped economists' forecasts of 581,000. New home sales have risen for five straight months.

"The upbeat tone of this report was quite encouraging and it points to sustained buoyancy in the housing sector recovery, which has been one of the few bright spots of the U.S. economy in recent months," said Millan Mulraine, deputy chief U.S. macro strategist, TD Securities. "When combined with the sustained positive momentum in the existing homes market and the constructive tone in building activity, a very rosy picture is beginning to emerge on the U.S. housing market."

Tesla (TSLA) - Get Report gave back most of the day's gains after announcing new versions of its Model S and Model X vehicles, including new batteries for faster performance. Expectations had been high after CEO Elon Musk made mention of an announcement earlier in the day.

Tableau Software (DATA) - Get Report soared 13% after the company appointed Adam Selipsky as CEO late Monday. Selipsky had previously held the position of vice president of sales, marketing and support for Amazon.com's (AMZN) - Get Report Web Services. Baird upped its price target on shares to $65 from $60 and maintained its outperform rating.