pub struct EtfTrick { /* private fields */ }Expand description
The ETF trick (AFML §2.4.1): the value of one dollar invested in a basket.
Build from in-memory Tables with EtfTrick::from_tables or from CSV paths with
EtfTrick::from_csv, then call EtfTrick::get_etf_series.
Implementations§
Source§impl EtfTrick
impl EtfTrick
Sourcepub fn from_tables(
open: Table,
close: Table,
alloc: Table,
costs: Table,
rates: Option<Table>,
) -> Result<Self, EtfTrickError>
pub fn from_tables( open: Table, close: Table, alloc: Table, costs: Table, rates: Option<Table>, ) -> Result<Self, EtfTrickError>
Creates an ETF trick from in-memory tables.
open and close are prices, alloc the target weights (any leverage; they are
de-levered), costs the carry or dividends per bar in price units (added to the price
change), and rates the FX rate of each instrument to the account currency (1 when
None). All tables must share the row index and column count.
§Errors
EtfTrickError::IndexMismatchif a table’s index or row count differs fromopen’s.EtfTrickError::ColumnMismatchif a table’s column count differs fromopen’s.
Sourcepub fn from_csv(
open_path: &str,
close_path: &str,
alloc_path: &str,
costs_path: &str,
rates_path: Option<&str>,
) -> Result<Self, EtfTrickError>
pub fn from_csv( open_path: &str, close_path: &str, alloc_path: &str, costs_path: &str, rates_path: Option<&str>, ) -> Result<Self, EtfTrickError>
Creates an ETF trick that reads its tables from CSV files (see Table::from_csv) when
EtfTrick::get_etf_series is called.
§Errors
Never; the files are not opened until EtfTrick::get_etf_series. The Result is
kept for API stability.
Sourcepub fn get_etf_series(
&self,
batch_size: usize,
) -> Result<Vec<(String, f64)>, EtfTrickError>
pub fn get_etf_series( &self, batch_size: usize, ) -> Result<Vec<(String, f64)>, EtfTrickError>
Computes the value series (index, K_t), starting from K = 1.
Implements AFML §2.4.1: at a rebalance on bar t the holdings become
h_t = w_t K_t / (o_{t+1} fx_t sum|w_t|), and bar t + 1 adds
sum h_t fx_{t+1} (delta_{t+1} + costs_{t+1}), with delta the open-to-close change on
the bar after a rebalance and the close-to-close change otherwise. Between rebalances
the holdings are carried unchanged.
The series starts on the second row with K = 1, and that row counts as a rebalance.
The first row is not used, and the last row is dropped (sizing there needs a next open),
so n rows give n - 2 values; fewer than three rows give none. The row index matches
mlfinlab’s output; the values do not, because mlfinlab sizes the holdings one bar late
(see the module page).
batch_size exists for mlfinlab compatibility: it is checked for CSV sources and
otherwise ignored. CSV files are read in full.
§Errors
EtfTrickError::BatchTooSmallif the source is CSV andbatch_size < 3.- Any
Table::from_csverror for a CSV source. EtfTrickError::IndexMismatchorEtfTrickError::ColumnMismatchif the tables disagree in shape.EtfTrickError::MissingColumnif a table lacks an instrument named inalloc.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EtfTrick
impl RefUnwindSafe for EtfTrick
impl Send for EtfTrick
impl Sync for EtfTrick
impl Unpin for EtfTrick
impl UnsafeUnpin for EtfTrick
impl UnwindSafe for EtfTrick
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Key for Twhere
T: Clone,
impl<T> Key for Twhere
T: Clone,
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.