Class for running a backtest. See below for usage example.

// 1. First create the backtester options 
let ops = {
base_asset : "ETH",
quote_asset : "BUSD",
data : [ {p :1450 , t : "ISO_DATE" }...],
initial_portfolio : {
base_balance : 20 ,
quote_balance : 0 ,
} ,
logger_id : "ETHUSDC" ,
fee : 0.001 ,
slippage : 0.01,
target_precision : 0.05,
target_ratio : 0.6,
}

// 2. Then create the backtester
let backtester = new BacktestBalancer(ops) ;

// 3. Then run the backtest
await backtester.backtest() ;

// 4. Then extract the backtest metrics and use them in a graph, analysis, etc...
let {
hodl_porfolio_series,
balance_portfolio_series,
rebalances
} = backtester ;

Hierarchy (view full)

Constructors

Properties

Logger: any
balance_portfolio_series: common.trading.backtest_balancer.Portfolio[]
current_index: number
fee: number
hodl_portfolio_series: common.trading.backtest_balancer.Portfolio[]
last_balance_data: any
log_mode: string
ratio_series: number[]
rebalances: any[]
slippage: number
state: any
transactions_costs: any

Methods

  • Retrieve data about a potential rebalancing

    Returns Promise<{
        base_amt: number;
        base_delta: number;
        base_market_amt: number;
        base_price: number;
        current_ratio: number;
        portfolio_value: number;
        quote_amt: number;
        ratio_error: number;
        target_achieved: boolean;
        target_base_amt: number;
        target_precision: number;
        target_ratio: number;
        trade_type: common.trading.portfolio_balancer_lib.MarketTradeType;
    }>

  • Parameters

    Returns {
        base_balance: number;
        p: number;
        quote_balance: number;
        t: string;
        value: number;
    }

    • base_balance: number
    • p: number
    • quote_balance: number
    • t: string
    • value: number
  • Parameters

    • tc: any
    • p: number

    Returns {
        fee_cost: any;
        slippage_cost: any;
        total: any;
    }

    • fee_cost: any
    • slippage_cost: any
    • total: any