Open River-Shi opened 3 weeks ago
If you need to execute your order on spot or dynamically compute a value from the market depth, you can input the spot asset as well. The custom data integration example demonstrates how to work with data that is not directly from the trading asset, such as on-chain data or news. Additionally, adding the full asset data can slow down backtesting because it requires replaying tick-by-tick data. If you only need specific values from spot, the example shows a much faster approach.
Also, it may be confusing, but linear_asset
and inverse_asset
don't necessarily refer to futures. These simply set how the equity and trading value are calculated. Spot is inherently linear, so for a spot asset, you just use linear_asset
.
Please see the following example.
spot = (
# Set a spot asset data
BacktestAsset()
.data(['data/{}_{}.npz'.format(asset_name, date) for date in range(20230731, 20230732)])
.initial_snapshot('data/{}_20230730_eod.npz'.format(asset_name))
.linear_asset(1.0)
.intp_order_latency(latency_data)
.power_prob_queue_model(2.0)
.no_partial_fill_exchange()
.trading_value_fee_model(-0.00005, 0.0007)
.tick_size(asset_info['tick_size'])
.lot_size(asset_info['lot_size'])
.roi_lb(0.0)
.roi_ub(mid_price * 5)
.last_trades_capacity(10000)
)
linear_futures = (
# Set a linear futures asset data
BacktestAsset()
.data(['data/{}_{}.npz'.format(asset_name, date) for date in range(20230731, 20230732)])
.initial_snapshot('data/{}_20230730_eod.npz'.format(asset_name))
.linear_asset(1.0)
.intp_order_latency(latency_data)
.power_prob_queue_model(2.0)
.no_partial_fill_exchange()
.trading_value_fee_model(-0.00005, 0.0007)
.tick_size(asset_info['tick_size'])
.lot_size(asset_info['lot_size'])
.roi_lb(0.0)
.roi_ub(mid_price * 5)
.last_trades_capacity(10000)
)
# asset_no of spot is 0
# asset_no of linear_futures is 1
hbt = ROIVectorMarketDepthBacktest([spot, linear_futures])
If you need to execute your order on spot or dynamically compute a value from the market depth, you can input the spot asset as well. The custom data integration example demonstrates how to work with data that is not directly from the trading asset, such as on-chain data or news. Additionally, adding the full asset data can slow down backtesting because it requires replaying tick-by-tick data. If you only need specific values from spot, the example shows a much faster approach.
Also, it may be confusing, but
linear_asset
andinverse_asset
don't necessarily refer to futures. These simply set how the equity and trading value are calculated. Spot is inherently linear, so for a spot asset, you just uselinear_asset
.Please see the following example.
spot = ( # Set a spot asset data BacktestAsset() .data(['data/{}_{}.npz'.format(asset_name, date) for date in range(20230731, 20230732)]) .initial_snapshot('data/{}_20230730_eod.npz'.format(asset_name)) .linear_asset(1.0) .intp_order_latency(latency_data) .power_prob_queue_model(2.0) .no_partial_fill_exchange() .trading_value_fee_model(-0.00005, 0.0007) .tick_size(asset_info['tick_size']) .lot_size(asset_info['lot_size']) .roi_lb(0.0) .roi_ub(mid_price * 5) .last_trades_capacity(10000) ) linear_futures = ( # Set a linear futures asset data BacktestAsset() .data(['data/{}_{}.npz'.format(asset_name, date) for date in range(20230731, 20230732)]) .initial_snapshot('data/{}_20230730_eod.npz'.format(asset_name)) .linear_asset(1.0) .intp_order_latency(latency_data) .power_prob_queue_model(2.0) .no_partial_fill_exchange() .trading_value_fee_model(-0.00005, 0.0007) .tick_size(asset_info['tick_size']) .lot_size(asset_info['lot_size']) .roi_lb(0.0) .roi_ub(mid_price * 5) .last_trades_capacity(10000) ) # asset_no of spot is 0 # asset_no of linear_futures is 1 hbt = ROIVectorMarketDepthBacktest([spot, linear_futures])
Thanks
Can
Asset Type
be set tospot
? I understand from the documentation that we can integrate spot data by integrating custom data, but I believe setting the asset type withspot_asset(1.0)
would be more elegant.Also, is there a way to set different asset types within the same asset? For instance, how can I include
spot
andlinear
for btcusdt?