-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Adding ChangeInstrument op #1005
Conversation
Adding Change instrument OP. This op allows one to use features of a different instrument.
update parse_field to accommodate ChangeInstrument
qlib/data/ops.py
Outdated
def __str__(self): | ||
return "{}({},{})".format(type(self).__name__, self.instrument, self.feature) | ||
|
||
def load(self, instrument, start_index, end_index, freq): |
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.
super().load(self, instrument, start_index, end_index, *args)
Will it better to call the method from super class directly?
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.
Thanks for the comments. I was trying to use self.instrument as part of the cache key in the load function, since this op is likely used to add some features from frequently used instruments such as market index or sector index. In this case, rewriting the load function with self.instrument as part of cache args enables the caching is done with the changed instrument, rather than the original instrument, this should be more efficient than using super().load(self, instrument, start_index, end_index, *args).
Another way to achieve the same caching performance may be to call super().load(self, self.instrument, start_index, end_index, *args). This should do the trick without changing the _load_internal function, 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.
Please let me know how you think and I can revise it. Thanks!
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.
Yes.
I think this is a more concise way to implement.
Another way to achieve the same caching performance may be to call super().load(self, self.instrument, start_index, end_index, *args). This should do the trick without changing the _load_internal function, 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.
@wan9c9
Hi, did you encounter any problems when implementing the concise version ?
qlib/data/ops.py
Outdated
@@ -32,6 +32,91 @@ | |||
|
|||
np.seterr(invalid="ignore") | |||
|
|||
|
|||
#################### Change instrument ######################## |
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 duplicates with the docs string.
I think we can keep only the one in the docstring.
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.
Yes, sure. I wrote the first paragraph to motivate the class, and it should be fine to keep only those in the doc string and I'll update 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.
Hi, @wan9c9 did you fix this ?
Thanks
Hi, @wan9c9 |
Hi, @wan9c9 BTW, please fix the error reported by CI |
Propose test
@wan9c9 did you encounter any problems when fix the remained issues in the comments? |
@you-n-g, sorry for the delays, I'm busy with other stuff and couldn't commit the revision as I also messed up the code. I did wrote some tests, which couldn't pass the test. The test code are show below. class TestOperatorDataSetting(TestOperatorData):
if name == "main": Could you please take a look? Thanks! |
@wan9c9 I added your test case here and fix a bug. Please merge it |
@you-n-g, looks like the link https://github.com/wan9c9/qlib/pull/4wan9c9 doesn't work. Can you please send a valid link and I'll double check? Thanks! |
Sorry I mixed your ID and the link. Here is the right link wan9c9#4 |
@wan9c9 It looks great now! |
* add ChangeInstrument to ops Adding Change instrument OP. This op allows one to use features of a different instrument. * Update __init__.py update parse_field to accommodate ChangeInstrument * Propose test * Add test case and fix bug * Update ops.py * Update ops.py * simplify the operator further * implement abstract method * fix arg bug * clean test Co-authored-by: Young <afe.young@gmail.com> Co-authored-by: you-n-g <you-n-g@users.noreply.github.com>
Description
The ChangeInstrument allows using the features of another instrument.
Motivation and Context
How Has This Been Tested?
pytest qlib/tests/test_all_pipeline.py
under upper directory ofqlib
.Screenshots of Test Results (if appropriate):
Types of changes