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_profit_loss_total
Calculates the total profit_loss
calculate_r_multiple
Function to calculate the R-multiple
calculate_risk_actual
Calculates the risk we actually took, based on the data in TABLE_TRADE
Functions
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
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
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
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
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
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