A “stock” is a partial ownership of a company, and the “market” where these partial ownerships were bought and sold had to come into being after enough partial ownership had been created to make a market for them. That time was in the 17th-18th century, (earliest, Muscovy Company in 1555) as economic speculation in colonization and natural resources exploitation, as well as a desire to establish a trade route to the spice and silk-rich East, drove investors into buying partial stakes in exploration expeditions to non-European countries. When single-patronage was not available, charter companies were established, in which each charter member received a share of the profit proportionate with his percent of the investment. The first location for exchanging, buying, and selling such shares was Jonathan's coffee house, in London.
Here it says that the exchange of shares in limited libility organizations originated in Europe in the sixteenth century.
One must wonder if gold or silver smiths might have opperated as specialists in the exchange of contracts long before.