ex_backtest v0.0.1 ExBacktest.Strategy.Trader

Link to this section Summary

Functions

create_transaction Add a record to the trade hostory

do_trades Try to find buy and sell points based on given potential points. It starts buy the first buy point and tries to find the nearest sell point. It continues to find the next buy points and etc.

Link to this section Functions

Link to this function

buy(data, buy_index, cash, commission, potential_buy_points, potential_sell_points, history)

buy(list(), number(), float(), float(), list(), list(), map()) ::
  {float(), map()}

buy Add the current index as a buy point to the history

Parameters

- data: An array of price data like Close prices.
- buy_index: Buy index to be added in the history
- cash: Current amount of the money
- commision: Commision percent, for example, for 1 percent it must be 0.01
- potential_buy_points: List of indixes which show potential points for buying
- potential_sell_points: List of indixes which show potential points for selling
- history: A map contains trades data. Each item is like this:
            ```101 => %{"type" => "BUY", "price" => 12.023, "cash" => 1.0023} ```
Link to this function

calc_trade_resault(buy_price, sell_price, commission, cash)

Link to this function

create_transaction(type, buy_or_sell_index, price, cash, history)

create_transaction(String.t(), number(), float(), float(), map()) ::
  {number(), map()}

create_transaction Add a record to the trade hostory

Parameters

type: BUY or SELL or CURRENT. CURRENT is used if the last point is buy and there is no more sell point
buy_or_sell_index: Trade point index
price: Value in the index
cash: Amounnt of current cash
history: Trade history
Link to this function

do_trades(data, potential_buy_points, potential_sell_points, init_cash, commision)

do_trades([float()], [integer()], [integer()], float(), float()) ::
  {number(), %{}}

do_trades Try to find buy and sell points based on given potential points. It starts buy the first buy point and tries to find the nearest sell point. It continues to find the next buy points and etc.

Parameters

- data: An array of price data like Close prices.
- potential_buy_points: List of indixes which show potential points for buying
- potential_sell_points: List of indixes which show potential points for selling
- init_cash: The money to start trading
- commision: Commision percent, for example, for 1 percent it must be 0.01
Link to this function

sell(data, sell_index, buy_index, cash, commission, potential_buy_points, potential_sell_points, history)

sell(list(), number(), number(), float(), float(), list(), list(), map()) ::
  {float(), map()}

sell Add the current index as a buy point to the history

Parameters

- data: An array of price data like Close prices.
- sell_index: Sell index to be added in the history
- buy_index: Last buy index
- cash: Current amount of the money
- commision: Commision percent, for example, for 1 percent it must be 0.01
- potential_buy_points: List of indixes which show potential points for buying
- potential_sell_points: List of indixes which show potential points for selling
- history: A map contains trades data. Each item is like this:
            ```101 => %{"type" => "BUY", "price" => 12.023, "cash" => 1.0023} ```