-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Option Strategy Filter Universe #8088
Option Strategy Filter Universe #8088
Conversation
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.
Nice! Leaving some thoughts and requests
// Select the set strike | ||
var strike = AllSymbols.OrderBy(x => Math.Abs(Underlying.Price - x.ID.StrikePrice + strikeFromAtm)) | ||
.First().ID.StrikePrice; | ||
var contracts = AllSymbols.Where(x => x.ID.StrikePrice == strike && x.ID.OptionRight == right); |
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.
Cool!
Couple of thoughts:
- Believe it's a bit sad & fragile having to duplicate the knowledge of each strategy again here, we could have a core implementation which could take a
OptionStrategyDefinition
instance for example and generically handle it there, each of these sugar names could just pass their option strategy definition to the core one and boom, we can simplify many lines and potential issues due to the duplication - The implementations seem a bit inconsistent on when using
AllSymbols
&/or the helper methodsWhere/Contracts/etc
the helper methods are overridingAllSymbols
& calling to List (sad to do it multiple times etc) -> I think we should avoid them and just useAllSymbols
but at the end of the method call ToList and override it - Just double checking, I see ur using Abs for date/strike input operations which is strange given the input could be +/- , seems if used in OrderBy it would treat +/- result in the same way which doesn't seem right?
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.
Just double checking, I see ur using Abs for date/strike input operations which is strange given the input could be +/- , seems if used in OrderBy it would treat +/- result in the same way which doesn't seem right?
Yah that was intentional. We look for the best match but not a conditional best match
{ | ||
public override void Initialize() | ||
{ | ||
_func = u => u.IncludeWeeklys().Strikes(-10, +10).Expiration(0, 180).BoxSpread(30, 5); |
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.
Isn't Expiration
filter overlapping with the daysTillExpiry
in the option strategy? For example in this example if Expiration was (30, 180) 🤔
Makes me think that daysTillExpiry
would only be used if Expiration
filter isn't used? which could mean we can push it to the end of the option strategy as an optional probably defaulting to null, maybe if Expiration
wasn't use use 30 instead as default
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.
It is intentional: Expiration
is a strict rule, but daysTillExpiry
is looking for the best match only🤔 I don't think they are mutaully exclusive.
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.
Expiration is a strict rule, but daysTillExpiry is looking for the best match only🤔
Sounds like a bug if user provides 30 daysTIllExpiry
and it can use something bellow that?
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.
.Strikes(-10, +10).Expiration(0, 180)
Let's remove this from the examples
Sounds like a bug if user provides 30 daysTIllExpiry and it can use something bellow that? nevermind 👍
Please rebase from master, the regression test interface was changed & a unit test CI bug was shipped |
var expiry = AllSymbols.OrderBy(x => Math.Abs((x.ID.Date - _lastExchangeDate.AddDays(daysTillExpiry)).Days)) | ||
.First().ID.Date; | ||
var contracts = AllSymbols.Where(x => x.ID.Date == expiry && x.ID.OptionRight == right); | ||
// Select strike price | ||
var selected = contracts.OrderBy(x => Math.Abs(x.ID.StrikePrice - Underlying.Price - strikeFromAtm)).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.
I don't think the expiration filter here is behaving as expected, take the follow example
DaysTillExpiry 4
Today 8
Contract 1 expiration date 9
Contract 2 expiration date 15
Contract 3 expiration date 20
9 - (8 + 4) => Abs(-3) ? -> HERE
15 - (8 + 4) => Abs(3) -> HERE
20 - (8 + 4) => Abs(8)
We should have 1 centralized helper method location where we handle these daysTillExpiry/strikeFromAtm and reuse them in the whole file
I'd suggest rename daysTillExpiry
to minDaysTillExpiry
and could directly use the Expiration(minDaysTillExpiry, max)
?
Description
Add helper method to filter option universe by shortlisting a particular type of option strategies
e.g.
option.SetFilter(u => u.IncludeWeeklys().Strike(-2, 2).Expiration(0, 90).IronCondor(30, 5, 10)
will return 4 contracts that best fit the criteria given and be able to form an Iron Condor.Related Issue
NA
Motivation and Context
For users that only wish to obtain certain contracts for forming an option strategy, it can reduce the number of option contract data subscribed to speed up the algorithm and avoid further filtering manually.
e.g. A single-day Iron Condor algorithm yielded a near 50% speed improvement:
.IronCondor(30, 5, 10)
filterRequires Documentation Change
How Has This Been Tested?
Types of changes
Checklist:
bug-<issue#>-<description>
orfeature-<issue#>-<description>