Skip to content
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

Support multiple outputs for custom factors #1119

Merged
merged 1 commit into from Apr 21, 2016

Conversation

dmichalowicz
Copy link
Contributor

Add an optional outputs parameter to CustomFactor allowing multiple outputs to be computed and returned from a single CustomFactor, each output of which is itself a Factor.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 84.308% when pulling 233602c on multiple-factor-outputs into 675eff4 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 84.309% when pulling 835af4e on multiple-factor-outputs into 675eff4 on master.

@@ -510,6 +520,42 @@ def test_rolling_and_nonrolling(self):
),
)

def test_factor_with_multiple_outputs(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Add better test cases

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 84.309% when pulling 3fc69c1 on multiple-factor-outputs into 3f2a574 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 84.274% when pulling 3fc69c1 on multiple-factor-outputs into 3f2a574 on master.


def compute(self, today, assets, out, open, close):
out.double_open[:] = open * 2
out.double_close[:] = close * 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice API!

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 84.297% when pulling d21ece4 on multiple-factor-outputs into 3f2a574 on master.

enough outputs and that factor does not have class-level default outputs.
"""
msg = (
"{termname} requires at least two outputs, but was given "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"at least two" seems more specific than this should be?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes; I'll make RecarrayFactor support single outputs as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually meant that this might want to be at least {N}, where N is an arg, but I don't know if there are cases where we know we need more than two outputs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok. So for the purpose of RecarrayFactors as we have them it makes sense, but wouldn't hurt to be more generalizable in case we come across such a case.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.008%) to 84.263% when pulling a872419 on multiple-factor-outputs into 3f2a574 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 84.297% when pulling a872419 on multiple-factor-outputs into 3f2a574 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.06%) to 84.294% when pulling 9fce2f8 on multiple-factor-outputs into d2ab5ed on master.

def _validate(self):
super(RecarrayFactor, self)._validate()
if not self.outputs:
raise TermOutputsNotSpecified(termname=type(self).__name__)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In thinking about it, I don't think a RecarrayFactor even needs to specify any outputs. At the end of the day it acts how all other regular factors do with a single out. So this can all be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this check should be performed on the inputted factor, i.e. check that the parent's factor.outputs is not empty.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.09%) to 84.323% when pulling 6bf612b on multiple-factor-outputs into d2ab5ed on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.09%) to 84.323% when pulling bfdb648 on multiple-factor-outputs into d2ab5ed on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 84.252% when pulling 7df8544 on multiple-factor-outputs into d2ab5ed on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 84.245% when pulling fb0d521 on multiple-factor-outputs into d2ab5ed on master.

@dmichalowicz dmichalowicz changed the title WIP: Support multiple outputs for custom factors Support multiple outputs for custom factors Apr 13, 2016
class MultipleOutputs(CustomFactor):
window_length = 1
inputs = [USEquityPricing.open, USEquityPricing.close]
outputs = ['open', 'close']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want a test that exercises the behavior of passing outputs dynamically to the constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in test_custom_factor_outputs_parameter

@dmichalowicz
Copy link
Contributor Author

@ssanderson Should be ready for another look

'''
dtype = float64_dtype

def __getattr__(self, attribute_name):
if self.outputs is NotSpecified:
raise AttributeError()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be AttributeError(attribute_name).

@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 84.245% when pulling ec68d04 on multiple-factor-outputs into 842c47b on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 84.243% when pulling c4d190c on multiple-factor-outputs into 2179553 on master.

@ssanderson
Copy link
Contributor

LGTM. @dmichalowicz feel free to merge when appveyor finishes.

@dmichalowicz dmichalowicz merged commit 28ffee2 into master Apr 21, 2016
@dmichalowicz dmichalowicz deleted the multiple-factor-outputs branch April 21, 2016 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants