Open AlexCatarino opened 2 months ago
OptionContract
object, values for Open interest, the greeks (delta, gamma etc.) and implied volatility should be made available. Below is the referenced properties that are exposed when invoking the OptionContract
object
The below files should be modified to support the, above noted, current specification
QuantConnect.Polygon/PolygonOptionChainProvider.cs
Update the REST API endpoint from /v3/reference/options/contracts
to /v3/snapshot/options/{underlyingAsset}
Proposed
var request = new RestRequest("/v3/snapshot/options/{underlyingAsset}", Method.GET).AddUrlSegment("underlyingAsset", underlying.Value);
request.AddQueryParameter("expiration_date", date.ToStringInvariant("yyyy-MM-dd"));
request.AddQueryParameter("limit", "250");
NB: When querying an index option, the value for underlyingAsset
should be prefixed with I:
.
Example: For SPX; the value for underlyingAsset
is I:SPX
This ensures that the API Response returns all required attributes when querying an index option
QuantConnect.Polygon/Rest/OptionContract.cs
All test are passed
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
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.
Expected Behavior
This data source supports open interest.
Actual Behavior
We receive the following message:
Proposed Solution
It's found in the Option Chain endpoint
/v3/snapshot/options/{underlyingAsset}
https://polygon.io/docs/options/get_v3_snapshot_options__underlyingassetReproducing the Problem
Deploy index option algorithm with polygon data provider.
Checklist
master
branch