Skip to main content

EtfTrick

Struct EtfTrick 

Source
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

Source

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
Source

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.

Source

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
Source

pub fn reset(&mut self)

Does nothing; kept for mlfinlab API compatibility (the computation holds no state between calls).

Trait Implementations§

Source§

impl Clone for EtfTrick

Source§

fn clone(&self) -> EtfTrick

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EtfTrick

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 T
where T: Clone,

§

fn align() -> usize

The alignment necessary for the key. Must return a power of two.
§

fn size(&self) -> usize

The size of the key in bytes.
§

unsafe fn init(&self, ptr: *mut u8)

Initialize the key in the given memory location. Read more
§

unsafe fn get<'a>(ptr: *const u8) -> &'a T

Get a reference to the key from the given memory location. Read more
§

unsafe fn drop_in_place(ptr: *mut u8)

Drop the key in place. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.