libcalculatorfinance v0.0.1 LibCalculatorFinance.Trading.AfterTrade

Functions, related to calculations after a trade has been closed.

Summary

Functions

calculate_cost_other

Calculates other costs based on the difference that remains

calculate_cost_total

Function to calculate the total cost associated with the given trade

calculate_profit_loss

Calculates the profit_loss, without taking tax and commission into account

calculate_r_multiple

Function to calculate the R-multiple

Functions

calculate_cost_other(a_profit_loss, a_profit_loss_total, a_cost_total)

calculate_cost_other

Calculates other costs based on the difference that remains.

Examples

# positive, no other cost
iex> Float.round(LibCalculatorFinance.Trading.AfterTrade.calculate_cost_other(12.0, 8.92, 3.08), 6)
0.0
# negative, no other cost
iex> Float.round(LibCalculatorFinance.Trading.AfterTrade.calculate_cost_other(-12.0, -8.92, -3.08), 6)
0.0
# positive, 1.5 EUR other cost
iex> Float.round(LibCalculatorFinance.Trading.AfterTrade.calculate_cost_other(12.0, 8.92, 1.58), 6)
1.5
# negative, 1.5 EUR other cost
iex> Float.round(LibCalculatorFinance.Trading.AfterTrade.calculate_cost_other(-12.0, -8.92, -1.58), 6)
-1.5
calculate_cost_total(a_amount_buy, a_tax_buy, a_commission_buy, a_amount_sell, a_tax_sell, a_commission_sell)

calculate_cost_total

Function to calculate the total cost associated with the given trade.

Examples

iex> Float.round(LibCalculatorFinance.Trading.AfterTrade.calculate_cost_total(100.0, 3.0, 1.0, 50.0, 3.0, 1.0), 6)
6.5
calculate_profit_loss(a_price_buy, a_shares_buy, a_price_sell, a_shares_sell)

calculate_profit_loss

Calculates the profit_loss, without taking tax and commission into account.

Note

profit_loss = S.Ps - S.Pb

It’s the same for long and short

Examples

iex> Float.round(LibCalculatorFinance.Trading.AfterTrade.calculate_profit_loss(12.0, 2, 24.0, 2), 6)
24.0
calculate_profit_loss_total(a_price_buy, a_shares_buy, a_tax_buy, a_commission_buy, a_price_sell, a_shares_sell, a_tax_sell, a_commission_sell)

calculate_profit_loss_total

Calculates the total profit_loss.

Note

profit_loss = S.Ps - S.Ps.T - C - (S.Pb + S.Pb.T + C)

It’s the same for long and short

Examples

iex> Float.round(LibCalculatorFinance.Trading.AfterTrade.calculate_profit_loss_total(12.0, 2, 3.0, 1.0, 24.0, 2, 3.0, 1.0), 6)
21.28
calculate_r_multiple(a_profit_loss, a_risk_initial)

calculate_r_multiple

Function to calculate the R-multiple.

Examples

iex> Float.round(LibCalculatorFinance.Trading.AfterTrade.calculate_r_multiple(-100.0, 200.0), 6)
-0.5
calculate_risk_actual(a_price_buy, a_shares_buy, a_tax_buy, a_commission_buy, a_price_sell, a_shares_sell, a_tax_sell, a_commission_sell, a_risk_initial, a_profit_loss)

calculate_risk_actual

Calculates the risk we actually took, based on the data in TABLE_TRADE.

Note

risk_actual = S.Pb + S.Pb.T + Cb - (S.Ps - S.Ps.T - Cs)

It’s the same for long and short.

Examples

# -minimum risk-
iex> LibCalculatorFinance.Trading.AfterTrade.calculate_risk_actual(4138.00, 4, 0.0, 3.0, 4151.30, 4, 0.0, 3.0, 117.4136, 53.20)
117.4136
# -bigger risk-
iex> LibCalculatorFinance.Trading.AfterTrade.calculate_risk_actual(4178.50, 4, 0.0, 3.0, 4144.50, 4, 0.0, 3.0, 119.4196, -136.0)
142.0000