Overall Statistics
Total Orders
2
Average Win
1357.28%
Average Loss
0%
Compounding Annual Return
906612724.775%
Drawdown
1.700%
Expectancy
0
Start Equity
1000000
End Equity
14572747.53
Net Profit
1357.275%
Sharpe Ratio
2.73906359336249E+20
Sortino Ratio
1.56371013696892E+23
Probabilistic Sharpe Ratio
84.551%
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
27.421
Annual Variance
751.887
Information Ratio
2.7390635933624877E+20
Tracking Error
27.421
Treynor Ratio
0
Total Fees
$2.47
Estimated Strategy Capacity
$240000000000.00
Lowest Capacity Asset
6J UNFBZUGKR5KX
Portfolio Turnover
1.73%
Drawdown Recovery
17
from AlgorithmImports import *


class JpyDelistingDataRepro(QCAlgorithm):
    """
    Minimal reproduction of ticket 215474576755380.

    Subscribes to /6J with the SAME continuous-future settings the customer
    used (Daily resolution, OPEN_INTEREST mapping, BACKWARDS_RATIO
    normalization, contract_depth_offset=0). Buys 1 contract early in May
    2010 and lets the delisting liquidation fire on 2010-06-14/15.

    Logs every daily bar that arrives so we can see the bad price tick on
    the contract's last trading day. If the data is correct, every Close
    will sit in ~0.010-0.012 (USD per JPY). The customer reports a fill
    at 1.0964 -- exactly 100x.
    """

    def initialize(self):
        self.set_start_date(2010, 5, 1)
        self.set_end_date(2010, 6, 30)
        self.set_cash(1_000_000)

        self.set_brokerage_model(BrokerageName.INTERACTIVE_BROKERS_BROKERAGE, AccountType.MARGIN)

        self.future = self.add_future(
            "6J",
            resolution=Resolution.DAILY,
            data_mapping_mode=DataMappingMode.OPEN_INTEREST,
            data_normalization_mode=DataNormalizationMode.BACKWARDS_RATIO,
            contract_depth_offset=0,
        )

        self._bought = False

    def on_data(self, data):
        for kvp in data.bars:
            sym = kvp.key
            bar = kvp.value
            tag = "ALERT_100X" if bar.close > 0.5 else ""
            self.log(
                f"DAILY sym={sym.value} t={self.time.isoformat()} "
                f"O={bar.open} H={bar.high} L={bar.low} C={bar.close} {tag}"
            )

        if not self._bought:
            mapped = self.securities[self.future.symbol].mapped
            if mapped is not None and mapped in self.securities and self.securities[mapped].price > 0:
                self.market_order(mapped, 1)
                self._bought = True
                self.log(f"BUY {mapped.value} at price={self.securities[mapped].price}")

    def on_order_event(self, order_event):
        if order_event.status == OrderStatus.FILLED:
            order = self.transactions.get_order_by_id(order_event.order_id)
            tag = order.tag if order else ""
            self.log(
                f"FILL sym={order_event.symbol.value} qty={order_event.fill_quantity} "
                f"price={order_event.fill_price} tag='{tag}'"
            )