Liking cljdoc? Tell your friends :D

clojure-backtesting.portfolio


close-out-ordersclj

source

close-records!clj

(close-records!)

Closes any open CSV records.

Closes any open CSV records.
sourceraw docstring

eval-recordclj

source

eval-report-dataclj

source

evalreport-wrtrclj

source

init-capitalclj

source

init-portfolioclj

(init-portfolio date capital)

This function initialises or restarts the backtester at date with capital in cash. A restart clears the previous run: the portfolio, its records, indicators, automations and any orders still pending. When OUTPUT-DIR is set, the order, portfolio-value and evaluation records are also written there as CSV files.

This function initialises or restarts the backtester at `date` with
`capital` in cash. A restart clears the previous run: the portfolio,
its records, indicators, automations and any orders still pending.
When OUTPUT-DIR is set, the order, portfolio-value and evaluation
records are also written there as CSV files.
sourceraw docstring

LOAN-EXISTclj

source

log-returnclj

(log-return curr prev)

Natural-log return from prev to curr, or 0.0 when either is not positive.

Natural-log return from `prev` to `curr`, or 0.0 when either is not positive.
sourceraw docstring

on-init-portfolioclj

(on-init-portfolio key f)

Registers f, a function of no arguments, to be called by every init-portfolio so that it clears run state this namespace cannot reach. Registering again under the same key replaces the earlier hook.

Registers `f`, a function of no arguments, to be called by every
init-portfolio so that it clears run state this namespace cannot reach.
Registering again under the same `key` replaces the earlier hook.
sourceraw docstring

order-recordclj

source

order-wrtrclj

source

portfolioclj

source

portfolio-exposureclj

(portfolio-exposure)

The current portfolio map summarised in dollars: :cash, :long (market value of long positions), :short (absolute market value of short positions), :equity (cash + long - short), :gross (long + short) and :loan (cash borrowed, i.e. the negative cash balance).

The current portfolio map summarised in dollars: :cash, :long (market
value of long positions), :short (absolute market value of short
positions), :equity (cash + long - short), :gross (long + short) and
:loan (cash borrowed, i.e. the negative cash balance).
sourceraw docstring

portfolio-valueclj

source

portvalue-wrtrclj

source

record-portfolio-valueclj

(record-portfolio-value date)

Appends (or replaces) today's entry in the portfolio-value vector from the current portfolio map: equity as :tot-value, its log return since the previous trading day's entry (or since the starting capital on the first day), the cumulative return, cash borrowed (:loan), the value of borrowed stock (:short), :leverage = (loan + short) / equity and :margin = equity / gross position value (1.0 with no positions).

Appends (or replaces) today's entry in the portfolio-value vector from
the current portfolio map: equity as :tot-value, its log return since
the previous trading day's entry (or since the starting capital on the
first day), the cumulative return, cash borrowed (:loan), the value of
borrowed stock (:short), :leverage = (loan + short) / equity and
:margin = equity / gross position value (1.0 with no positions).
sourceraw docstring

revalue-holdings!clj

(revalue-holdings! date info-map)

Brings every holding that has a row in today's info-map to today's price, crediting dividends to cash, then records today's portfolio value. A holding with no row for MISSING-DAYS-LIMIT trading days in a row is treated as delisted and written off to cash at its last value.

Brings every holding that has a row in today's `info-map` to today's
price, crediting dividends to cash, then records today's portfolio value.
A holding with no row for MISSING-DAYS-LIMIT trading days in a row is
treated as delisted and written off to cash at its last value.
sourceraw docstring

revalue-positionclj

(revalue-position {:keys [price aprc quantity cfacpr] :as position} info)

Carries a position to today's data row info. Returns [position cash] where cash is the dividend paid out to the cash balance. With REINVEST-DIVIDENDS the position's value follows the security's total return (the APRC ratio since it was last valued) and the share count absorbs both dividends and splits; nothing is paid out. Without it the share count changes only by the split factor and the remainder of the total return is paid out as cash. Short positions pay the dividend instead of receiving it.

Carries a position to today's data row `info`. Returns [position cash]
where cash is the dividend paid out to the cash balance.
With REINVEST-DIVIDENDS the position's value follows the security's
total return (the APRC ratio since it was last valued) and the share
count absorbs both dividends and splits; nothing is paid out.
Without it the share count changes only by the split factor and the
remainder of the total return is paid out as cash. Short positions pay
the dividend instead of receiving it.
sourceraw docstring

TERMINATEDclj

source

total-valueclj

(total-value)

This function returns the remaining total value including the cash and stock value

This function returns the remaining total value including the cash and stock value
sourceraw docstring

update-loanclj

(update-loan date amount is-interest)

Records today's portfolio value after a change in borrowing. When is-interest is true, amount is interest debited from cash first; otherwise it is the amount just borrowed, which is informational since the loan balance is read from the cash balance.

Records today's portfolio value after a change in borrowing. When
`is-interest` is true, `amount` is interest debited from cash first;
otherwise it is the amount just borrowed, which is informational since
the loan balance is read from the cash balance.
sourceraw docstring

update-portfolioclj

(update-portfolio date permno quantity info loan)

Applies a trade of quantity shares of permno at today's row info and records today's portfolio value. loan is the amount borrowed for it.

Applies a trade of `quantity` shares of `permno` at today's row `info`
and records today's portfolio value. `loan` is the amount borrowed for it.
sourceraw docstring

update-portfolio-mapclj

(update-portfolio-map date permno quantity info loan)

Buys (quantity > 0) or sells quantity shares of permno at the price in today's row info, moving quantity * price between cash and the holding.

Buys (quantity > 0) or sells quantity shares of `permno` at the price in
today's row `info`, moving quantity * price between cash and the holding.
sourceraw docstring

write-off!clj

(write-off! permno)

Books the holding in permno as cash at its last value and removes it, for a security that has stopped trading.

Books the holding in `permno` as cash at its last value and removes it,
for a security that has stopped trading.
sourceraw docstring

write-record!clj

(write-record! wrtr-atom line)

Appends line to the record held in wrtr-atom, if that record is being written.

Appends `line` to the record held in `wrtr-atom`, if that record is being written.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close