← Back
const { findUnusualVolume } = require('../src/analysis/unusualVolume');

// Helper: generate an expiry string N days from now in YYMMDD format
function futureExpiry(daysFromNow) {
    const d = new Date(Date.now() + daysFromNow * 86400000);
    const yy = String(d.getUTCFullYear()).slice(2);
    const mm = String(d.getUTCMonth() + 1).padStart(2, '0');
    const dd = String(d.getUTCDate()).padStart(2, '0');
    return `${yy}${mm}${dd}`;
}

describe('Unusual Volume Analysis', () => {

    const spotPrices = { 'BTC': 80000 };
    const EXP = futureExpiry(14); // 14 days out — passes DTE 7-30 filter

    it('should ignore extremely high V/OI ratios if premium is under $5,000', () => {
        const mockOptions = [
            {
                symbol: `BTC-${EXP}-80000-C`,
                side: 'CALL',
                volume: 1,
                openInterest: 0,
                lastPrice: 39,
                strikePrice: 80000
            }
        ];

        const result = findUnusualVolume(mockOptions, spotPrices);

        expect(result.data.length).toBe(0);
        expect(result.count).toBe(0);
    });

    it('should flag extreme volume if premium is exactly or well over $5,000', () => {
        const mockOptions = [
            {
                symbol: `BTC-${EXP}-85000-C`,
                side: 'CALL',
                volume: 3000,
                openInterest: 50,
                lastPrice: 40,
                strikePrice: 85000
            }
        ];

        const result = findUnusualVolume(mockOptions, spotPrices);

        expect(result.data.length).toBe(1);
        expect(result.data[0].signal.severity).toBe('EXTREME');
        expect(result.data[0].premiumUsd).toBe(120000);
    });

    it('should reject options with DTE < 7 (theta burn danger)', () => {
        const shortExp = futureExpiry(3);
        const mockOptions = [
            {
                symbol: `BTC-${shortExp}-80000-C`,
                side: 'CALL',
                volume: 5000,
                openInterest: 100,
                lastPrice: 50,
                strikePrice: 80000
            }
        ];

        const result = findUnusualVolume(mockOptions, spotPrices);

        expect(result.data.length).toBe(0);
    });

    it('should reject options with DTE > 30', () => {
        const longExp = futureExpiry(60);
        const mockOptions = [
            {
                symbol: `BTC-${longExp}-80000-C`,
                side: 'CALL',
                volume: 5000,
                openInterest: 100,
                lastPrice: 50,
                strikePrice: 80000
            }
        ];

        const result = findUnusualVolume(mockOptions, spotPrices);

        expect(result.data.length).toBe(0);
    });
});

📜 Git History

06783dafix: options-screener-v2 — 9 bug fixes, 5 strategy improvements, 2 infra enhancements3 months ago
2581c69feat(ops): add winston logger, jest tests for whale analysis, and push diagnostic endpoint4 months ago
Show last diff
Loading...