# Portfolio allocations

Before your users can invest in a portfolio of selected instruments, the target allocation of the portfolio must be defined. A portfolio manager (or the asset management department) selects the most suitable instruments and their weightings. In this way, the investor's preferences are reflected in the resulting portfolio investment. Outside the Upvest Investment API, this is sometimes called a 'model portfolio'.

In the Investment API, this step is performed by creating a **portfolio allocation resource**. Portfolio allocations are standalone resources that you can create at any time. This resource reflects the target state of a portfolio investment and may be reused across the entire user base on your platform.

## Specifications

A portfolio allocation is defined by a list of instruments and their respective portfolio weights as a percentage of the total investment. They adhere to the following rules:

* The sum of the weights of all instruments in the allocation **must** equal 1.
* Each individual weight must be **0 or greater** (i.e., no short positions are allowed).
* A portfolio allocation must include **at least one instrument** and no instrument can be listed twice.
* You can only include instruments that are **tradable on the Investment API**. This also applies to instruments with a weight of 0. If such an instrument is no longer tradable, remove it from the allocation.


### Instruments with a weight of 0

Setting an instrument's weight equal to 0 keeps the instrument listed in the allocation without investing in it. For example, in a two-fund portfolio, such as a German pension Standarddepot, an end user can allocate 100% to one fund and keep the other fund listed with a weight of 0.

An instrument with a weight of 0 behaves exactly like an instrument that is not in the allocation, except that it remains listed and is validated like any other instrument.

The effect depends on the portfolio order type and the [order distribution strategy](/products/tol/guides/portfolios/portfolio_order_distribution) as shown in the table below:

| **Order type** | **Effect of a weight of 0** |
|  --- | --- |
| `BUY` | No orders are created for the instrument. The full amount goes to the other instruments, regardless of their position in the list. This applies to both the default and the self-balancing strategy. |
| `SELL` (with the default strategy) | The sell is split by the current value of each held position and ignores the allocation. A held position in the instrument is sold in proportion to its value, like any other position. |
| `SELL` (with the self-balancing strategy) | A held position in the instrument counts as over its target, so it is sold first. If the instrument's share of the sell would sell the whole position, the portfolio order is cancelled with the reason `SELL_LIMIT_EXCEEDED`. The same applies to an instrument that was removed from the allocation. |
| `REBALANCING` | A held position in the instrument is sold in full, and the proceeds buy the other instruments. An instrument that is not held gets nothing. |


## Creating portfolio allocations

To create a portfolio allocation, send the following request:

**POST** [`/portfolios/allocations`](/api/portfolios/create_portfolios_allocation)

Request
```json
{
  "name": "Allocation 1",
  "allocation": [
    {
      "instrument_id": "IE00B0M62Q58",
      "instrument_id_type": "ISIN",
      "weight": "0.7"
    },
    {
      "instrument_id": "US0378331005",
      "instrument_id_type": "ISIN",
      "weight": "0.3"
    }
  ]
}
```

Response
```json
{
  "id": "436244bb-4afd-4002-b53b-b1d7a3bca032",
  "created_at": "2021-07-21T14:10:00.00Z",
  "updated_at": "2021-07-21T14:10:00.00Z",
  "name": "Allocation 1",
  "allocation": [
    {
      "instrument_id": "IE00B0M62Q58",
      "instrument_id_type": "ISIN",
      "weight": "0.7"
    },
    {
      "instrument_id": "US0378331005",
      "instrument_id_type": "ISIN",
      "weight": "0.3"
    }
  ]
}
```

This example request creates a new portfolio allocation containing two different instruments.

| **Parameter** | **Description** |
|  --- | --- |
| `id` | You can use the returned allocation ID to continuously manage the created portfolio allocation and to configure a portfolio investment for your users (see next step). |
| `name` | **Optional**: Naming the created allocation is optional. |


As soon as a new portfolio allocation has been created, you receive a [webhook](/api/portfolios/portfolio_allocation_event) confirming the creation.