User Tools

Site Tools


trading:basic_concepts

Basic Concepts

The basic formulae and notions regarding the trading will be provided.

Contract For Difference (CFD)

This type of contract is considered a Derivative Contract since its price is derived from another activity, the so-called underlying asset.

Balance and Equity

The amount of money present in the account is indicated by balance and equity, with the following differences:

  • equity is the account's money plus the algebraic sum of the profit of all the open positions;
  • balance is the account's money plus the algebraic sum of the profit after a position is closed.

Therefore, when there are no open positions equity is equal to balance.

Ask Price and Bid Price

It's called spread the difference between the ask price and the bid price:

spread = ask - bid

and it's always:

ask > bid

The spread represents the profit made by the broker every time the trader opens and closes a position.

Open Price and Close Price

Depending on the trade's direction, the open_price and the close_price are calculated in different ways:

trade's direction open price close price
buy (long) ask bid
sell (short) bid ask

Margin Required

The money necessary to open a position, with size = 1, depends on the margin_percent [%], established by the broker, and which varies with the symbol:

margin_required = 1 * open / exchange_rate * margin_percent / 100 [currency]

where the exchange_rate is the rate of exchange between the account's currency and the symbol's currency.

Leverage

Leverage is defined as:

leverage = 1 / margin_percent * 100
Figure 1: Margin percent for the symbol US500.

Margin

The amount of money that a trader puts at risk at each trade is called margin and is a percentage (risk [%]) of the amount of money available margin_free in the account:

margin = margin_free * risk / 100 [currency]

Size

The size of a trade is calculated as:

size = margin / margin_required

The trade's volume must respect the maximum and minimum limit imposed by the broker as well as the step between two consecutive values:

size = round((margin / margin_required) / vol_step) * vol_step;

if (size > vol_max) {
    size = vol_max;
}
else if (size < vol_min) {
    size = 0;
}

Obviously, in case size == 0, no position can be open.

Figure 2: Volume specifications for the symbol US500.

Margin Open

The money necessary to open a position of any size is equal to:

margin_open = size * margin_required [currency]

The margin_open is a deposit which will be given back as soon as the position is closed and no stop_out occurs.

Margin Free

The money left in the account after a position has been opened is:

margin_free = equity - margin_open [currency]

When a position is open, the volatility of the price leads to temporary unrealized profit or loss: the margin_free has the function to absorb these losses and prevent a margin_call or, even worse, a stop_out.

Margin Level

The percentage ratio of the equity against the margin_open is given by:

margin_level = equity / margin_open * 100 [%]

In particular:

  • margin_level = 0 when no position is open.
  • margin_level = 100% when margin_free = 0 due to the losses;

Stop Out

When margin_level < 100% there is no more margin_free to cover further losses which are now absorbed by the margin_open. Therefore, brokers have a specific threshold limit under which a position is automatically closed:

if (margin_level < limit) {
    stop_out();
}

Take Profit and Stop Loss

The value in currency at which close a position in profit or at a loss is calculated as:

take_profit = open_price + size * points [currency]
stop_loss = open_price - size * points [currency]

Points

The distance between two values, measured on a chart of a specific symbol, has to be multiplied by the number of digits of that symbol:

points = abs(value_A - value_B) * pow(10, digits)
Figure 3: As an example, from the symbol US500:
value_A = 4493.2
value_B = 4499.7
abs(value_A - value_B) = 6.5
digits = 1
pow(10, digits) = 10^1
points = 65

Swap

A swap rate is a rollover interest for holding a position overnight or over the weekend. Depending on the type of position (long or short), the interest could be positive or negative.

The formula varies with the type of the market (forex, commodities, indices, …), as specified by the broker.

The interest values provided by the broker are on an annual basis. Divide them by 365 to get values on a daily basis.

Figure 4: As an example, from the symbol US500:
swap = volume * contract_size * market_close_price * (swap_percent / 100 / 365) [currency]

Converting Profit into Account Currency

If the account currency is different from the symbol currency, the conversion should consider the exchange rate of the Ask price at the time when the position is closed.

The trade is done in the symbol currency and the relative profit/loss is then converted into the account currency buying the equivalent amount of money.

// buy
price_in = Ask  // [USD]
price_out = Bid  // [USD]
profit/loss = (price_out - price_in) * size  // [USD]
exchange_rate = Ask  // [EURUSD]
profit/loss = profit_loss / exchange_rate  // [EUR]

// sell
price_in = Bid  // [USD]
price_out = ASk  // [USD]
profit/loss = (price_in - price_out) * size  // [USD]
exchange_rate = Ask  // [EURUSD]
profit/loss = profit_loss / exchange_rate  // [EUR]
trading/basic_concepts.txt · Last modified: 2024/01/08 16:58 by tormec