-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Index option request data universe examples #1911
Add Index option request data universe examples #1911
Conversation
c3a7943
to
cfc2caa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tthank you, @baobach.
Sorry for the long wait.
Please run the C# and Pyhon codes on QC Cloud to ensure there is no bugs and the results are the same.
_option.SetFilter(u => u.IncludeWeeklys().Expiration(0, 0).Strikes(-1, 1)); | ||
|
||
// Filter the option universe by Delta. | ||
_option.SetFilter(optionFilterUniverse => optionFilterUniverse.Delta(0.25m, 0.75m)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding two universes is misleading, since users can think it is a combination of both.
This filter is not adding weeklies, and AddindexOption is not adding SPXW.
Generally, use Resolution.Minute.
if (calls.Count < 1) return; | ||
|
||
// Sorted the contracts according to their strike prices. | ||
calls = calls.OrderBy(x => x.Strike).ToList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can condense this logic to:
var call = chain.Where(contract => contract.Right == OptionRight.Call).OrderBy(x => x.Strike).FirstOrDefault();
if (call != null) Buy(call.Symbol, 1);
The Python version is good, but we should leverage C# features.
# Filter the option universe to only select 0DTE options. | ||
self._option.set_filter(lambda u: u.include_weeklys().expiration(0, 0).strikes(-1, 1)) | ||
# Filter the option universe by Delta. | ||
self._option.set_filter(lambda option_filter_universe: option_filter_universe.delta(0.25, 0.75)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue of C# version.
var expiry = chain.Max(x => x.Expiry); | ||
var atmCall = chain.Where(x => x.Expiry == expiry) | ||
.OrderBy(x => Math.Abs(x.Strike - x.UnderlyingLastPrice)) | ||
.First(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be good, but ideally we use FirstOrDefault and check for null.
if chain: | ||
# Obtain the ATM call that expires furthest (90 days). | ||
expiry = max(x.expiry for x in chain) | ||
atm_call = min(chain, key=lambda x: abs(x.strike - x.underlying_last_price)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expiry
not used. Please run C# and Python examples. They should have the same results.
foreach (var removed in changes.RemovedSecurities) | ||
{ | ||
// Liquidate the contracts that exit the universe (due to expiry). | ||
if (Portfolio[removed.Symbol].Invested) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use: removed.Invested
or we can remove this if-condition, since Liquidade does nothing if this case if the security is not invested.
Description
Securities / Asset Classes / Index Option / Requesting Data / Universes
Related Issue
closes #1901
Motivation and Context
Types of changes
Checklist:
bug-<issue#>-<description>
orfeature-<issue#>-<description>