Stocks held higher on Monday as crude oil and energy names rallied on high hopes for an extension to a production cap agreement.

The S&P 500 was up 0.39%, the Dow Jones Industrial Average added 0.36%, and the Nasdaq rose 0.4%. The S&P 500 and Nasdaq hit all-time intraday highs earlier in the session. 

Crude oil prices rallied on Monday after energy ministers from Russia and Saudi Arabia surprised by calling for an extension to an oil production cap agreement.

The ministers called for the current deal among the Organization of the Petroleum Exporting Countries to be extended by nine months, far longer than what analysts had hoped. Speaking in Beijing on Monday, Saudi Arabia's energy minister, Khalid al-Falih, and Russia's Alexander Novak said they wanted the current agreement to continue holding back around 1.8 million barrels of oil from the market each day until the first quarter of 2018. 

"The two ministers agreed to do whatever it takes to achieve the desired goal of stabilizing the market and reducing commercial oil inventories to their five-year average level," the ministers said in a joint statement, "as well as to underscore the determination of oil producers to ensure market stability."

An extension to the OPEC deal will be the main point of conversation when the 13 member countries meet in Vienna on May 25. The current agreement, established last November, is set to expire at the end of June.

"There seems to be a real commitment about reducing the glut from oil powerhouses that are Saudi Arabia and Russia -- the latter being the largest oil producer in the world and the former being the largest exporter," said Fawad Razaqzada, market analyst at "Given the backing of Russia, in my view an agreement will be made. The market clearly expects that, with oil prices making a sharp comeback."

West Texas Intermediate crude was up 2.1% to $48.85 a barrel on Monday, its best gains since Wednesday of last week. Crude oil ended Monday's session at a two-week high. 

Energy stocks made big gains on Monday. Major oil producers including Exxon Mobil (XOM) - Get Report , Royal Dutch Shell (RDS.A) , Chevron (CVX) - Get Report , PetroChina (PTR) - Get Report , Total (TOT) - Get Report , BP (BP) - Get Report  and Schlumberger (SLB) - Get Report were all higher. The Energy Select Sector SPDR ETF (XLE) - Get Report increased 1.1%. 

Schlumberger is a holding in Jim Cramer's Action Alerts PLUS Charitable Trust Portfolio. Want to be alerted before Cramer buys or sells SLB? Learn more now.

Jim Cramer recommends holding onto oil stocks for now, but to be prepared to pull the trigger if crude reaches $53. Get his insights with a free trial subscription to our premium site for investors, Real Money.

A massive outbreak of cyberattacks spread across Europe over the weekend. The initial attack, known as "WannaCry," paralyzed computers running Britain's hospital network, Germany's national railway and scores of other companies and government agencies around the world. 

The "WannaCry" attack was estimated to have affected more than 200,000 computers in 150 countries since its initial launch on Friday. Britain's National Cyber Security Centre warned the cyber attack could spread "significantly" as computer systems and networks come online at the start of the working week.

Cybersecurity companies were on the upswing Monday. Symantec (SYMC) - Get Report , FireEye (FEYE) - Get Report  , Cisco (CSCO) - Get Report , Qualys (QLYS) - Get Report , and Palo Alto Networks (PANW) - Get Report were each higher. The PureFunds ISE Cyber Security ETF (HACK) - Get Report rose more than 3%. 

Cisco is a holding in Jim Cramer's Action Alerts PLUS Charitable Trust Portfolio. Want to be alerted before Cramer buys or sells CSCO? Learn more now.

Wall Street closed mixed on Friday after Nordstrom (JWN) - Get Report and J.C. Penney (JCP) - Get Report became the latest retail names to report on a weak quarter. The Dow closed lower for its fourth straight session in a row.

Wall Street is trapped in a "momentum-less" market, Bob Byrne said over on our premium site for investors Real Money. Get his insights with a free trial subscription to Real Money.

Manufacturing activity in the New York area fell into negative territory in May, according to the Empire State manufacturing survey. The measure dropped to negative 1 this month from positive 5.2 in April. Analysts had anticipated an increase to positive 7. The headline number was in negative territory for the first time this year. New orders declined to negative 4.4 this month, the worst reading in a year. 

Homebuilder sentiment improved in May as confidence in demand remained strong. The National Association of Home Builders' housing market index rose 2 points to a reading of 70, above consensus of a flat reading of 68. The NAHB said "existing home inventory remains tight" meaning that demand for new construction should continue. 

Thermo Fisher Scientific (TMO) - Get Report  rose 0.5% Monday after agreeing to acquire Patheon (PTHN) for $35 a share. The $7.2 billion deal, which includes $2 billion of net debt, is expected to be accretive to adjusted earnings in the first full year after closing. The acquisition is expected to close by the end of the year. Patheon shares jumped 33%. 

Moody's (MCO) - Get Report will purchase Dutch business information providerBureau Van Dijk for about $3.3 billion in a move that will expand the ratings agency's risk, data and analytics business. The company expects the purchase to benefit top- and bottom-line results slightly in 2018 and become fully accretive by 2019. Earlier this year, Moody's acquired the structured finance data and analytics business of Frankfurt-based SCDM.

Tesla (TSLA) - Get Report declined 2.9% after Morgan Stanley downgraded its rating on the stock to equal weight from overweight. The firm widened its full-year operating loss for this year and next after the company released its first-quarter performance. The price target was held at $305. 

Buffalo Wild Wings (BWLD)  increased 2.1% Monday after analysts at Deutsche Bank upgraded the stock to buy from hold while raising its price target to $180 from $155. The firm still sees possible risks to sales and profits in the near-term however, but cost-cutting initiatives could lessen the impact of those potential headwinds.

Coach (COH)  rose after Deutsche Bank upgraded its rating to buy from hold. Analysts remain optimistic Coach can effectively boost profit with its acquisition of Kate Spade (KATE) . The firm also cited the success of Coach's turnaround so far.

Snap (SNAP) - Get Report surged 7%, one of its best performances since going public in March, after filings showed investment firms Fidelity and BlackRock had stakes in the company. Daniel Loeb's Third Point also disclosed a position in Snap as of the end of March. 

Cocktails & Cramer

Join Jim Cramer on May 23 for an exclusive party at Bar San Miguel, his Brooklyn tavern. You'll get to watch a screening of Mad Money, after which Jim will arrive fresh off of the CNBC set to mingle, pose for photos and answer your investing questions. Participants will enjoy dinner, drinks, an autographed copy of Jim's book Get Rich Carefully and a one-year membership to Action Alerts PLUS, Jim's club for investors. (Current AAP members will receive one extra year of membership for free.)

When: Tuesday, May 23, 6 p.m.-9 p.m. EDT

Where: Bar San Miguel, 307 Smith St., Brooklyn, N.Y.

Cost: $375 per person

Space is very limited, so click here to reserve your ticket to this exclusive event today.

Read more stories on TheStreet: