pub struct HyperliquidBacktest {Show 14 fields
pub base_backtest: Option<Backtest>,
pub data: HyperliquidData,
pub strategy_name: String,
pub initial_capital: f64,
pub commission_config: HyperliquidCommission,
pub commission_tracker: CommissionTracker,
pub order_type_strategy: OrderTypeStrategy,
pub funding_pnl: Vec<f64>,
pub trading_pnl: Vec<f64>,
pub total_pnl: Vec<f64>,
pub total_funding_paid: f64,
pub total_funding_received: f64,
pub funding_payments: Vec<FundingPayment>,
pub enhanced_metrics: EnhancedMetrics,
}
Expand description
Enhanced backtesting engine with Hyperliquid-specific features
Fields§
§base_backtest: Option<Backtest>
Underlying rs-backtester Backtest instance
data: HyperliquidData
Original Hyperliquid data with funding information
strategy_name: String
Strategy name for identification
initial_capital: f64
Initial capital for the backtest
commission_config: HyperliquidCommission
Commission configuration
commission_tracker: CommissionTracker
Commission tracking
order_type_strategy: OrderTypeStrategy
Order type strategy for commission calculation
funding_pnl: Vec<f64>
Funding PnL tracking (separate from trading PnL)
trading_pnl: Vec<f64>
Trading PnL tracking (without funding)
total_pnl: Vec<f64>
Total PnL tracking (trading + funding)
total_funding_paid: f64
Total funding paid (negative values)
total_funding_received: f64
Total funding received (positive values)
funding_payments: Vec<FundingPayment>
Funding payment history
enhanced_metrics: EnhancedMetrics
Enhanced metrics
Implementations§
Source§impl HyperliquidBacktest
impl HyperliquidBacktest
Sourcepub fn new(
data: HyperliquidData,
strategy_name: String,
initial_capital: f64,
commission: HyperliquidCommission,
) -> Self
pub fn new( data: HyperliquidData, strategy_name: String, initial_capital: f64, commission: HyperliquidCommission, ) -> Self
Create a new HyperliquidBacktest instance
Sourcepub fn base_backtest(&self) -> Option<&Backtest>
pub fn base_backtest(&self) -> Option<&Backtest>
Access the base backtest instance
Sourcepub fn base_backtest_mut(&mut self) -> Option<&mut Backtest>
pub fn base_backtest_mut(&mut self) -> Option<&mut Backtest>
Access the base backtest instance mutably
Sourcepub fn with_order_type_strategy(self, strategy: OrderTypeStrategy) -> Self
pub fn with_order_type_strategy(self, strategy: OrderTypeStrategy) -> Self
Set the order type strategy for commission calculation
Sourcepub fn initialize_base_backtest(&mut self) -> Result<()>
pub fn initialize_base_backtest(&mut self) -> Result<()>
Initialize the underlying rs-backtester with converted data
Sourcepub fn calculate_with_funding(&mut self) -> Result<()>
pub fn calculate_with_funding(&mut self) -> Result<()>
Calculate backtest results including funding payments This method applies funding payments to positions based on funding rates and timing
Sourcepub fn calculate_with_funding_and_positions(
&mut self,
positions: &[f64],
) -> Result<()>
pub fn calculate_with_funding_and_positions( &mut self, positions: &[f64], ) -> Result<()>
Calculate funding payments with position tracking This version allows external position tracking for more accurate funding calculations
Sourcepub fn is_funding_time(&self, timestamp: DateTime<FixedOffset>) -> bool
pub fn is_funding_time(&self, timestamp: DateTime<FixedOffset>) -> bool
Check if a given timestamp is a funding payment time (every 8 hours) Hyperliquid funding payments occur at 00:00, 08:00, and 16:00 UTC
Sourcepub fn get_funding_rate_for_timestamp(
&self,
timestamp: DateTime<FixedOffset>,
) -> Option<f64>
pub fn get_funding_rate_for_timestamp( &self, timestamp: DateTime<FixedOffset>, ) -> Option<f64>
Get funding rate for a specific timestamp from the data
Sourcepub fn calculate_funding_payment(
&self,
position_size: f64,
funding_rate: f64,
mark_price: f64,
) -> f64
pub fn calculate_funding_payment( &self, position_size: f64, funding_rate: f64, mark_price: f64, ) -> f64
Calculate funding payment based on position size, funding rate, and mark price Formula: funding_payment = position_size * funding_rate * mark_price Positive payment means funding received, negative means funding paid
pub fn data(&self) -> &HyperliquidData
pub fn strategy_name(&self) -> &str
pub fn initial_capital(&self) -> f64
pub fn commission_config(&self) -> &HyperliquidCommission
pub fn funding_pnl(&self) -> &[f64]
pub fn trading_pnl(&self) -> &[f64]
pub fn total_funding_paid(&self) -> f64
pub fn total_funding_received(&self) -> f64
pub fn funding_payments(&self) -> &[FundingPayment]
pub fn enhanced_metrics(&self) -> &EnhancedMetrics
pub fn is_initialized(&self) -> bool
pub fn validate(&self) -> Result<()>
Sourcepub fn commission_stats(&self) -> CommissionStats
pub fn commission_stats(&self) -> CommissionStats
Get commission statistics
Sourcepub fn calculate_trade_commission(
&self,
trade_value: f64,
trade_index: usize,
scenario: TradingScenario,
) -> (OrderType, f64)
pub fn calculate_trade_commission( &self, trade_value: f64, trade_index: usize, scenario: TradingScenario, ) -> (OrderType, f64)
Calculate trade commission based on order type strategy
Sourcepub fn track_commission(
&mut self,
timestamp: DateTime<FixedOffset>,
order_type: OrderType,
trade_value: f64,
commission_paid: f64,
scenario: TradingScenario,
)
pub fn track_commission( &mut self, timestamp: DateTime<FixedOffset>, order_type: OrderType, trade_value: f64, commission_paid: f64, scenario: TradingScenario, )
Track commission for reporting
Sourcepub fn funding_summary(&self) -> FundingSummary
pub fn funding_summary(&self) -> FundingSummary
Generate a funding summary for reporting
Sourcepub fn enhanced_report(&self) -> Result<EnhancedReport>
pub fn enhanced_report(&self) -> Result<EnhancedReport>
Generate an enhanced report with Hyperliquid-specific metrics
Sourcepub fn print_enhanced_report(&self) -> Result<()>
pub fn print_enhanced_report(&self) -> Result<()>
Print enhanced report to console
Sourcepub fn export_to_csv<P: AsRef<Path>>(&self, path: P) -> Result<()>
pub fn export_to_csv<P: AsRef<Path>>(&self, path: P) -> Result<()>
Export backtest results to CSV
Sourcepub fn export_funding_to_csv<P: AsRef<Path>>(&self, path: P) -> Result<()>
pub fn export_funding_to_csv<P: AsRef<Path>>(&self, path: P) -> Result<()>
Export funding payments to CSV
Sourcepub fn funding_report(&self) -> Result<FundingReport>
pub fn funding_report(&self) -> Result<FundingReport>
Generate a detailed funding report
Trait Implementations§
Source§impl Clone for HyperliquidBacktest
impl Clone for HyperliquidBacktest
Source§fn clone(&self) -> HyperliquidBacktest
fn clone(&self) -> HyperliquidBacktest
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for HyperliquidBacktest
impl RefUnwindSafe for HyperliquidBacktest
impl Send for HyperliquidBacktest
impl Sync for HyperliquidBacktest
impl Unpin for HyperliquidBacktest
impl UnwindSafe for HyperliquidBacktest
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> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.