> For the complete documentation index, see [llms.txt](https://quantinfra.gitbook.io/quantinfra-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://quantinfra.gitbook.io/quantinfra-docs/balances-and-investment.md).

# Balances and investment

All accounts in QuantInfra are multi-currency and multi-instrument.

## Account currency

When creating an account, its base currency must be selected. When the account equity is calculated at the end of the day, all position and cash balance values will be converted to the account currency.

## Cash balance

Cash balance includes:

* Balance operations (deposits and withdrawals)
* Trades booked to the account (the payment in the settlement currency of the contract is added or subtracted from the cash balance for contracts with type Stock and FX; commission for the trade is subtracted from the balance)
* Futures variation margin
* Interest and funding payments for open positions

## Balance operations

Balance operations are used to adjust an account's cash balance. They can be created manually in the Control Panel. For brokers that allow downloading the balance operations history (e.g., Binance), the operations are downloaded automatically.

Creating a balance operation manually allows specifying 3 flags:

<table><thead><tr><th width="279.8984375">Flag</th><th>Description</th></tr></thead><tbody><tr><td>AffectsBalance</td><td>Default = yes<br><br>Indicates whether the operation will change the balance of the account</td></tr><tr><td>AffectsPnL</td><td>Default = no<br><br>Indicates whether the operation must be added to the PnL.<br>For automatically downloaded funding payments is set to yes.</td></tr><tr><td>AffectsInvestment</td><td>Default = yes<br><br>Indicates whether the operation will change the investment<br>For automatically downloaded funding payments is set to no.</td></tr></tbody></table>

## Investment and share count

One of the platform's concepts is that strategies must trade with a leverage of 1, where leverage is calculated as the position value divided by the investment.

This allows:

* comparing strategies’ yield directly;
* mixing strategies into books and calculating the book total return;
* copying strategies from virtual accounts to ESAs.

When some strategies are added to a book, and there is a fund account connected to this book, investment helps to automate allocations to particular strategies:

* A balance operation is created on the fund account, changing its investment
* The platform automatically calculates the investments of particular strategies inside the fund as (*Strategy weight in the book* x *Fund leverage* x *Fund investment*) and updates balances of the strategies’ accounts. Upon updating the balance, the callback OnInvestmentChanged is invoked for each of the strategies, so they can adjust the current positions, if required.

Investment also serves as the denominator when calculating a strategy's return (and building the yield chart). The algorithm calculating the returns supports changes in the investment by using the Share Count and Share Price:

* Initially, the Share Price of the account equals 1 and Share Count equals 0
* When a balance operation that affects investment is processed, share count changes by the investment change divided by the current share price
* Share price equals the current account equity divided by the share count
* Return between two moments of time equals the ratio between share prices at these moments minus one

Example:

|                                                              | Investment | Equity  | Share price | Share count | Yield since inception   |
| ------------------------------------------------------------ | ---------- | ------- | ----------- | ----------- | ----------------------- |
| Initial investment of 100’000 units of account base currency | 100’000    | 100’000 | 1           | 100’000     | 1 / 1 - 1 = 0           |
| After trading, PnL equal to 10’000 is accumulated            | 100’000    | 110’000 | 1.1         | 100’000     | 1.1 / 1 - 1 = 0.1 = 10% |
| 10’000 of the PnL is withdrawn                               | 90’000     | 100’000 | 1.1         | 90’909      | 10%                     |
| Another 10’000 of PnL is booked                              | 90’000     | 110’000 | 1.21        | 90’909      | 21%                     |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://quantinfra.gitbook.io/quantinfra-docs/balances-and-investment.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
