← Back to list

cash_carry_btc

Cash & Carry: Long spot BTC + Short perpetual BTC to collect funding. This is a delta-neutral strategy that profits from positive funding rates. When funding is high (longs pay shorts), we:

Symbol: BTC | Exchange: Bitfinex

4/6
Profitable Years
+31.0%
Total Return
50.5%
Avg Win Rate
0.11
Avg Sharpe

Year-by-Year Results

Year Return Win Rate Trades Max DD Sharpe
2020 +2.9% 48.4% 122 32.7% 0.06
2021 +27.9% 52.1% 142 18.5% 0.60
2022 -0.3% 50.9% 108 31.1% 0.00
2023 +0.4% 50.0% 60 31.0% 0.01
2024 -0.4% 50.0% 94 65.7% 0.00
2025 +0.5% 51.5% 68 31.0% 0.01

Entry Logic

See strategy file

Exit Logic

See strategy file

Source Code

"""
Strategy: cash_carry_btc
========================
Cash & Carry: Long spot BTC + Short perpetual BTC to collect funding.

This is a delta-neutral strategy that profits from positive funding rates.
When funding is high (longs pay shorts), we:
1. Buy spot BTC as hedge
2. Short perpetual BTC to collect funding

The position is market-neutral, so we profit purely from funding payments.

Entry: Funding APR > 15%
Exit: Funding APR < 5%
"""
import sys
sys.path.insert(0, '/root/trade_rules')


def init_strategy():
    return {
        'name': 'cash_carry_btc',
        'subscriptions': [
            {'symbol': 'tBTCUSD', 'exchange': 'bitfinex', 'timeframe': '4h'},
            {'symbol': 'tBTCF0:USTF0', 'exchange': 'bitfinex', 'timeframe': '4h'},
        ],
        'parameters': {
            'funding_entry_threshold': 0.15,  # 15% APR
            'funding_exit_threshold': 0.05,   # 5% APR
        }
    }


def process_time_step(ctx):
    spot_key = ('tBTCUSD', 'bitfinex')
    perp_key = ('tBTCF0:USTF0', 'bitfinex')

    perp_bars = ctx['bars'].get(perp_key, [])
    i = ctx['i']
    positions = ctx['positions']
    params = ctx['parameters']

    if not perp_bars or i >= len(perp_bars):
        return []

    # Get current funding rate from perp bar
    funding_apr = perp_bars[i].funding_apr

    actions = []
    has_spot = spot_key in positions
    has_perp = perp_key in positions

    # Entry: high funding rate - go delta neutral
    if funding_apr > params['funding_entry_threshold']:
        if not has_spot:
            actions.append({
                'action': 'open_long',
                'symbol': 'tBTCUSD',
                'exchange': 'bitfinex',
                'size': 1.0,
            })
        if not has_perp:
            actions.append({
                'action': 'open_short',
                'symbol': 'tBTCF0:USTF0',
                'exchange': 'bitfinex',
                'size': 1.0,
            })

    # Exit: low funding - close both legs
    elif funding_apr < params['funding_exit_threshold']:
        if has_spot:
            actions.append({
                'action': 'close_long',
                'symbol': 'tBTCUSD',
                'exchange': 'bitfinex',
            })
        if has_perp:
            actions.append({
                'action': 'close_short',
                'symbol': 'tBTCF0:USTF0',
                'exchange': 'bitfinex',
            })

    return actions