0bps

Strategy vault / Other

Derbit Option Backtest Test

- Simulate Deribit options trading logic - Support buying and selling options - Because exercise needs to be combined with the futures price, exercise is not supported for the time being. Real orders can be exercised…

JavaScriptOther
Author
发明者量化
Complexity
Starter · 49 lines
Parameters
0
Backtest bar
1h · intraday
Tested on
BTC/USD · futures
  • Simulate Deribit options trading logic
  • Support buying and selling options
  • Because exercise needs to be combined with the futures price, exercise is not supported for the time being. Real orders can be exercised through the IO interface.

Source JavaScript

/*backtest
start: 2020-06-08 00:00:00
end: 2020-08-05 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Deribit","currency":"BTC_USD"}]
*/

function main() {
    exchange.SetContractType('BTC-7AUG20-12750-C');
    var ticker = exchange.GetTicker();
    Log(ticker);
    exchange.SetDirection("sell");
    var orderId = exchange.Sell(ticker.Sell, 10);
    Log(exchange.GetAccount());
    Log(exchange.GetOrders());
    exchange.CancelOrder(orderId);
    Log(exchange.GetAccount());
    
    
    exchange.Sell(ticker.Buy, 10);
    Log(exchange.GetAccount());
    Log(exchange.GetPosition());
    ticker = exchange.GetTicker();
    exchange.SetDirection("closesell");
    exchange.Buy(ticker.Sell, 10);
    Log(exchange.GetAccount());
    Log(exchange.GetPosition());
    
    
    
    ticker = exchange.GetTicker();
    Log(ticker);
    exchange.SetDirection("buy");
    orderId = exchange.Buy(ticker.Buy, 10);
    Log(exchange.GetAccount());
    exchange.CancelOrder(orderId);
    Log(exchange.GetAccount());
    
    
    exchange.Buy(ticker.Sell, 10);
    Log(exchange.GetAccount());
    Log(exchange.GetPosition());
    ticker = exchange.GetTicker();
    exchange.SetDirection("closebuy");
    exchange.Sell(ticker.Buy, 10);
    Log(exchange.GetAccount());
    Log(exchange.GetPosition());
}

Published by 发明者量化 on the FMZ strategy square · last modified 2020-08-07. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Derbit-Option-Backtest-Test.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open