libcalculatorfinance v0.0.1 LibCalculatorFinance.Trading.BeforeTrade
Functions, related to calculations before starting a trade.
Summary
Functions
calculate_amount
Calculates the amount withouth tax and commission
calculate_amount_with_tax
Calculates the amount (buy/sell) with tax included, but not the commission
calculate_amount_with_tax_and_commission
Calculates the amount with tax and commission
calculate_price
Calculates the price when buying or selling
calculate_risk_initial
Calculates the initial risk. This is the risk we will take if our stoploss is reached. This should be equal to the risk_input if everything was correctly calculated
calculate_risk_input
Calculates the risk based on total pool and input. Consider this the theoretical risk we want to take
calculate_shares_recommended
Calculates the recommended amount of shares you can buy
calculate_stoploss
Calculates the stoploss
cost_tax
Cost of tax (buy and sell)
cost_transaction
Cost of transaction (tax and commission)
Functions
calculate_amount
Calculates the amount withouth tax and commission.
Examples
iex> LibCalculatorFinance.Trading.BeforeTrade.calculate_amount(12.0, 2)
24.0
calculate_amount_with_tax
Calculates the amount (buy/sell) with tax included, but not the commission.
Note
profit_loss = S.P + S.P.T (buy)
profit_loss = S.P - S.P.T (sell)
Examples
iex> LibCalculatorFinance.Trading.BeforeTrade.calculate_amount_with_tax(12.0, 2, 3.0, :buy)
23.28
iex> LibCalculatorFinance.Trading.BeforeTrade.calculate_amount_with_tax(12.0, 2, 3.0, :sell)
24.72
calculate_amount_with_tax_and_commission
Calculates the amount with tax and commission.
Note
AMT = S.P + S.P.T + C (buy)
AMT = S.P - S.P.T - C (sell)
Examples
iex> LibCalculatorFinance.Trading.BeforeTrade.calculate_amount_with_tax_and_commission(12.0, 2, 3.0, 1.0, :buy)
97.0
iex> LibCalculatorFinance.Trading.BeforeTrade.calculate_amount_with_tax_and_commission(12.0, 2, 3.0, 1.0, :sell)
-49.0
calculate_price
Calculates the price when buying or selling.
Examples
iex> Float.round(LibCalculatorFinance.Trading.BeforeTrade.calculate_price(24.0, 2, 3.0, 1.0, :buy), 6)
11.165049
iex> Float.round(LibCalculatorFinance.Trading.BeforeTrade.calculate_price(24.0, 2, 3.0, 1.0, :sell), 6)
12.886598
calculate_risk_initial
Calculates the initial risk. This is the risk we will take if our stoploss is reached. This should be equal to the risk_input if everything was correctly calculated.
Long
S.Pb + S.Pb.T + C - (S.Psl - S.Psl.T - C)
Short
S.Ps + S.Psl.T + C - (S.Ps - S.Ps.T - C)
Examples
iex> Float.round(LibCalculatorFinance.Trading.BeforeTrade.calculate_risk_initial(12.0, 2, 3.0, 1.0, 10.0, true), 6)
7.320000
iex> Float.round(LibCalculatorFinance.Trading.BeforeTrade.calculate_risk_initial(12.0, 2, 3.0, 1.0, 10.0, false), 6)
-0.680000
calculate_risk_input
Calculates the risk based on total pool and input. Consider this the theoretical risk we want to take.
Examples
iex> LibCalculatorFinance.Trading.BeforeTrade.calculate_risk_input(10000.00, 2.0)
200.0
calculate_stoploss
Calculates the stoploss.
Long
amount selling at stoploss - amount at buying = initial risk of pool
(S.Psl + S.Psl.T + C) - (S.Pb - S.Pb.T - C) = R/100 * pool
Short
amount selling - amount buying at stoploss = initial risk of pool
(S.Ps + S.Ps.T + C) - (S.Psl - S.Psl.T - C) = R/100 * pool
Examples
iex> LibCalculatorFinance.Trading.BeforeTrade.calculate_stoploss(12.0, 2, 3.0, 1.0, 2.0, 10000.0, true)
109.00492610837439
iex> LibCalculatorFinance.Trading.BeforeTrade.calculate_stoploss(12.0, 2, 3.0, 1.0, 2.0, 10000.0, false)
-87.95939086294416
cost_tax
Cost of tax (buy and sell).
Examples
iex> LibCalculatorFinance.Trading.BeforeTrade.cost_tax(25.75, 1.0, 2, 12.0, :buy)
0.75
iex> LibCalculatorFinance.Trading.BeforeTrade.cost_tax(22.25, 1.0, 2, 12.0, :sell)
0.75