Getty Images.

Suppose you have some extra money lying around, but you aren't sure what to invest in. Depending on how long you have until you might need to use the money, there are different things to invest in. Here are some smart ways to invest your money by time frame.

One year or less

Suppose you have a few thousand dollars lying around, but you know that you'll have to spend it some time in the next year to buy a car, or put a new roof on your house, for example. Although it may be enticing to invest it in the stock market and hope it grows, your best bet is to keep it in cash by holding it in a high-yielding savings account.

While stocks make a great long-term investment, they make a poor short-term investment. As my colleague Morgan Housel has explained, the stock market is best suited for investors who can be invested for the long haul. Over the history of the stock market, investing for one-year periods has resulted in losses 31% of the time.

High-yield savings accounts are thus your best bet because they are liquid, frequently fee-free, and offer returns that, while low, are better than sticking your cash under a mattress. By shopping around, you can easily find high-yield accounts that offer 1% or so per year, significantly more than the 0.05% rates paid by the nation's largest banks on traditional savings accounts.

One to five years

If you can afford to lock up your money for the intermediate term, your investment options expand and offer better profit potential. But you can't really afford to take the risk of investing it in stocks just yet -- even over a five-year period, average annual returns for stocks have been negative about 20% of the time.

The best short-term investments for this timeline include bank certificates of deposit, inflation-protected government bonds, and high-quality short-term bond funds.

  • Certificates of deposit: Banks will pay you higher rates if you can commit to locking up your money for one to five years. Currently, 5-year CDs yield about 2% per year, or twice the rate of high-yield savings accounts. FDIC insured against losses up to $250,000, your chance of losing money is zero. Beware, however, that you could lose some money to early-withdrawal penalties if need it before the CD matures.
  • Inflation-protected U.S. Treasuries: You can protect the purchasing power of your savings by investing in I-Bonds. These securities pay a fixed rate of interest (currently 0.1%) plus the measured rate of inflation. Thus, if inflation were 2% in any given year, investors would receive a return that approximates 2.1% (fixed rate plus inflation of 2%). An I-Bond can be cashed in after one year. However, if you cash in an I-bond within the first five years, you'll surrender three months' of interest. Hold them for five years or longer, and you can cash them in at any time, penalty free.
  • High-quality bond funds: An investment-grade, short-term bond fund can be an excellent choice as a short-term investment. Though they aren't guaranteed by the U.S. Government like I-Bonds or bank CDs, losses are very unlikely. For example, the Vanguard Short-Term Investment-Grade Fund (VFSTX 0.10%) currently yields about 2%, and is generally a very safe investment option. While it lost money during the financial crisis in 2008, it quickly recoveedr and exceed its pre-crisis peak within one year.

5 years or more

If you don't expect to need this extra money for five years or more, you can start to think about risk at least some of it in the stock market. Over periods of five years, the stock market has historically produced negative annual returns 20% of the time. However, historically, over any period of more than 20 years, the U.S. stock markets have never sustained a loss.

The optimal asset allocations for any given period of time have been heavily debated, but the basic premise that the longer your time horizon, the greater the proportion of your assets you can safely hold in stocks has always held true.

  • 10 years: This is an investment timeline commonly associated with saving for the college expenses of a child. Vanguard recommends  an asset allocation of 25% stocks and 75% bonds for the future college costs of a child currently in the 6- to 10-year-old range, which approximates a 10-year holding period.
  • 20 years or more: This investment timeline is generally associated with saving for retirement. Investors with very long timelines can afford to keep a significantly higher fraction of their portfolio in stocks. People in their 20s who expect to work another 40 or so years before retiring can reasonably invest in a portfolio of 90% stocks and 10% bonds. (Many target-date funds with targets that far in the future invest this aggressively.) Workers who are only 20 or so years away from retirement may prefer to dial back the risk and put 80% of their portfolio in stocks and 20% of it in bonds.

As for how to buy stocks and bonds, low-fee index funds make a great choice. By putting money in just four low-fee Vanguard funds, an investor can invest in every single U.S. and international stock and bond of meaningful size. They are:

  • Total Stock Market Index Fund (VTSMX 1.27%)
  • Total International Stock Index Fund (VGTSX 0.96%)
  • Total Bond Market Index Fund (VBMFX 0.11%) 
  • Total International Bond Index Fund (VTIBX -0.10%)

By far, the most important part of investing for the long term is sticking to it. Studies have shown time and time again that investors who panic and sell when stocks fall, expecting to get back in when conditions are better, worsen their financial futures by selling at temporarily depressed prices.

Ultimately, your ideal long-term asset allocation is one that will allow you to sleep well at night and ignore the desire to tinker with your portfolio through every up and down of the market. This is a highly personal matter, and no one can tell you how you'll feel when the next stock market correction hits.

Stock/Bond Allocation

Worst one-year decline since 1926

0%/100%

-8.1%

20%/80%

-10.1%

40%/60%

-18.4%

60%/40%

-26.6%

80%/20%

-34.9%

100%/0%

-43.1%

Source: Vanguard.

Use the table above as a guideline to understand the potential for short-term losses based on various asset allocations. If you know that you couldn't personally ever tolerate seeing your wealth drop by more than 40% in a year, then you absolutely shouldn't be 100% invested in stocks, and a 60/40 or 80/20 portfolio may be better suited for you, for example. 

The road to wealth from investing is full of its ups and downs, but investors who are patient and capable of ignoring the swings from one year to the next have realized untold riches through long-term investing.