QuantConnect / Lean.DataSource.Polygon

LEAN Polygon Data Source
3 stars 5 forks source link

Open Interest Support #12

Open AlexCatarino opened 2 months ago

AlexCatarino commented 2 months ago

Expected Behavior

This data source supports open interest.

Actual Behavior

We receive the following message:

“Warning: USA IndexOption OpenInterest data not supported. Please consider reviewing the data providers selection.” 

Proposed Solution

It's found in the Option Chain endpoint /v3/snapshot/options/{underlyingAsset} https://polygon.io/docs/options/get_v3_snapshot_options__underlyingasset

Reproducing the Problem

Deploy index option algorithm with polygon data provider.

Checklist

endk17 commented 2 months ago

Specification

Is there the means to query for open interest value when using Polygon datasets ?

Current

Proposed

The below files should be modified to support the, above noted, current specification

endk17 commented 2 months ago

Hi @AlexCatarino

Can you and or your support team please assist with getting my PR reviewed and approved.

ref: https://github.com/QuantConnect/Lean.DataSource.Polygon/pull/15

Many thanks Enda

ArthurAsenheimer commented 1 month ago

FYI, the following algorithm reproduces the bug:

# region imports
from AlgorithmImports import *
# endregion

class IndexOptionAlgorithm(QCAlgorithm):
    def initialize(self):
        self.set_start_date(2024, 1, 1) 
        self.set_end_date(2024, 5, 1)
        self.set_cash(100000)
        self.spx = self.add_index('SPX') 
        self.spx_option = self.add_index_option(self.spx.symbol) 
        self.spx_option.set_filter(-1, 1, 0, 100)  

    def on_data(self, data: Slice):
        if self.algorithm_mode is not AlgorithmMode.LIVE:
            return 
        chain = data.option_chains.get(self.spx_option.symbol)
        if not chain:
            return 
        for contract in chain: 
            self.log(f"{contract.symbol}| open interest: {contract.open_interest}; delta: {contract.greeks.delta}; implied volatility: {contract.implied_volatility}.") 

Excerpt from logs when using QC + Polygon as data providers in live mode:

2024-05-10 17:37:48 Launching analysis for L-3ffd0d19687922fd9e89e48e6bdf8fea with LEAN Engine v2.5.0.0.16423
2024-05-10 17:37:54 Paper Brokerage account base currency: USD
2024-05-10 17:38:08 Warning: usa IndexOption OpenInterest data not supported. Please consider reviewing the data providers selection.
2024-05-10 17:39:00 SPX   240517C05215000| open interest: 0.0; delta: 0.532253383735248; implied volatility: 0.0920031928428969.
2024-05-10 17:39:00 SPX   240517C05220000| open interest: 0.0; delta: 0.505825425148433; implied volatility: 0.0918866720162672.
2024-05-10 17:39:00 SPX   240517P05215000| open interest: 0.0; delta: -0.470339109238199; implied volatility: 0.102137279946327.
2024-05-10 17:39:00 SPX   240517P05220000| open interest: 0.0; delta: -0.49415161757284; implied volatility: 0.101699571257173.
2024-05-10 17:39:00 SPX   240621C05215000| open interest: 0.0; delta: 0.558908042608909; implied volatility: 0.109208822620727.
2024-05-10 17:39:00 SPX   240621C05220000| open interest: 0.0; delta: 0.549011714694276; implied volatility: 0.108904994834179.