#### NOTE
[Go to the end](#sphx-glr-download-auto-examples-data-preparation-plot-1-investment-horizon-py)
to download the full example code or to run this example in your browser via JupyterLite.

<a id="sphx-glr-auto-examples-data-preparation-plot-1-investment-horizon-py"></a>

<a id="investment-horizon"></a>

# Investment Horizon

This tutorial explores the difference between the general
procedure using different investment horizons and the simplified procedure as explained
in [data preparation](https://skfolio.org/user_guide/data_preparation.html.md#data-preparation).

<a id="prices"></a>

## Prices

We load the S&P 500 [dataset](https://skfolio.org/user_guide/datasets.html.md#datasets) composed of the daily prices of 20
assets from the S&P 500 Index composition starting from 1990-01-02 up to 2022-12-28:

```Python
from plotly.io import show

from skfolio import PerfMeasure, Population, RiskMeasure
from skfolio.datasets import load_sp500_dataset
from skfolio.optimization import MeanRisk
from skfolio.preprocessing import prices_to_returns
from skfolio.prior import EmpiricalPrior

prices = load_sp500_dataset()
prices.head()
```

[plotly figure stripped from llms output]<style>html[data-theme="dark"] div.output_subarea:has(.plotly-graph-div){background:#fff;border-radius:0.25rem;padding:0.5rem}@media (prefers-color-scheme: dark){html:not([data-theme="light"]) div.output_subarea:has(.plotly-graph-div){background:#fff;border-radius:0.25rem;padding:0.5rem}}</style><script>if (!window.plotlySphinxGalleryResize) {window.plotlySphinxGalleryResize = true;window.addEventListener("load", function () {document.querySelectorAll(".plotly-graph-div").forEach(function (gd) { Plotly.Plots.resize(gd); });});}</script>

<br/>

Let’s plot the portfolios compositions:

```Python
population.plot_composition()
```

<style>html[data-theme="dark"] div.output_subarea:has(.plotly-graph-div){background:#fff;border-radius:0.25rem;padding:0.5rem}@media (prefers-color-scheme: dark){html:not([data-theme="light"]) div.output_subarea:has(.plotly-graph-div){background:#fff;border-radius:0.25rem;padding:0.5rem}}</style><script>if (!window.plotlySphinxGalleryResize) {window.plotlySphinxGalleryResize = true;window.addEventListener("load", function () {document.querySelectorAll(".plotly-graph-div").forEach(function (gd) { Plotly.Plots.resize(gd); });});}</script>[plotly figure stripped from llms output]
<br />
<br />

We can see that the simplified procedure only start to diverge from the general one
for investment horizons longer than one year.

**Total running time of the script:** (0 minutes 1.318 seconds)

<a id="sphx-glr-download-auto-examples-data-preparation-plot-1-investment-horizon-py"></a>
[![Launch JupyterLite](auto_examples/data_preparation/images/jupyterlite_badge_logo.svg)](../../lite/lab/index.html?path=auto_examples/data_preparation/plot_1_investment_horizon.ipynb)

[`Download Jupyter notebook: plot_1_investment_horizon.ipynb`](https://skfolio.org/auto_examples/data_preparation/_downloads/f85e312b20dcdd4fb7c29268aa9c42cc/plot_1_investment_horizon.ipynb)

[`Download Python source code: plot_1_investment_horizon.py`](https://skfolio.org/auto_examples/data_preparation/_downloads/dbc56be12f8ae0dfedeb1c54c4af79b0/plot_1_investment_horizon.py)

[`Download zipped: plot_1_investment_horizon.zip`](https://skfolio.org/auto_examples/data_preparation/_downloads/eacee1ea68b6b1767aa362ca2bcfb25f/plot_1_investment_horizon.zip)

[Gallery generated by Sphinx-Gallery](https://sphinx-gallery.github.io)
