Billions of shares of stock are bought and sold each day, and it's this buying and selling that sets stock prices. In the short term, stocks go up and down because of the law of supply and demand.

Here's a simple illustration: Imagine there are 1,000 people willing to buy one share of stock XYZ for $10, but there are only 500 people willing to sell one share of XYZ for $10. The first 500 buyers each snag a share for $10. The other 500 buyers who were left out then raise their offer price to $10.50. This higher offer price persuades some owners of XYZ who didn't want to sell at $10 to sell at $10.50. The stock price is now $10.50 instead of $10 since that was the price of the latest transaction.

What affects stock price?

High demand for a stock drives the stock price higher, but what causes that high demand in the first place? It's all about how investors feel:

  1. Market sentiment toward the stock.
  2. Market sentiment toward the industry.
  3. Market sentiment toward the stock market.
  4. Confidence in the economy.

The more confident investors are about a company's prospects or the potential for positive developments, the more likely they are to want the stock. Conversely, a loss of confidence can lead investors to sell, pushing down the stock price.

Factors that can affect sentiment toward a stock include quarterly earnings reports beating or falling short of expectations, analyst upgrades or downgrades, and positive or negative business developments.

Demand for a stock can also be affected by sentiment toward a particular industry. An electric vehicle company, for example, may see its stock price soar as investors snap up shares because those investors are confident in the future of the EV industry. A rising tide can lift all boats.

This goes both ways. If investors sour on an industry, every stock in that industry could suffer -- regardless of how each individual company is doing.

Confidence in the stock market can also push up demand and prices for individual stocks. If investors believe that stocks are a good investment, either because valuations are attractive or because the stock market has been trending upwards, an increase in demand for stocks can push up prices across the board.

The opposite is also true. A declining stock market can zap investor confidence and lead to more selling and lower stock prices, and high valuations can prompt some investors to buy fewer stocks or sell their holdings.

Opinions about the trajectory of the economy also play a role in setting stock prices. Investors may sell some stocks in anticipation of an economic slowdown. The widespread belief in a recovering or booming economy, on the other hand, can lead to an increase in demand for stocks.

But why do stock prices change every second?

Stock prices are driven up and down in the short term by supply and demand, and the supply-demand balance is driven by market sentiment. But investors don't change their opinions every second. So why, then, do stock prices change so fast?

The current stock price is nothing more than the price at which the last transaction took place. For many stocks, transactions are occurring every second the stock market is open.

Investors trade an average of 90 million shares of Apple (NASDAQ:AAPL) each day. Every time a block of shares is bought and sold, the stock price changes to reflect the latest transaction price. The sheer number of transactions ensures that the stock price fluctuates every second, even if there's been no change in market sentiment.

The big picture is what matters

Long-term investors, like those of us at The Motley Fool, don't much care about the short-term developments that push stock prices up and down each trading day. When you have years or even decades to let your money grow, analyst reports and earnings beats are often fleeting and irrelevant. What matters is where a company will be five, 10, or 20 years from now.

In the long term, the value of a stock is ultimately tied to the future cash flows generated by the company. Investors who believe a company will be able to increase its earnings in the long run or who believe a stock is undervalued may be willing to pay a higher price for the stock today, regardless of short-term developments. This creates a pool of demand undeterred by day-to-day news, which can push the stock price higher or prevent big declines.

While a lot of ink is spilled about daily fluctuations in stock prices, and while many people try to profit from those short-term moves, long-term investors should be laser-focused on a company's potential to increase its profits over many years. Ultimately, rising profits push stock prices higher.