# getCosts

Obtain buy and sell transaction costs from portfolio object

## Syntax

``````[BuyCost,SellCost] = getCosts(obj)``````

## Description

Use the `getCosts` function with a `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` object to obtain buy and sell transaction costs from portfolio objects.

For details on the respective workflows when using these different objects, see Portfolio Object Workflow, PortfolioCVaR Object Workflow, and PortfolioMAD Object Workflow.

example

``````[BuyCost,SellCost] = getCosts(obj)``` obtains buy and sell transaction costs from portfolio objects.```

## Examples

collapse all

Given portfolio `p` with the costs set, obtain the values for `BuyCost` and `SellCost`.

```p = Portfolio; p = setCosts(p, 0.001, 0.001, 5); [BuyCost, SellCost] = getCosts(p)```
```BuyCost = 1.0000e-03 ```
```SellCost = 1.0000e-03 ```

Given a PortfolioCVaR object `p` with the costs set, obtain the values for `BuyCost` and `SellCost`.

```p = PortfolioCVaR; p = setCosts(p, 0.001, 0.001, 5); [BuyCost, SellCost] = getCosts(p)```
```BuyCost = 1.0000e-03 ```
```SellCost = 1.0000e-03 ```

Given a PortfolioMAD object `p` with the costs set, obtain the values for `BuyCost` and `SellCost`.

```p = PortfolioMAD; p = setCosts(p, 0.001, 0.001, 5); [BuyCost, SellCost] = getCosts(p)```
```BuyCost = 1.0000e-03 ```
```SellCost = 1.0000e-03 ```

## Input Arguments

collapse all

Object for portfolio, specified using `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` object. For more information on creating a portfolio object, see

Data Types: `object`

## Output Arguments

collapse all

Proportional transaction cost to purchase each asset, returned as a vector for a `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` input object (`obj`).

Proportional transaction cost to sell each asset, returned as a vector for a `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` input object (`obj`).

## Tips

You can also use dot notation to obtain the buy and sell transaction costs from portfolio objects.

`[BuyCost, SellCost] = obj.getCosts;`

## Version History

Introduced in R2011a
{"ft_lang_label":"__label__en","ft_lang_prob":0.6981534,"math_prob":0.62810105,"size":2397,"snap":"2023-14-2023-23","text_gpt3_token_len":641,"char_repetition_ratio":0.19557041,"word_repetition_ratio":0.44159544,"special_character_ratio":0.22736755,"punctuation_ratio":0.14769976,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98790497,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-06-01T15:28:22Z\",\"WARC-Record-ID\":\"<urn:uuid:ed2fad39-f70d-4eec-9e2a-666f88ece7c5>\",\"Content-Length\":\"96935\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:c00533dd-2740-4ba9-a663-a5f604dc2d09>\",\"WARC-Concurrent-To\":\"<urn:uuid:9900dbfa-2858-4ba1-b763-f756017bd458>\",\"WARC-IP-Address\":\"23.218.145.211\",\"WARC-Target-URI\":\"https://jp.mathworks.com/help/finance/portfolio.getcosts.html\",\"WARC-Payload-Digest\":\"sha1:VHXUBSNU4DRXLLN6MK5M5F32N2B24PD6\",\"WARC-Block-Digest\":\"sha1:U3HOPE6J74UN6Z2CO2DVM4YMNQ5KZ4S5\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224647895.20_warc_CC-MAIN-20230601143134-20230601173134-00570.warc.gz\"}"}