repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
quantopian/zipline | zipline/finance/metrics/metric.py | _ClassicRiskMetrics.risk_metric_period | def risk_metric_period(cls,
start_session,
end_session,
algorithm_returns,
benchmark_returns,
algorithm_leverages):
"""
Creates a dictionary representing the state of th... | python | def risk_metric_period(cls,
start_session,
end_session,
algorithm_returns,
benchmark_returns,
algorithm_leverages):
"""
Creates a dictionary representing the state of th... | [
"def",
"risk_metric_period",
"(",
"cls",
",",
"start_session",
",",
"end_session",
",",
"algorithm_returns",
",",
"benchmark_returns",
",",
"algorithm_leverages",
")",
":",
"algorithm_returns",
"=",
"algorithm_returns",
"[",
"(",
"algorithm_returns",
".",
"index",
">=... | Creates a dictionary representing the state of the risk report.
Parameters
----------
start_session : pd.Timestamp
Start of period (inclusive) to produce metrics on
end_session : pd.Timestamp
End of period (inclusive) to produce metrics on
algorithm_retur... | [
"Creates",
"a",
"dictionary",
"representing",
"the",
"state",
"of",
"the",
"risk",
"report",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/finance/metrics/metric.py#L559-L666 | train |
quantopian/zipline | zipline/assets/roll_finder.py | RollFinder._get_active_contract_at_offset | def _get_active_contract_at_offset(self, root_symbol, dt, offset):
"""
For the given root symbol, find the contract that is considered active
on a specific date at a specific offset.
"""
oc = self.asset_finder.get_ordered_contracts(root_symbol)
session = self.trading_cale... | python | def _get_active_contract_at_offset(self, root_symbol, dt, offset):
"""
For the given root symbol, find the contract that is considered active
on a specific date at a specific offset.
"""
oc = self.asset_finder.get_ordered_contracts(root_symbol)
session = self.trading_cale... | [
"def",
"_get_active_contract_at_offset",
"(",
"self",
",",
"root_symbol",
",",
"dt",
",",
"offset",
")",
":",
"oc",
"=",
"self",
".",
"asset_finder",
".",
"get_ordered_contracts",
"(",
"root_symbol",
")",
"session",
"=",
"self",
".",
"trading_calendar",
".",
"... | For the given root symbol, find the contract that is considered active
on a specific date at a specific offset. | [
"For",
"the",
"given",
"root",
"symbol",
"find",
"the",
"contract",
"that",
"is",
"considered",
"active",
"on",
"a",
"specific",
"date",
"at",
"a",
"specific",
"offset",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/assets/roll_finder.py#L33-L45 | train |
quantopian/zipline | zipline/assets/roll_finder.py | RollFinder.get_contract_center | def get_contract_center(self, root_symbol, dt, offset):
"""
Parameters
----------
root_symbol : str
The root symbol for the contract chain.
dt : Timestamp
The datetime for which to retrieve the current contract.
offset : int
The offset ... | python | def get_contract_center(self, root_symbol, dt, offset):
"""
Parameters
----------
root_symbol : str
The root symbol for the contract chain.
dt : Timestamp
The datetime for which to retrieve the current contract.
offset : int
The offset ... | [
"def",
"get_contract_center",
"(",
"self",
",",
"root_symbol",
",",
"dt",
",",
"offset",
")",
":",
"return",
"self",
".",
"_get_active_contract_at_offset",
"(",
"root_symbol",
",",
"dt",
",",
"offset",
")"
] | Parameters
----------
root_symbol : str
The root symbol for the contract chain.
dt : Timestamp
The datetime for which to retrieve the current contract.
offset : int
The offset from the primary contract.
0 is the primary, 1 is the secondary,... | [
"Parameters",
"----------",
"root_symbol",
":",
"str",
"The",
"root",
"symbol",
"for",
"the",
"contract",
"chain",
".",
"dt",
":",
"Timestamp",
"The",
"datetime",
"for",
"which",
"to",
"retrieve",
"the",
"current",
"contract",
".",
"offset",
":",
"int",
"The... | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/assets/roll_finder.py#L47-L64 | train |
quantopian/zipline | zipline/assets/roll_finder.py | RollFinder.get_rolls | def get_rolls(self, root_symbol, start, end, offset):
"""
Get the rolls, i.e. the session at which to hop from contract to
contract in the chain.
Parameters
----------
root_symbol : str
The root symbol for which to calculate rolls.
start : Timestamp
... | python | def get_rolls(self, root_symbol, start, end, offset):
"""
Get the rolls, i.e. the session at which to hop from contract to
contract in the chain.
Parameters
----------
root_symbol : str
The root symbol for which to calculate rolls.
start : Timestamp
... | [
"def",
"get_rolls",
"(",
"self",
",",
"root_symbol",
",",
"start",
",",
"end",
",",
"offset",
")",
":",
"oc",
"=",
"self",
".",
"asset_finder",
".",
"get_ordered_contracts",
"(",
"root_symbol",
")",
"front",
"=",
"self",
".",
"_get_active_contract_at_offset",
... | Get the rolls, i.e. the session at which to hop from contract to
contract in the chain.
Parameters
----------
root_symbol : str
The root symbol for which to calculate rolls.
start : Timestamp
Start of the date range.
end : Timestamp
En... | [
"Get",
"the",
"rolls",
"i",
".",
"e",
".",
"the",
"session",
"at",
"which",
"to",
"hop",
"from",
"contract",
"to",
"contract",
"in",
"the",
"chain",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/assets/roll_finder.py#L66-L137 | train |
quantopian/zipline | zipline/assets/roll_finder.py | VolumeRollFinder._active_contract | def _active_contract(self, oc, front, back, dt):
r"""
Return the active contract based on the previous trading day's volume.
In the rare case that a double volume switch occurs we treat the first
switch as the roll. Take the following case for example:
| +++++ _____... | python | def _active_contract(self, oc, front, back, dt):
r"""
Return the active contract based on the previous trading day's volume.
In the rare case that a double volume switch occurs we treat the first
switch as the roll. Take the following case for example:
| +++++ _____... | [
"def",
"_active_contract",
"(",
"self",
",",
"oc",
",",
"front",
",",
"back",
",",
"dt",
")",
":",
"front_contract",
"=",
"oc",
".",
"sid_to_contract",
"[",
"front",
"]",
".",
"contract",
"back_contract",
"=",
"oc",
".",
"sid_to_contract",
"[",
"back",
"... | r"""
Return the active contract based on the previous trading day's volume.
In the rare case that a double volume switch occurs we treat the first
switch as the roll. Take the following case for example:
| +++++ _____
| + __ / <--- 'G'
| ... | [
"r",
"Return",
"the",
"active",
"contract",
"based",
"on",
"the",
"previous",
"trading",
"day",
"s",
"volume",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/assets/roll_finder.py#L170-L241 | train |
quantopian/zipline | zipline/assets/roll_finder.py | VolumeRollFinder.get_contract_center | def get_contract_center(self, root_symbol, dt, offset):
"""
Parameters
----------
root_symbol : str
The root symbol for the contract chain.
dt : Timestamp
The datetime for which to retrieve the current contract.
offset : int
The offset ... | python | def get_contract_center(self, root_symbol, dt, offset):
"""
Parameters
----------
root_symbol : str
The root symbol for the contract chain.
dt : Timestamp
The datetime for which to retrieve the current contract.
offset : int
The offset ... | [
"def",
"get_contract_center",
"(",
"self",
",",
"root_symbol",
",",
"dt",
",",
"offset",
")",
":",
"# When determining the center contract on a specific day using volume",
"# rolls, simply picking the contract with the highest volume could",
"# cause flip-flopping between active contract... | Parameters
----------
root_symbol : str
The root symbol for the contract chain.
dt : Timestamp
The datetime for which to retrieve the current contract.
offset : int
The offset from the primary contract.
0 is the primary, 1 is the secondary,... | [
"Parameters",
"----------",
"root_symbol",
":",
"str",
"The",
"root",
"symbol",
"for",
"the",
"contract",
"chain",
".",
"dt",
":",
"Timestamp",
"The",
"datetime",
"for",
"which",
"to",
"retrieve",
"the",
"current",
"contract",
".",
"offset",
":",
"int",
"The... | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/assets/roll_finder.py#L243-L276 | train |
quantopian/zipline | zipline/lib/adjusted_array.py | _normalize_array | def _normalize_array(data, missing_value):
"""
Coerce buffer data for an AdjustedArray into a standard scalar
representation, returning the coerced array and a dict of argument to pass
to np.view to use when providing a user-facing view of the underlying data.
- float* data is coerced to float64 wi... | python | def _normalize_array(data, missing_value):
"""
Coerce buffer data for an AdjustedArray into a standard scalar
representation, returning the coerced array and a dict of argument to pass
to np.view to use when providing a user-facing view of the underlying data.
- float* data is coerced to float64 wi... | [
"def",
"_normalize_array",
"(",
"data",
",",
"missing_value",
")",
":",
"if",
"isinstance",
"(",
"data",
",",
"LabelArray",
")",
":",
"return",
"data",
",",
"{",
"}",
"data_dtype",
"=",
"data",
".",
"dtype",
"if",
"data_dtype",
"in",
"BOOL_DTYPES",
":",
... | Coerce buffer data for an AdjustedArray into a standard scalar
representation, returning the coerced array and a dict of argument to pass
to np.view to use when providing a user-facing view of the underlying data.
- float* data is coerced to float64 with viewtype float64.
- int32, int64, and uint32 are... | [
"Coerce",
"buffer",
"data",
"for",
"an",
"AdjustedArray",
"into",
"a",
"standard",
"scalar",
"representation",
"returning",
"the",
"coerced",
"array",
"and",
"a",
"dict",
"of",
"argument",
"to",
"pass",
"to",
"np",
".",
"view",
"to",
"use",
"when",
"providin... | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/lib/adjusted_array.py#L84-L136 | train |
quantopian/zipline | zipline/lib/adjusted_array.py | _merge_simple | def _merge_simple(adjustment_lists, front_idx, back_idx):
"""
Merge lists of new and existing adjustments for a given index by appending
or prepending new adjustments to existing adjustments.
Notes
-----
This method is meant to be used with ``toolz.merge_with`` to merge
adjustment mappings.... | python | def _merge_simple(adjustment_lists, front_idx, back_idx):
"""
Merge lists of new and existing adjustments for a given index by appending
or prepending new adjustments to existing adjustments.
Notes
-----
This method is meant to be used with ``toolz.merge_with`` to merge
adjustment mappings.... | [
"def",
"_merge_simple",
"(",
"adjustment_lists",
",",
"front_idx",
",",
"back_idx",
")",
":",
"if",
"len",
"(",
"adjustment_lists",
")",
"==",
"1",
":",
"return",
"list",
"(",
"adjustment_lists",
"[",
"0",
"]",
")",
"else",
":",
"return",
"adjustment_lists",... | Merge lists of new and existing adjustments for a given index by appending
or prepending new adjustments to existing adjustments.
Notes
-----
This method is meant to be used with ``toolz.merge_with`` to merge
adjustment mappings. In case of a collision ``adjustment_lists`` contains
two lists, e... | [
"Merge",
"lists",
"of",
"new",
"and",
"existing",
"adjustments",
"for",
"a",
"given",
"index",
"by",
"appending",
"or",
"prepending",
"new",
"adjustments",
"to",
"existing",
"adjustments",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/lib/adjusted_array.py#L139-L170 | train |
quantopian/zipline | zipline/lib/adjusted_array.py | ensure_ndarray | def ensure_ndarray(ndarray_or_adjusted_array):
"""
Return the input as a numpy ndarray.
This is a no-op if the input is already an ndarray. If the input is an
adjusted_array, this extracts a read-only view of its internal data buffer.
Parameters
----------
ndarray_or_adjusted_array : nump... | python | def ensure_ndarray(ndarray_or_adjusted_array):
"""
Return the input as a numpy ndarray.
This is a no-op if the input is already an ndarray. If the input is an
adjusted_array, this extracts a read-only view of its internal data buffer.
Parameters
----------
ndarray_or_adjusted_array : nump... | [
"def",
"ensure_ndarray",
"(",
"ndarray_or_adjusted_array",
")",
":",
"if",
"isinstance",
"(",
"ndarray_or_adjusted_array",
",",
"ndarray",
")",
":",
"return",
"ndarray_or_adjusted_array",
"elif",
"isinstance",
"(",
"ndarray_or_adjusted_array",
",",
"AdjustedArray",
")",
... | Return the input as a numpy ndarray.
This is a no-op if the input is already an ndarray. If the input is an
adjusted_array, this extracts a read-only view of its internal data buffer.
Parameters
----------
ndarray_or_adjusted_array : numpy.ndarray | zipline.data.adjusted_array
Returns
--... | [
"Return",
"the",
"input",
"as",
"a",
"numpy",
"ndarray",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/lib/adjusted_array.py#L345-L368 | train |
quantopian/zipline | zipline/lib/adjusted_array.py | _check_window_params | def _check_window_params(data, window_length):
"""
Check that a window of length `window_length` is well-defined on `data`.
Parameters
----------
data : np.ndarray[ndim=2]
The array of data to check.
window_length : int
Length of the desired window.
Returns
-------
... | python | def _check_window_params(data, window_length):
"""
Check that a window of length `window_length` is well-defined on `data`.
Parameters
----------
data : np.ndarray[ndim=2]
The array of data to check.
window_length : int
Length of the desired window.
Returns
-------
... | [
"def",
"_check_window_params",
"(",
"data",
",",
"window_length",
")",
":",
"if",
"window_length",
"<",
"1",
":",
"raise",
"WindowLengthNotPositive",
"(",
"window_length",
"=",
"window_length",
")",
"if",
"window_length",
">",
"data",
".",
"shape",
"[",
"0",
"... | Check that a window of length `window_length` is well-defined on `data`.
Parameters
----------
data : np.ndarray[ndim=2]
The array of data to check.
window_length : int
Length of the desired window.
Returns
-------
None
Raises
------
WindowLengthNotPositive
... | [
"Check",
"that",
"a",
"window",
"of",
"length",
"window_length",
"is",
"well",
"-",
"defined",
"on",
"data",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/lib/adjusted_array.py#L371-L400 | train |
quantopian/zipline | zipline/lib/adjusted_array.py | AdjustedArray.update_adjustments | def update_adjustments(self, adjustments, method):
"""
Merge ``adjustments`` with existing adjustments, handling index
collisions according to ``method``.
Parameters
----------
adjustments : dict[int -> list[Adjustment]]
The mapping of row indices to lists of... | python | def update_adjustments(self, adjustments, method):
"""
Merge ``adjustments`` with existing adjustments, handling index
collisions according to ``method``.
Parameters
----------
adjustments : dict[int -> list[Adjustment]]
The mapping of row indices to lists of... | [
"def",
"update_adjustments",
"(",
"self",
",",
"adjustments",
",",
"method",
")",
":",
"try",
":",
"merge_func",
"=",
"_merge_methods",
"[",
"method",
"]",
"except",
"KeyError",
":",
"raise",
"ValueError",
"(",
"\"Invalid merge method %s\\n\"",
"\"Valid methods are:... | Merge ``adjustments`` with existing adjustments, handling index
collisions according to ``method``.
Parameters
----------
adjustments : dict[int -> list[Adjustment]]
The mapping of row indices to lists of adjustments that should be
appended to existing adjustment... | [
"Merge",
"adjustments",
"with",
"existing",
"adjustments",
"handling",
"index",
"collisions",
"according",
"to",
"method",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/lib/adjusted_array.py#L209-L236 | train |
quantopian/zipline | zipline/lib/adjusted_array.py | AdjustedArray._iterator_type | def _iterator_type(self):
"""
The iterator produced when `traverse` is called on this Array.
"""
if isinstance(self._data, LabelArray):
return LabelWindow
return CONCRETE_WINDOW_TYPES[self._data.dtype] | python | def _iterator_type(self):
"""
The iterator produced when `traverse` is called on this Array.
"""
if isinstance(self._data, LabelArray):
return LabelWindow
return CONCRETE_WINDOW_TYPES[self._data.dtype] | [
"def",
"_iterator_type",
"(",
"self",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"_data",
",",
"LabelArray",
")",
":",
"return",
"LabelWindow",
"return",
"CONCRETE_WINDOW_TYPES",
"[",
"self",
".",
"_data",
".",
"dtype",
"]"
] | The iterator produced when `traverse` is called on this Array. | [
"The",
"iterator",
"produced",
"when",
"traverse",
"is",
"called",
"on",
"this",
"Array",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/lib/adjusted_array.py#L253-L259 | train |
quantopian/zipline | zipline/lib/adjusted_array.py | AdjustedArray.traverse | def traverse(self,
window_length,
offset=0,
perspective_offset=0):
"""
Produce an iterator rolling windows rows over our data.
Each emitted window will have `window_length` rows.
Parameters
----------
window_length : int... | python | def traverse(self,
window_length,
offset=0,
perspective_offset=0):
"""
Produce an iterator rolling windows rows over our data.
Each emitted window will have `window_length` rows.
Parameters
----------
window_length : int... | [
"def",
"traverse",
"(",
"self",
",",
"window_length",
",",
"offset",
"=",
"0",
",",
"perspective_offset",
"=",
"0",
")",
":",
"data",
"=",
"self",
".",
"_data",
".",
"copy",
"(",
")",
"_check_window_params",
"(",
"data",
",",
"window_length",
")",
"retur... | Produce an iterator rolling windows rows over our data.
Each emitted window will have `window_length` rows.
Parameters
----------
window_length : int
The number of rows in each emitted window.
offset : int, optional
Number of rows to skip before the first... | [
"Produce",
"an",
"iterator",
"rolling",
"windows",
"rows",
"over",
"our",
"data",
".",
"Each",
"emitted",
"window",
"will",
"have",
"window_length",
"rows",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/lib/adjusted_array.py#L261-L289 | train |
quantopian/zipline | zipline/lib/adjusted_array.py | AdjustedArray.inspect | def inspect(self):
"""
Return a string representation of the data stored in this array.
"""
return dedent(
"""\
Adjusted Array ({dtype}):
Data:
{data!r}
Adjustments:
{adjustments}
"""
).format(
... | python | def inspect(self):
"""
Return a string representation of the data stored in this array.
"""
return dedent(
"""\
Adjusted Array ({dtype}):
Data:
{data!r}
Adjustments:
{adjustments}
"""
).format(
... | [
"def",
"inspect",
"(",
"self",
")",
":",
"return",
"dedent",
"(",
"\"\"\"\\\n Adjusted Array ({dtype}):\n\n Data:\n {data!r}\n\n Adjustments:\n {adjustments}\n \"\"\"",
")",
".",
"format",
"(",
"dtype",
"=",
"self",
... | Return a string representation of the data stored in this array. | [
"Return",
"a",
"string",
"representation",
"of",
"the",
"data",
"stored",
"in",
"this",
"array",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/lib/adjusted_array.py#L291-L309 | train |
quantopian/zipline | zipline/lib/adjusted_array.py | AdjustedArray.update_labels | def update_labels(self, func):
"""
Map a function over baseline and adjustment values in place.
Note that the baseline data values must be a LabelArray.
"""
if not isinstance(self.data, LabelArray):
raise TypeError(
'update_labels only supported if da... | python | def update_labels(self, func):
"""
Map a function over baseline and adjustment values in place.
Note that the baseline data values must be a LabelArray.
"""
if not isinstance(self.data, LabelArray):
raise TypeError(
'update_labels only supported if da... | [
"def",
"update_labels",
"(",
"self",
",",
"func",
")",
":",
"if",
"not",
"isinstance",
"(",
"self",
".",
"data",
",",
"LabelArray",
")",
":",
"raise",
"TypeError",
"(",
"'update_labels only supported if data is of type LabelArray.'",
")",
"# Map the baseline values.",... | Map a function over baseline and adjustment values in place.
Note that the baseline data values must be a LabelArray. | [
"Map",
"a",
"function",
"over",
"baseline",
"and",
"adjustment",
"values",
"in",
"place",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/lib/adjusted_array.py#L311-L328 | train |
quantopian/zipline | zipline/finance/controls.py | TradingControl.handle_violation | def handle_violation(self, asset, amount, datetime, metadata=None):
"""
Handle a TradingControlViolation, either by raising or logging and
error with information about the failure.
If dynamic information should be displayed as well, pass it in via
`metadata`.
"""
... | python | def handle_violation(self, asset, amount, datetime, metadata=None):
"""
Handle a TradingControlViolation, either by raising or logging and
error with information about the failure.
If dynamic information should be displayed as well, pass it in via
`metadata`.
"""
... | [
"def",
"handle_violation",
"(",
"self",
",",
"asset",
",",
"amount",
",",
"datetime",
",",
"metadata",
"=",
"None",
")",
":",
"constraint",
"=",
"self",
".",
"_constraint_msg",
"(",
"metadata",
")",
"if",
"self",
".",
"on_error",
"==",
"'fail'",
":",
"ra... | Handle a TradingControlViolation, either by raising or logging and
error with information about the failure.
If dynamic information should be displayed as well, pass it in via
`metadata`. | [
"Handle",
"a",
"TradingControlViolation",
"either",
"by",
"raising",
"or",
"logging",
"and",
"error",
"with",
"information",
"about",
"the",
"failure",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/finance/controls.py#L79-L99 | train |
quantopian/zipline | zipline/finance/controls.py | MaxOrderCount.validate | def validate(self,
asset,
amount,
portfolio,
algo_datetime,
algo_current_data):
"""
Fail if we've already placed self.max_count orders today.
"""
algo_date = algo_datetime.date()
# Reset order c... | python | def validate(self,
asset,
amount,
portfolio,
algo_datetime,
algo_current_data):
"""
Fail if we've already placed self.max_count orders today.
"""
algo_date = algo_datetime.date()
# Reset order c... | [
"def",
"validate",
"(",
"self",
",",
"asset",
",",
"amount",
",",
"portfolio",
",",
"algo_datetime",
",",
"algo_current_data",
")",
":",
"algo_date",
"=",
"algo_datetime",
".",
"date",
"(",
")",
"# Reset order count if it's a new day.",
"if",
"self",
".",
"curre... | Fail if we've already placed self.max_count orders today. | [
"Fail",
"if",
"we",
"ve",
"already",
"placed",
"self",
".",
"max_count",
"orders",
"today",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/finance/controls.py#L119-L137 | train |
quantopian/zipline | zipline/finance/controls.py | RestrictedListOrder.validate | def validate(self,
asset,
amount,
portfolio,
algo_datetime,
algo_current_data):
"""
Fail if the asset is in the restricted_list.
"""
if self.restrictions.is_restricted(asset, algo_datetime):
... | python | def validate(self,
asset,
amount,
portfolio,
algo_datetime,
algo_current_data):
"""
Fail if the asset is in the restricted_list.
"""
if self.restrictions.is_restricted(asset, algo_datetime):
... | [
"def",
"validate",
"(",
"self",
",",
"asset",
",",
"amount",
",",
"portfolio",
",",
"algo_datetime",
",",
"algo_current_data",
")",
":",
"if",
"self",
".",
"restrictions",
".",
"is_restricted",
"(",
"asset",
",",
"algo_datetime",
")",
":",
"self",
".",
"ha... | Fail if the asset is in the restricted_list. | [
"Fail",
"if",
"the",
"asset",
"is",
"in",
"the",
"restricted_list",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/finance/controls.py#L154-L164 | train |
quantopian/zipline | zipline/finance/controls.py | MaxOrderSize.validate | def validate(self,
asset,
amount,
portfolio,
algo_datetime,
algo_current_data):
"""
Fail if the magnitude of the given order exceeds either self.max_shares
or self.max_notional.
"""
if self.asse... | python | def validate(self,
asset,
amount,
portfolio,
algo_datetime,
algo_current_data):
"""
Fail if the magnitude of the given order exceeds either self.max_shares
or self.max_notional.
"""
if self.asse... | [
"def",
"validate",
"(",
"self",
",",
"asset",
",",
"amount",
",",
"portfolio",
",",
"algo_datetime",
",",
"algo_current_data",
")",
":",
"if",
"self",
".",
"asset",
"is",
"not",
"None",
"and",
"self",
".",
"asset",
"!=",
"asset",
":",
"return",
"if",
"... | Fail if the magnitude of the given order exceeds either self.max_shares
or self.max_notional. | [
"Fail",
"if",
"the",
"magnitude",
"of",
"the",
"given",
"order",
"exceeds",
"either",
"self",
".",
"max_shares",
"or",
"self",
".",
"max_notional",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/finance/controls.py#L199-L223 | train |
quantopian/zipline | zipline/finance/controls.py | MaxPositionSize.validate | def validate(self,
asset,
amount,
portfolio,
algo_datetime,
algo_current_data):
"""
Fail if the given order would cause the magnitude of our position to be
greater in shares than self.max_shares or greater in do... | python | def validate(self,
asset,
amount,
portfolio,
algo_datetime,
algo_current_data):
"""
Fail if the given order would cause the magnitude of our position to be
greater in shares than self.max_shares or greater in do... | [
"def",
"validate",
"(",
"self",
",",
"asset",
",",
"amount",
",",
"portfolio",
",",
"algo_datetime",
",",
"algo_current_data",
")",
":",
"if",
"self",
".",
"asset",
"is",
"not",
"None",
"and",
"self",
".",
"asset",
"!=",
"asset",
":",
"return",
"current_... | Fail if the given order would cause the magnitude of our position to be
greater in shares than self.max_shares or greater in dollar value than
self.max_notional. | [
"Fail",
"if",
"the",
"given",
"order",
"would",
"cause",
"the",
"magnitude",
"of",
"our",
"position",
"to",
"be",
"greater",
"in",
"shares",
"than",
"self",
".",
"max_shares",
"or",
"greater",
"in",
"dollar",
"value",
"than",
"self",
".",
"max_notional",
"... | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/finance/controls.py#L257-L287 | train |
quantopian/zipline | zipline/finance/controls.py | LongOnly.validate | def validate(self,
asset,
amount,
portfolio,
algo_datetime,
algo_current_data):
"""
Fail if we would hold negative shares of asset after completing this
order.
"""
if portfolio.positions[asset].a... | python | def validate(self,
asset,
amount,
portfolio,
algo_datetime,
algo_current_data):
"""
Fail if we would hold negative shares of asset after completing this
order.
"""
if portfolio.positions[asset].a... | [
"def",
"validate",
"(",
"self",
",",
"asset",
",",
"amount",
",",
"portfolio",
",",
"algo_datetime",
",",
"algo_current_data",
")",
":",
"if",
"portfolio",
".",
"positions",
"[",
"asset",
"]",
".",
"amount",
"+",
"amount",
"<",
"0",
":",
"self",
".",
"... | Fail if we would hold negative shares of asset after completing this
order. | [
"Fail",
"if",
"we",
"would",
"hold",
"negative",
"shares",
"of",
"asset",
"after",
"completing",
"this",
"order",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/finance/controls.py#L298-L309 | train |
quantopian/zipline | zipline/finance/controls.py | AssetDateBounds.validate | def validate(self,
asset,
amount,
portfolio,
algo_datetime,
algo_current_data):
"""
Fail if the algo has passed this Asset's end_date, or before the
Asset's start date.
"""
# If the order is for ... | python | def validate(self,
asset,
amount,
portfolio,
algo_datetime,
algo_current_data):
"""
Fail if the algo has passed this Asset's end_date, or before the
Asset's start date.
"""
# If the order is for ... | [
"def",
"validate",
"(",
"self",
",",
"asset",
",",
"amount",
",",
"portfolio",
",",
"algo_datetime",
",",
"algo_current_data",
")",
":",
"# If the order is for 0 shares, then silently pass through.",
"if",
"amount",
"==",
"0",
":",
"return",
"normalized_algo_dt",
"=",... | Fail if the algo has passed this Asset's end_date, or before the
Asset's start date. | [
"Fail",
"if",
"the",
"algo",
"has",
"passed",
"this",
"Asset",
"s",
"end_date",
"or",
"before",
"the",
"Asset",
"s",
"start",
"date",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/finance/controls.py#L321-L354 | train |
quantopian/zipline | zipline/finance/controls.py | MaxLeverage.validate | def validate(self,
_portfolio,
_account,
_algo_datetime,
_algo_current_data):
"""
Fail if the leverage is greater than the allowed leverage.
"""
if _account.leverage > self.max_leverage:
self.fail() | python | def validate(self,
_portfolio,
_account,
_algo_datetime,
_algo_current_data):
"""
Fail if the leverage is greater than the allowed leverage.
"""
if _account.leverage > self.max_leverage:
self.fail() | [
"def",
"validate",
"(",
"self",
",",
"_portfolio",
",",
"_account",
",",
"_algo_datetime",
",",
"_algo_current_data",
")",
":",
"if",
"_account",
".",
"leverage",
">",
"self",
".",
"max_leverage",
":",
"self",
".",
"fail",
"(",
")"
] | Fail if the leverage is greater than the allowed leverage. | [
"Fail",
"if",
"the",
"leverage",
"is",
"greater",
"than",
"the",
"allowed",
"leverage",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/finance/controls.py#L424-L433 | train |
quantopian/zipline | zipline/finance/controls.py | MinLeverage.validate | def validate(self,
_portfolio,
account,
algo_datetime,
_algo_current_data):
"""
Make validation checks if we are after the deadline.
Fail if the leverage is less than the min leverage.
"""
if (algo_datetime > sel... | python | def validate(self,
_portfolio,
account,
algo_datetime,
_algo_current_data):
"""
Make validation checks if we are after the deadline.
Fail if the leverage is less than the min leverage.
"""
if (algo_datetime > sel... | [
"def",
"validate",
"(",
"self",
",",
"_portfolio",
",",
"account",
",",
"algo_datetime",
",",
"_algo_current_data",
")",
":",
"if",
"(",
"algo_datetime",
">",
"self",
".",
"deadline",
"and",
"account",
".",
"leverage",
"<",
"self",
".",
"min_leverage",
")",
... | Make validation checks if we are after the deadline.
Fail if the leverage is less than the min leverage. | [
"Make",
"validation",
"checks",
"if",
"we",
"are",
"after",
"the",
"deadline",
".",
"Fail",
"if",
"the",
"leverage",
"is",
"less",
"than",
"the",
"min",
"leverage",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/finance/controls.py#L463-L474 | train |
quantopian/zipline | zipline/assets/asset_db_migrations.py | alter_columns | def alter_columns(op, name, *columns, **kwargs):
"""Alter columns from a table.
Parameters
----------
name : str
The name of the table.
*columns
The new columns to have.
selection_string : str, optional
The string to use in the selection. If not provided, it will select ... | python | def alter_columns(op, name, *columns, **kwargs):
"""Alter columns from a table.
Parameters
----------
name : str
The name of the table.
*columns
The new columns to have.
selection_string : str, optional
The string to use in the selection. If not provided, it will select ... | [
"def",
"alter_columns",
"(",
"op",
",",
"name",
",",
"*",
"columns",
",",
"*",
"*",
"kwargs",
")",
":",
"selection_string",
"=",
"kwargs",
".",
"pop",
"(",
"'selection_string'",
",",
"None",
")",
"if",
"kwargs",
":",
"raise",
"TypeError",
"(",
"'alter_co... | Alter columns from a table.
Parameters
----------
name : str
The name of the table.
*columns
The new columns to have.
selection_string : str, optional
The string to use in the selection. If not provided, it will select all
of the new columns from the old table.
... | [
"Alter",
"columns",
"from",
"a",
"table",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/assets/asset_db_migrations.py#L13-L61 | train |
quantopian/zipline | zipline/assets/asset_db_migrations.py | downgrade | def downgrade(engine, desired_version):
"""Downgrades the assets db at the given engine to the desired version.
Parameters
----------
engine : Engine
An SQLAlchemy engine to the assets database.
desired_version : int
The desired resulting version for the assets database.
"""
... | python | def downgrade(engine, desired_version):
"""Downgrades the assets db at the given engine to the desired version.
Parameters
----------
engine : Engine
An SQLAlchemy engine to the assets database.
desired_version : int
The desired resulting version for the assets database.
"""
... | [
"def",
"downgrade",
"(",
"engine",
",",
"desired_version",
")",
":",
"# Check the version of the db at the engine",
"with",
"engine",
".",
"begin",
"(",
")",
"as",
"conn",
":",
"metadata",
"=",
"sa",
".",
"MetaData",
"(",
"conn",
")",
"metadata",
".",
"reflect... | Downgrades the assets db at the given engine to the desired version.
Parameters
----------
engine : Engine
An SQLAlchemy engine to the assets database.
desired_version : int
The desired resulting version for the assets database. | [
"Downgrades",
"the",
"assets",
"db",
"at",
"the",
"given",
"engine",
"to",
"the",
"desired",
"version",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/assets/asset_db_migrations.py#L65-L109 | train |
quantopian/zipline | zipline/assets/asset_db_migrations.py | downgrades | def downgrades(src):
"""Decorator for marking that a method is a downgrade to a version to the
previous version.
Parameters
----------
src : int
The version this downgrades from.
Returns
-------
decorator : callable[(callable) -> callable]
The decorator to apply.
""... | python | def downgrades(src):
"""Decorator for marking that a method is a downgrade to a version to the
previous version.
Parameters
----------
src : int
The version this downgrades from.
Returns
-------
decorator : callable[(callable) -> callable]
The decorator to apply.
""... | [
"def",
"downgrades",
"(",
"src",
")",
":",
"def",
"_",
"(",
"f",
")",
":",
"destination",
"=",
"src",
"-",
"1",
"@",
"do",
"(",
"operator",
".",
"setitem",
"(",
"_downgrade_methods",
",",
"destination",
")",
")",
"@",
"wraps",
"(",
"f",
")",
"def",... | Decorator for marking that a method is a downgrade to a version to the
previous version.
Parameters
----------
src : int
The version this downgrades from.
Returns
-------
decorator : callable[(callable) -> callable]
The decorator to apply. | [
"Decorator",
"for",
"marking",
"that",
"a",
"method",
"is",
"a",
"downgrade",
"to",
"a",
"version",
"to",
"the",
"previous",
"version",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/assets/asset_db_migrations.py#L133-L158 | train |
quantopian/zipline | zipline/assets/asset_db_migrations.py | _downgrade_v1 | def _downgrade_v1(op):
"""
Downgrade assets db by removing the 'tick_size' column and renaming the
'multiplier' column.
"""
# Drop indices before batch
# This is to prevent index collision when creating the temp table
op.drop_index('ix_futures_contracts_root_symbol')
op.drop_index('ix_fu... | python | def _downgrade_v1(op):
"""
Downgrade assets db by removing the 'tick_size' column and renaming the
'multiplier' column.
"""
# Drop indices before batch
# This is to prevent index collision when creating the temp table
op.drop_index('ix_futures_contracts_root_symbol')
op.drop_index('ix_fu... | [
"def",
"_downgrade_v1",
"(",
"op",
")",
":",
"# Drop indices before batch",
"# This is to prevent index collision when creating the temp table",
"op",
".",
"drop_index",
"(",
"'ix_futures_contracts_root_symbol'",
")",
"op",
".",
"drop_index",
"(",
"'ix_futures_contracts_symbol'",... | Downgrade assets db by removing the 'tick_size' column and renaming the
'multiplier' column. | [
"Downgrade",
"assets",
"db",
"by",
"removing",
"the",
"tick_size",
"column",
"and",
"renaming",
"the",
"multiplier",
"column",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/assets/asset_db_migrations.py#L162-L189 | train |
quantopian/zipline | zipline/assets/asset_db_migrations.py | _downgrade_v2 | def _downgrade_v2(op):
"""
Downgrade assets db by removing the 'auto_close_date' column.
"""
# Drop indices before batch
# This is to prevent index collision when creating the temp table
op.drop_index('ix_equities_fuzzy_symbol')
op.drop_index('ix_equities_company_symbol')
# Execute batc... | python | def _downgrade_v2(op):
"""
Downgrade assets db by removing the 'auto_close_date' column.
"""
# Drop indices before batch
# This is to prevent index collision when creating the temp table
op.drop_index('ix_equities_fuzzy_symbol')
op.drop_index('ix_equities_company_symbol')
# Execute batc... | [
"def",
"_downgrade_v2",
"(",
"op",
")",
":",
"# Drop indices before batch",
"# This is to prevent index collision when creating the temp table",
"op",
".",
"drop_index",
"(",
"'ix_equities_fuzzy_symbol'",
")",
"op",
".",
"drop_index",
"(",
"'ix_equities_company_symbol'",
")",
... | Downgrade assets db by removing the 'auto_close_date' column. | [
"Downgrade",
"assets",
"db",
"by",
"removing",
"the",
"auto_close_date",
"column",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/assets/asset_db_migrations.py#L193-L212 | train |
quantopian/zipline | zipline/assets/asset_db_migrations.py | _downgrade_v3 | def _downgrade_v3(op):
"""
Downgrade assets db by adding a not null constraint on
``equities.first_traded``
"""
op.create_table(
'_new_equities',
sa.Column(
'sid',
sa.Integer,
unique=True,
nullable=False,
primary_key=True,
... | python | def _downgrade_v3(op):
"""
Downgrade assets db by adding a not null constraint on
``equities.first_traded``
"""
op.create_table(
'_new_equities',
sa.Column(
'sid',
sa.Integer,
unique=True,
nullable=False,
primary_key=True,
... | [
"def",
"_downgrade_v3",
"(",
"op",
")",
":",
"op",
".",
"create_table",
"(",
"'_new_equities'",
",",
"sa",
".",
"Column",
"(",
"'sid'",
",",
"sa",
".",
"Integer",
",",
"unique",
"=",
"True",
",",
"nullable",
"=",
"False",
",",
"primary_key",
"=",
"True... | Downgrade assets db by adding a not null constraint on
``equities.first_traded`` | [
"Downgrade",
"assets",
"db",
"by",
"adding",
"a",
"not",
"null",
"constraint",
"on",
"equities",
".",
"first_traded"
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/assets/asset_db_migrations.py#L216-L260 | train |
quantopian/zipline | zipline/assets/asset_db_migrations.py | _downgrade_v4 | def _downgrade_v4(op):
"""
Downgrades assets db by copying the `exchange_full` column to `exchange`,
then dropping the `exchange_full` column.
"""
op.drop_index('ix_equities_fuzzy_symbol')
op.drop_index('ix_equities_company_symbol')
op.execute("UPDATE equities SET exchange = exchange_full")... | python | def _downgrade_v4(op):
"""
Downgrades assets db by copying the `exchange_full` column to `exchange`,
then dropping the `exchange_full` column.
"""
op.drop_index('ix_equities_fuzzy_symbol')
op.drop_index('ix_equities_company_symbol')
op.execute("UPDATE equities SET exchange = exchange_full")... | [
"def",
"_downgrade_v4",
"(",
"op",
")",
":",
"op",
".",
"drop_index",
"(",
"'ix_equities_fuzzy_symbol'",
")",
"op",
".",
"drop_index",
"(",
"'ix_equities_company_symbol'",
")",
"op",
".",
"execute",
"(",
"\"UPDATE equities SET exchange = exchange_full\"",
")",
"with",... | Downgrades assets db by copying the `exchange_full` column to `exchange`,
then dropping the `exchange_full` column. | [
"Downgrades",
"assets",
"db",
"by",
"copying",
"the",
"exchange_full",
"column",
"to",
"exchange",
"then",
"dropping",
"the",
"exchange_full",
"column",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/assets/asset_db_migrations.py#L264-L282 | train |
quantopian/zipline | zipline/finance/metrics/core.py | _make_metrics_set_core | def _make_metrics_set_core():
"""Create a family of metrics sets functions that read from the same
metrics set mapping.
Returns
-------
metrics_sets : mappingproxy
The mapping of metrics sets to load functions.
register : callable
The function which registers new metrics sets in... | python | def _make_metrics_set_core():
"""Create a family of metrics sets functions that read from the same
metrics set mapping.
Returns
-------
metrics_sets : mappingproxy
The mapping of metrics sets to load functions.
register : callable
The function which registers new metrics sets in... | [
"def",
"_make_metrics_set_core",
"(",
")",
":",
"_metrics_sets",
"=",
"{",
"}",
"# Expose _metrics_sets through a proxy so that users cannot mutate this",
"# accidentally. Users may go through `register` to update this which will",
"# warn when trampling another metrics set.",
"metrics_sets"... | Create a family of metrics sets functions that read from the same
metrics set mapping.
Returns
-------
metrics_sets : mappingproxy
The mapping of metrics sets to load functions.
register : callable
The function which registers new metrics sets in the ``metrics_sets``
mapping... | [
"Create",
"a",
"family",
"of",
"metrics",
"sets",
"functions",
"that",
"read",
"from",
"the",
"same",
"metrics",
"set",
"mapping",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/finance/metrics/core.py#L6-L103 | train |
quantopian/zipline | zipline/pipeline/loaders/earnings_estimates.py | validate_column_specs | def validate_column_specs(events, columns):
"""
Verify that the columns of ``events`` can be used by a
EarningsEstimatesLoader to serve the BoundColumns described by
`columns`.
"""
required = required_estimates_fields(columns)
received = set(events.columns)
missing = required - received
... | python | def validate_column_specs(events, columns):
"""
Verify that the columns of ``events`` can be used by a
EarningsEstimatesLoader to serve the BoundColumns described by
`columns`.
"""
required = required_estimates_fields(columns)
received = set(events.columns)
missing = required - received
... | [
"def",
"validate_column_specs",
"(",
"events",
",",
"columns",
")",
":",
"required",
"=",
"required_estimates_fields",
"(",
"columns",
")",
"received",
"=",
"set",
"(",
"events",
".",
"columns",
")",
"missing",
"=",
"required",
"-",
"received",
"if",
"missing"... | Verify that the columns of ``events`` can be used by a
EarningsEstimatesLoader to serve the BoundColumns described by
`columns`. | [
"Verify",
"that",
"the",
"columns",
"of",
"events",
"can",
"be",
"used",
"by",
"a",
"EarningsEstimatesLoader",
"to",
"serve",
"the",
"BoundColumns",
"described",
"by",
"columns",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/earnings_estimates.py#L74-L92 | train |
quantopian/zipline | zipline/pipeline/loaders/earnings_estimates.py | EarningsEstimatesLoader.get_requested_quarter_data | def get_requested_quarter_data(self,
zero_qtr_data,
zeroth_quarter_idx,
stacked_last_per_qtr,
num_announcements,
dates):
"""
Sele... | python | def get_requested_quarter_data(self,
zero_qtr_data,
zeroth_quarter_idx,
stacked_last_per_qtr,
num_announcements,
dates):
"""
Sele... | [
"def",
"get_requested_quarter_data",
"(",
"self",
",",
"zero_qtr_data",
",",
"zeroth_quarter_idx",
",",
"stacked_last_per_qtr",
",",
"num_announcements",
",",
"dates",
")",
":",
"zero_qtr_data_idx",
"=",
"zero_qtr_data",
".",
"index",
"requested_qtr_idx",
"=",
"pd",
"... | Selects the requested data for each date.
Parameters
----------
zero_qtr_data : pd.DataFrame
The 'time zero' data for each calendar date per sid.
zeroth_quarter_idx : pd.Index
An index of calendar dates, sid, and normalized quarters, for only
the rows... | [
"Selects",
"the",
"requested",
"data",
"for",
"each",
"date",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/earnings_estimates.py#L190-L253 | train |
quantopian/zipline | zipline/pipeline/loaders/earnings_estimates.py | EarningsEstimatesLoader.get_split_adjusted_asof_idx | def get_split_adjusted_asof_idx(self, dates):
"""
Compute the index in `dates` where the split-adjusted-asof-date
falls. This is the date up to which, and including which, we will
need to unapply all adjustments for and then re-apply them as they
come in. After this date, adjustm... | python | def get_split_adjusted_asof_idx(self, dates):
"""
Compute the index in `dates` where the split-adjusted-asof-date
falls. This is the date up to which, and including which, we will
need to unapply all adjustments for and then re-apply them as they
come in. After this date, adjustm... | [
"def",
"get_split_adjusted_asof_idx",
"(",
"self",
",",
"dates",
")",
":",
"split_adjusted_asof_idx",
"=",
"dates",
".",
"searchsorted",
"(",
"self",
".",
"_split_adjusted_asof",
")",
"# The split-asof date is after the date index.",
"if",
"split_adjusted_asof_idx",
"==",
... | Compute the index in `dates` where the split-adjusted-asof-date
falls. This is the date up to which, and including which, we will
need to unapply all adjustments for and then re-apply them as they
come in. After this date, adjustments are applied as normal.
Parameters
----------... | [
"Compute",
"the",
"index",
"in",
"dates",
"where",
"the",
"split",
"-",
"adjusted",
"-",
"asof",
"-",
"date",
"falls",
".",
"This",
"is",
"the",
"date",
"up",
"to",
"which",
"and",
"including",
"which",
"we",
"will",
"need",
"to",
"unapply",
"all",
"ad... | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/earnings_estimates.py#L255-L280 | train |
quantopian/zipline | zipline/pipeline/loaders/earnings_estimates.py | EarningsEstimatesLoader.collect_overwrites_for_sid | def collect_overwrites_for_sid(self,
group,
dates,
requested_qtr_data,
last_per_qtr,
sid_idx,
columns,
... | python | def collect_overwrites_for_sid(self,
group,
dates,
requested_qtr_data,
last_per_qtr,
sid_idx,
columns,
... | [
"def",
"collect_overwrites_for_sid",
"(",
"self",
",",
"group",
",",
"dates",
",",
"requested_qtr_data",
",",
"last_per_qtr",
",",
"sid_idx",
",",
"columns",
",",
"all_adjustments_for_sid",
",",
"sid",
")",
":",
"# If data was requested for only 1 date, there can never be... | Given a sid, collect all overwrites that should be applied for this
sid at each quarter boundary.
Parameters
----------
group : pd.DataFrame
The data for `sid`.
dates : pd.DatetimeIndex
The calendar dates for which estimates data is requested.
req... | [
"Given",
"a",
"sid",
"collect",
"all",
"overwrites",
"that",
"should",
"be",
"applied",
"for",
"this",
"sid",
"at",
"each",
"quarter",
"boundary",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/earnings_estimates.py#L282-L353 | train |
quantopian/zipline | zipline/pipeline/loaders/earnings_estimates.py | EarningsEstimatesLoader.merge_into_adjustments_for_all_sids | def merge_into_adjustments_for_all_sids(self,
all_adjustments_for_sid,
col_to_all_adjustments):
"""
Merge adjustments for a particular sid into a dictionary containing
adjustments for all sids.
Param... | python | def merge_into_adjustments_for_all_sids(self,
all_adjustments_for_sid,
col_to_all_adjustments):
"""
Merge adjustments for a particular sid into a dictionary containing
adjustments for all sids.
Param... | [
"def",
"merge_into_adjustments_for_all_sids",
"(",
"self",
",",
"all_adjustments_for_sid",
",",
"col_to_all_adjustments",
")",
":",
"for",
"col_name",
"in",
"all_adjustments_for_sid",
":",
"if",
"col_name",
"not",
"in",
"col_to_all_adjustments",
":",
"col_to_all_adjustments... | Merge adjustments for a particular sid into a dictionary containing
adjustments for all sids.
Parameters
----------
all_adjustments_for_sid : dict[int -> AdjustedArray]
All adjustments for a particular sid.
col_to_all_adjustments : dict[int -> AdjustedArray]
... | [
"Merge",
"adjustments",
"for",
"a",
"particular",
"sid",
"into",
"a",
"dictionary",
"containing",
"adjustments",
"for",
"all",
"sids",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/earnings_estimates.py#L406-L429 | train |
quantopian/zipline | zipline/pipeline/loaders/earnings_estimates.py | EarningsEstimatesLoader.get_adjustments | def get_adjustments(self,
zero_qtr_data,
requested_qtr_data,
last_per_qtr,
dates,
assets,
columns,
**kwargs):
"""
Creates an AdjustedArr... | python | def get_adjustments(self,
zero_qtr_data,
requested_qtr_data,
last_per_qtr,
dates,
assets,
columns,
**kwargs):
"""
Creates an AdjustedArr... | [
"def",
"get_adjustments",
"(",
"self",
",",
"zero_qtr_data",
",",
"requested_qtr_data",
",",
"last_per_qtr",
",",
"dates",
",",
"assets",
",",
"columns",
",",
"*",
"*",
"kwargs",
")",
":",
"zero_qtr_data",
".",
"sort_index",
"(",
"inplace",
"=",
"True",
")",... | Creates an AdjustedArray from the given estimates data for the given
dates.
Parameters
----------
zero_qtr_data : pd.DataFrame
The 'time zero' data for each calendar date per sid.
requested_qtr_data : pd.DataFrame
The requested quarter data for each calen... | [
"Creates",
"an",
"AdjustedArray",
"from",
"the",
"given",
"estimates",
"data",
"for",
"the",
"given",
"dates",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/earnings_estimates.py#L431-L490 | train |
quantopian/zipline | zipline/pipeline/loaders/earnings_estimates.py | EarningsEstimatesLoader.create_overwrites_for_quarter | def create_overwrites_for_quarter(self,
col_to_overwrites,
next_qtr_start_idx,
last_per_qtr,
quarters_with_estimates_for_sid,
requ... | python | def create_overwrites_for_quarter(self,
col_to_overwrites,
next_qtr_start_idx,
last_per_qtr,
quarters_with_estimates_for_sid,
requ... | [
"def",
"create_overwrites_for_quarter",
"(",
"self",
",",
"col_to_overwrites",
",",
"next_qtr_start_idx",
",",
"last_per_qtr",
",",
"quarters_with_estimates_for_sid",
",",
"requested_quarter",
",",
"sid",
",",
"sid_idx",
",",
"columns",
")",
":",
"for",
"col",
"in",
... | Add entries to the dictionary of columns to adjustments for the given
sid and the given quarter.
Parameters
----------
col_to_overwrites : dict [column_name -> list of ArrayAdjustment]
A dictionary mapping column names to all overwrites for those
columns.
... | [
"Add",
"entries",
"to",
"the",
"dictionary",
"of",
"columns",
"to",
"adjustments",
"for",
"the",
"given",
"sid",
"and",
"the",
"given",
"quarter",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/earnings_estimates.py#L492-L563 | train |
quantopian/zipline | zipline/pipeline/loaders/earnings_estimates.py | EarningsEstimatesLoader.get_last_data_per_qtr | def get_last_data_per_qtr(self,
assets_with_data,
columns,
dates,
data_query_cutoff_times):
"""
Determine the last piece of information we know for each column on each
date in ... | python | def get_last_data_per_qtr(self,
assets_with_data,
columns,
dates,
data_query_cutoff_times):
"""
Determine the last piece of information we know for each column on each
date in ... | [
"def",
"get_last_data_per_qtr",
"(",
"self",
",",
"assets_with_data",
",",
"columns",
",",
"dates",
",",
"data_query_cutoff_times",
")",
":",
"# Get a DataFrame indexed by date with a MultiIndex of columns of",
"# [self.estimates.columns, normalized_quarters, sid], where each cell",
... | Determine the last piece of information we know for each column on each
date in the index for each sid and quarter.
Parameters
----------
assets_with_data : pd.Index
Index of all assets that appear in the raw data given to the
loader.
columns : iterable o... | [
"Determine",
"the",
"last",
"piece",
"of",
"information",
"we",
"know",
"for",
"each",
"column",
"on",
"each",
"date",
"in",
"the",
"index",
"for",
"each",
"sid",
"and",
"quarter",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/earnings_estimates.py#L667-L725 | train |
quantopian/zipline | zipline/pipeline/loaders/earnings_estimates.py | PreviousEarningsEstimatesLoader.get_zeroth_quarter_idx | def get_zeroth_quarter_idx(self, stacked_last_per_qtr):
"""
Filters for releases that are on or after each simulation date and
determines the previous quarter by picking out the most recent
release relative to each date in the index.
Parameters
----------
stacked... | python | def get_zeroth_quarter_idx(self, stacked_last_per_qtr):
"""
Filters for releases that are on or after each simulation date and
determines the previous quarter by picking out the most recent
release relative to each date in the index.
Parameters
----------
stacked... | [
"def",
"get_zeroth_quarter_idx",
"(",
"self",
",",
"stacked_last_per_qtr",
")",
":",
"previous_releases_per_date",
"=",
"stacked_last_per_qtr",
".",
"loc",
"[",
"stacked_last_per_qtr",
"[",
"EVENT_DATE_FIELD_NAME",
"]",
"<=",
"stacked_last_per_qtr",
".",
"index",
".",
"... | Filters for releases that are on or after each simulation date and
determines the previous quarter by picking out the most recent
release relative to each date in the index.
Parameters
----------
stacked_last_per_qtr : pd.DataFrame
A DataFrame with index of calendar ... | [
"Filters",
"for",
"releases",
"that",
"are",
"on",
"or",
"after",
"each",
"simulation",
"date",
"and",
"determines",
"the",
"previous",
"quarter",
"by",
"picking",
"out",
"the",
"most",
"recent",
"release",
"relative",
"to",
"each",
"date",
"in",
"the",
"ind... | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/earnings_estimates.py#L810-L838 | train |
quantopian/zipline | zipline/pipeline/loaders/earnings_estimates.py | SplitAdjustedEstimatesLoader.get_adjustments_for_sid | def get_adjustments_for_sid(self,
group,
dates,
requested_qtr_data,
last_per_qtr,
sid_to_idx,
columns,
... | python | def get_adjustments_for_sid(self,
group,
dates,
requested_qtr_data,
last_per_qtr,
sid_to_idx,
columns,
... | [
"def",
"get_adjustments_for_sid",
"(",
"self",
",",
"group",
",",
"dates",
",",
"requested_qtr_data",
",",
"last_per_qtr",
",",
"sid_to_idx",
",",
"columns",
",",
"col_to_all_adjustments",
",",
"split_adjusted_asof_idx",
"=",
"None",
",",
"split_adjusted_cols_for_group"... | Collects both overwrites and adjustments for a particular sid.
Parameters
----------
split_adjusted_asof_idx : int
The integer index of the date on which the data was split-adjusted.
split_adjusted_cols_for_group : list of str
The names of requested columns that ... | [
"Collects",
"both",
"overwrites",
"and",
"adjustments",
"for",
"a",
"particular",
"sid",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/earnings_estimates.py#L907-L965 | train |
quantopian/zipline | zipline/pipeline/loaders/earnings_estimates.py | SplitAdjustedEstimatesLoader.get_adjustments | def get_adjustments(self,
zero_qtr_data,
requested_qtr_data,
last_per_qtr,
dates,
assets,
columns,
**kwargs):
"""
Calculates both split ... | python | def get_adjustments(self,
zero_qtr_data,
requested_qtr_data,
last_per_qtr,
dates,
assets,
columns,
**kwargs):
"""
Calculates both split ... | [
"def",
"get_adjustments",
"(",
"self",
",",
"zero_qtr_data",
",",
"requested_qtr_data",
",",
"last_per_qtr",
",",
"dates",
",",
"assets",
",",
"columns",
",",
"*",
"*",
"kwargs",
")",
":",
"split_adjusted_cols_for_group",
"=",
"[",
"self",
".",
"name_map",
"["... | Calculates both split adjustments and overwrites for all sids. | [
"Calculates",
"both",
"split",
"adjustments",
"and",
"overwrites",
"for",
"all",
"sids",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/earnings_estimates.py#L967-L996 | train |
quantopian/zipline | zipline/pipeline/loaders/earnings_estimates.py | SplitAdjustedEstimatesLoader.determine_end_idx_for_adjustment | def determine_end_idx_for_adjustment(self,
adjustment_ts,
dates,
upper_bound,
requested_quarter,
sid_estimates):
... | python | def determine_end_idx_for_adjustment(self,
adjustment_ts,
dates,
upper_bound,
requested_quarter,
sid_estimates):
... | [
"def",
"determine_end_idx_for_adjustment",
"(",
"self",
",",
"adjustment_ts",
",",
"dates",
",",
"upper_bound",
",",
"requested_quarter",
",",
"sid_estimates",
")",
":",
"end_idx",
"=",
"upper_bound",
"# Find the next newest kd that happens on or after",
"# the date of this a... | Determines the date until which the adjustment at the given date
index should be applied for the given quarter.
Parameters
----------
adjustment_ts : pd.Timestamp
The timestamp at which the adjustment occurs.
dates : pd.DatetimeIndex
The calendar dates ov... | [
"Determines",
"the",
"date",
"until",
"which",
"the",
"adjustment",
"at",
"the",
"given",
"date",
"index",
"should",
"be",
"applied",
"for",
"the",
"given",
"quarter",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/earnings_estimates.py#L998-L1051 | train |
quantopian/zipline | zipline/pipeline/loaders/earnings_estimates.py | SplitAdjustedEstimatesLoader.collect_pre_split_asof_date_adjustments | def collect_pre_split_asof_date_adjustments(
self,
split_adjusted_asof_date_idx,
sid_idx,
pre_adjustments,
requested_split_adjusted_columns
):
"""
Collect split adjustments that occur before the
split-adjusted-asof-date. All those a... | python | def collect_pre_split_asof_date_adjustments(
self,
split_adjusted_asof_date_idx,
sid_idx,
pre_adjustments,
requested_split_adjusted_columns
):
"""
Collect split adjustments that occur before the
split-adjusted-asof-date. All those a... | [
"def",
"collect_pre_split_asof_date_adjustments",
"(",
"self",
",",
"split_adjusted_asof_date_idx",
",",
"sid_idx",
",",
"pre_adjustments",
",",
"requested_split_adjusted_columns",
")",
":",
"col_to_split_adjustments",
"=",
"{",
"}",
"if",
"len",
"(",
"pre_adjustments",
"... | Collect split adjustments that occur before the
split-adjusted-asof-date. All those adjustments must first be
UN-applied at the first date index and then re-applied on the
appropriate dates in order to match point in time share pricing data.
Parameters
----------
split_a... | [
"Collect",
"split",
"adjustments",
"that",
"occur",
"before",
"the",
"split",
"-",
"adjusted",
"-",
"asof",
"-",
"date",
".",
"All",
"those",
"adjustments",
"must",
"first",
"be",
"UN",
"-",
"applied",
"at",
"the",
"first",
"date",
"index",
"and",
"then",
... | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/earnings_estimates.py#L1053-L1115 | train |
quantopian/zipline | zipline/pipeline/loaders/earnings_estimates.py | SplitAdjustedEstimatesLoader.collect_post_asof_split_adjustments | def collect_post_asof_split_adjustments(self,
post_adjustments,
requested_qtr_data,
sid,
sid_idx,
si... | python | def collect_post_asof_split_adjustments(self,
post_adjustments,
requested_qtr_data,
sid,
sid_idx,
si... | [
"def",
"collect_post_asof_split_adjustments",
"(",
"self",
",",
"post_adjustments",
",",
"requested_qtr_data",
",",
"sid",
",",
"sid_idx",
",",
"sid_estimates",
",",
"requested_split_adjusted_columns",
")",
":",
"col_to_split_adjustments",
"=",
"{",
"}",
"if",
"post_adj... | Collect split adjustments that occur after the
split-adjusted-asof-date. Each adjustment needs to be applied to all
dates on which knowledge for the requested quarter was older than the
date of the adjustment.
Parameters
----------
post_adjustments : tuple(list(float), l... | [
"Collect",
"split",
"adjustments",
"that",
"occur",
"after",
"the",
"split",
"-",
"adjusted",
"-",
"asof",
"-",
"date",
".",
"Each",
"adjustment",
"needs",
"to",
"be",
"applied",
"to",
"all",
"dates",
"on",
"which",
"knowledge",
"for",
"the",
"requested",
... | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/earnings_estimates.py#L1117-L1215 | train |
quantopian/zipline | zipline/pipeline/loaders/earnings_estimates.py | SplitAdjustedEstimatesLoader.retrieve_split_adjustment_data_for_sid | def retrieve_split_adjustment_data_for_sid(self,
dates,
sid,
split_adjusted_asof_idx):
"""
dates : pd.DatetimeIndex
The calendar dates.
sid : i... | python | def retrieve_split_adjustment_data_for_sid(self,
dates,
sid,
split_adjusted_asof_idx):
"""
dates : pd.DatetimeIndex
The calendar dates.
sid : i... | [
"def",
"retrieve_split_adjustment_data_for_sid",
"(",
"self",
",",
"dates",
",",
"sid",
",",
"split_adjusted_asof_idx",
")",
":",
"adjustments",
"=",
"self",
".",
"_split_adjustments",
".",
"get_adjustments_for_sid",
"(",
"'splits'",
",",
"sid",
")",
"sorted",
"(",
... | dates : pd.DatetimeIndex
The calendar dates.
sid : int
The sid for which we want to retrieve adjustments.
split_adjusted_asof_idx : int
The index in `dates` as-of which the data is split adjusted.
Returns
-------
pre_adjustments : tuple(list(f... | [
"dates",
":",
"pd",
".",
"DatetimeIndex",
"The",
"calendar",
"dates",
".",
"sid",
":",
"int",
"The",
"sid",
"for",
"which",
"we",
"want",
"to",
"retrieve",
"adjustments",
".",
"split_adjusted_asof_idx",
":",
"int",
"The",
"index",
"in",
"dates",
"as",
"-",... | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/earnings_estimates.py#L1217-L1265 | train |
quantopian/zipline | zipline/pipeline/loaders/earnings_estimates.py | SplitAdjustedEstimatesLoader.merge_split_adjustments_with_overwrites | def merge_split_adjustments_with_overwrites(
self,
pre,
post,
overwrites,
requested_split_adjusted_columns
):
"""
Merge split adjustments with the dict containing overwrites.
Parameters
----------
pre : dict[str -> dict[int -> list]]
... | python | def merge_split_adjustments_with_overwrites(
self,
pre,
post,
overwrites,
requested_split_adjusted_columns
):
"""
Merge split adjustments with the dict containing overwrites.
Parameters
----------
pre : dict[str -> dict[int -> list]]
... | [
"def",
"merge_split_adjustments_with_overwrites",
"(",
"self",
",",
"pre",
",",
"post",
",",
"overwrites",
",",
"requested_split_adjusted_columns",
")",
":",
"for",
"column_name",
"in",
"requested_split_adjusted_columns",
":",
"# We can do a merge here because the timestamps in... | Merge split adjustments with the dict containing overwrites.
Parameters
----------
pre : dict[str -> dict[int -> list]]
The adjustments that occur before the split-adjusted-asof-date.
post : dict[str -> dict[int -> list]]
The adjustments that occur after the spli... | [
"Merge",
"split",
"adjustments",
"with",
"the",
"dict",
"containing",
"overwrites",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/earnings_estimates.py#L1294-L1336 | train |
quantopian/zipline | zipline/pipeline/loaders/earnings_estimates.py | PreviousSplitAdjustedEarningsEstimatesLoader.collect_split_adjustments | def collect_split_adjustments(self,
adjustments_for_sid,
requested_qtr_data,
dates,
sid,
sid_idx,
sid_estimates,
... | python | def collect_split_adjustments(self,
adjustments_for_sid,
requested_qtr_data,
dates,
sid,
sid_idx,
sid_estimates,
... | [
"def",
"collect_split_adjustments",
"(",
"self",
",",
"adjustments_for_sid",
",",
"requested_qtr_data",
",",
"dates",
",",
"sid",
",",
"sid_idx",
",",
"sid_estimates",
",",
"split_adjusted_asof_idx",
",",
"pre_adjustments",
",",
"post_adjustments",
",",
"requested_split... | Collect split adjustments for previous quarters and apply them to the
given dictionary of splits for the given sid. Since overwrites just
replace all estimates before the new quarter with NaN, we don't need to
worry about re-applying split adjustments.
Parameters
----------
... | [
"Collect",
"split",
"adjustments",
"for",
"previous",
"quarters",
"and",
"apply",
"them",
"to",
"the",
"given",
"dictionary",
"of",
"splits",
"for",
"the",
"given",
"sid",
".",
"Since",
"overwrites",
"just",
"replace",
"all",
"estimates",
"before",
"the",
"new... | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/earnings_estimates.py#L1342-L1401 | train |
quantopian/zipline | zipline/pipeline/loaders/earnings_estimates.py | NextSplitAdjustedEarningsEstimatesLoader.collect_split_adjustments | def collect_split_adjustments(self,
adjustments_for_sid,
requested_qtr_data,
dates,
sid,
sid_idx,
sid_estimates,
... | python | def collect_split_adjustments(self,
adjustments_for_sid,
requested_qtr_data,
dates,
sid,
sid_idx,
sid_estimates,
... | [
"def",
"collect_split_adjustments",
"(",
"self",
",",
"adjustments_for_sid",
",",
"requested_qtr_data",
",",
"dates",
",",
"sid",
",",
"sid_idx",
",",
"sid_estimates",
",",
"split_adjusted_asof_idx",
",",
"pre_adjustments",
",",
"post_adjustments",
",",
"requested_split... | Collect split adjustments for future quarters. Re-apply adjustments
that would be overwritten by overwrites. Merge split adjustments with
overwrites into the given dictionary of splits for the given sid.
Parameters
----------
adjustments_for_sid : dict[str -> dict[int -> list]]
... | [
"Collect",
"split",
"adjustments",
"for",
"future",
"quarters",
".",
"Re",
"-",
"apply",
"adjustments",
"that",
"would",
"be",
"overwritten",
"by",
"overwrites",
".",
"Merge",
"split",
"adjustments",
"with",
"overwrites",
"into",
"the",
"given",
"dictionary",
"o... | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/earnings_estimates.py#L1407-L1534 | train |
quantopian/zipline | zipline/pipeline/factors/basic.py | _ExponentialWeightedFactor.from_span | def from_span(cls, inputs, window_length, span, **kwargs):
"""
Convenience constructor for passing `decay_rate` in terms of `span`.
Forwards `decay_rate` as `1 - (2.0 / (1 + span))`. This provides the
behavior equivalent to passing `span` to pandas.ewma.
Examples
-----... | python | def from_span(cls, inputs, window_length, span, **kwargs):
"""
Convenience constructor for passing `decay_rate` in terms of `span`.
Forwards `decay_rate` as `1 - (2.0 / (1 + span))`. This provides the
behavior equivalent to passing `span` to pandas.ewma.
Examples
-----... | [
"def",
"from_span",
"(",
"cls",
",",
"inputs",
",",
"window_length",
",",
"span",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"span",
"<=",
"1",
":",
"raise",
"ValueError",
"(",
"\"`span` must be a positive number. %s was passed.\"",
"%",
"span",
")",
"decay_rate... | Convenience constructor for passing `decay_rate` in terms of `span`.
Forwards `decay_rate` as `1 - (2.0 / (1 + span))`. This provides the
behavior equivalent to passing `span` to pandas.ewma.
Examples
--------
.. code-block:: python
# Equivalent to:
# ... | [
"Convenience",
"constructor",
"for",
"passing",
"decay_rate",
"in",
"terms",
"of",
"span",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/basic.py#L198-L240 | train |
quantopian/zipline | zipline/pipeline/factors/basic.py | _ExponentialWeightedFactor.from_halflife | def from_halflife(cls, inputs, window_length, halflife, **kwargs):
"""
Convenience constructor for passing ``decay_rate`` in terms of half
life.
Forwards ``decay_rate`` as ``exp(log(.5) / halflife)``. This provides
the behavior equivalent to passing `halflife` to pandas.ewma.
... | python | def from_halflife(cls, inputs, window_length, halflife, **kwargs):
"""
Convenience constructor for passing ``decay_rate`` in terms of half
life.
Forwards ``decay_rate`` as ``exp(log(.5) / halflife)``. This provides
the behavior equivalent to passing `halflife` to pandas.ewma.
... | [
"def",
"from_halflife",
"(",
"cls",
",",
"inputs",
",",
"window_length",
",",
"halflife",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"halflife",
"<=",
"0",
":",
"raise",
"ValueError",
"(",
"\"`span` must be a positive number. %s was passed.\"",
"%",
"halflife",
")... | Convenience constructor for passing ``decay_rate`` in terms of half
life.
Forwards ``decay_rate`` as ``exp(log(.5) / halflife)``. This provides
the behavior equivalent to passing `halflife` to pandas.ewma.
Examples
--------
.. code-block:: python
# Equival... | [
"Convenience",
"constructor",
"for",
"passing",
"decay_rate",
"in",
"terms",
"of",
"half",
"life",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/basic.py#L244-L286 | train |
quantopian/zipline | zipline/pipeline/factors/basic.py | _ExponentialWeightedFactor.from_center_of_mass | def from_center_of_mass(cls,
inputs,
window_length,
center_of_mass,
**kwargs):
"""
Convenience constructor for passing `decay_rate` in terms of center of
mass.
Forwards `decay... | python | def from_center_of_mass(cls,
inputs,
window_length,
center_of_mass,
**kwargs):
"""
Convenience constructor for passing `decay_rate` in terms of center of
mass.
Forwards `decay... | [
"def",
"from_center_of_mass",
"(",
"cls",
",",
"inputs",
",",
"window_length",
",",
"center_of_mass",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"cls",
"(",
"inputs",
"=",
"inputs",
",",
"window_length",
"=",
"window_length",
",",
"decay_rate",
"=",
"(",
... | Convenience constructor for passing `decay_rate` in terms of center of
mass.
Forwards `decay_rate` as `1 - (1 / 1 + center_of_mass)`. This provides
behavior equivalent to passing `center_of_mass` to pandas.ewma.
Examples
--------
.. code-block:: python
# E... | [
"Convenience",
"constructor",
"for",
"passing",
"decay_rate",
"in",
"terms",
"of",
"center",
"of",
"mass",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/basic.py#L289-L328 | train |
quantopian/zipline | zipline/utils/math_utils.py | tolerant_equals | def tolerant_equals(a, b, atol=10e-7, rtol=10e-7, equal_nan=False):
"""Check if a and b are equal with some tolerance.
Parameters
----------
a, b : float
The floats to check for equality.
atol : float, optional
The absolute tolerance.
rtol : float, optional
The relative ... | python | def tolerant_equals(a, b, atol=10e-7, rtol=10e-7, equal_nan=False):
"""Check if a and b are equal with some tolerance.
Parameters
----------
a, b : float
The floats to check for equality.
atol : float, optional
The absolute tolerance.
rtol : float, optional
The relative ... | [
"def",
"tolerant_equals",
"(",
"a",
",",
"b",
",",
"atol",
"=",
"10e-7",
",",
"rtol",
"=",
"10e-7",
",",
"equal_nan",
"=",
"False",
")",
":",
"if",
"equal_nan",
"and",
"isnan",
"(",
"a",
")",
"and",
"isnan",
"(",
"b",
")",
":",
"return",
"True",
... | Check if a and b are equal with some tolerance.
Parameters
----------
a, b : float
The floats to check for equality.
atol : float, optional
The absolute tolerance.
rtol : float, optional
The relative tolerance.
equal_nan : bool, optional
Should NaN compare equal?... | [
"Check",
"if",
"a",
"and",
"b",
"are",
"equal",
"with",
"some",
"tolerance",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/utils/math_utils.py#L21-L47 | train |
quantopian/zipline | zipline/utils/math_utils.py | round_if_near_integer | def round_if_near_integer(a, epsilon=1e-4):
"""
Round a to the nearest integer if that integer is within an epsilon
of a.
"""
if abs(a - round(a)) <= epsilon:
return round(a)
else:
return a | python | def round_if_near_integer(a, epsilon=1e-4):
"""
Round a to the nearest integer if that integer is within an epsilon
of a.
"""
if abs(a - round(a)) <= epsilon:
return round(a)
else:
return a | [
"def",
"round_if_near_integer",
"(",
"a",
",",
"epsilon",
"=",
"1e-4",
")",
":",
"if",
"abs",
"(",
"a",
"-",
"round",
"(",
"a",
")",
")",
"<=",
"epsilon",
":",
"return",
"round",
"(",
"a",
")",
"else",
":",
"return",
"a"
] | Round a to the nearest integer if that integer is within an epsilon
of a. | [
"Round",
"a",
"to",
"the",
"nearest",
"integer",
"if",
"that",
"integer",
"is",
"within",
"an",
"epsilon",
"of",
"a",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/utils/math_utils.py#L72-L80 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | coerce_numbers_to_my_dtype | def coerce_numbers_to_my_dtype(f):
"""
A decorator for methods whose signature is f(self, other) that coerces
``other`` to ``self.dtype``.
This is used to make comparison operations between numbers and `Factor`
instances work independently of whether the user supplies a float or
integer literal... | python | def coerce_numbers_to_my_dtype(f):
"""
A decorator for methods whose signature is f(self, other) that coerces
``other`` to ``self.dtype``.
This is used to make comparison operations between numbers and `Factor`
instances work independently of whether the user supplies a float or
integer literal... | [
"def",
"coerce_numbers_to_my_dtype",
"(",
"f",
")",
":",
"@",
"wraps",
"(",
"f",
")",
"def",
"method",
"(",
"self",
",",
"other",
")",
":",
"if",
"isinstance",
"(",
"other",
",",
"Number",
")",
":",
"other",
"=",
"coerce_to_dtype",
"(",
"self",
".",
... | A decorator for methods whose signature is f(self, other) that coerces
``other`` to ``self.dtype``.
This is used to make comparison operations between numbers and `Factor`
instances work independently of whether the user supplies a float or
integer literal.
For example, if I write::
my_fi... | [
"A",
"decorator",
"for",
"methods",
"whose",
"signature",
"is",
"f",
"(",
"self",
"other",
")",
"that",
"coerces",
"other",
"to",
"self",
".",
"dtype",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L70-L91 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | binop_return_dtype | def binop_return_dtype(op, left, right):
"""
Compute the expected return dtype for the given binary operator.
Parameters
----------
op : str
Operator symbol, (e.g. '+', '-', ...).
left : numpy.dtype
Dtype of left hand side.
right : numpy.dtype
Dtype of right hand sid... | python | def binop_return_dtype(op, left, right):
"""
Compute the expected return dtype for the given binary operator.
Parameters
----------
op : str
Operator symbol, (e.g. '+', '-', ...).
left : numpy.dtype
Dtype of left hand side.
right : numpy.dtype
Dtype of right hand sid... | [
"def",
"binop_return_dtype",
"(",
"op",
",",
"left",
",",
"right",
")",
":",
"if",
"is_comparison",
"(",
"op",
")",
":",
"if",
"left",
"!=",
"right",
":",
"raise",
"TypeError",
"(",
"\"Don't know how to compute {left} {op} {right}.\\n\"",
"\"Comparisons are only sup... | Compute the expected return dtype for the given binary operator.
Parameters
----------
op : str
Operator symbol, (e.g. '+', '-', ...).
left : numpy.dtype
Dtype of left hand side.
right : numpy.dtype
Dtype of right hand side.
Returns
-------
outdtype : numpy.dtyp... | [
"Compute",
"the",
"expected",
"return",
"dtype",
"for",
"the",
"given",
"binary",
"operator",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L101-L138 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | binary_operator | def binary_operator(op):
"""
Factory function for making binary operator methods on a Factor subclass.
Returns a function, "binary_operator" suitable for implementing functions
like __add__.
"""
# When combining a Factor with a NumericalExpression, we use this
# attrgetter instance to defer... | python | def binary_operator(op):
"""
Factory function for making binary operator methods on a Factor subclass.
Returns a function, "binary_operator" suitable for implementing functions
like __add__.
"""
# When combining a Factor with a NumericalExpression, we use this
# attrgetter instance to defer... | [
"def",
"binary_operator",
"(",
"op",
")",
":",
"# When combining a Factor with a NumericalExpression, we use this",
"# attrgetter instance to defer to the commuted implementation of the",
"# NumericalExpression operator.",
"commuted_method_getter",
"=",
"attrgetter",
"(",
"method_name_for_... | Factory function for making binary operator methods on a Factor subclass.
Returns a function, "binary_operator" suitable for implementing functions
like __add__. | [
"Factory",
"function",
"for",
"making",
"binary",
"operator",
"methods",
"on",
"a",
"Factor",
"subclass",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L141-L201 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | reflected_binary_operator | def reflected_binary_operator(op):
"""
Factory function for making binary operator methods on a Factor.
Returns a function, "reflected_binary_operator" suitable for implementing
functions like __radd__.
"""
assert not is_comparison(op)
@with_name(method_name_for_op(op, commute=True))
@... | python | def reflected_binary_operator(op):
"""
Factory function for making binary operator methods on a Factor.
Returns a function, "reflected_binary_operator" suitable for implementing
functions like __radd__.
"""
assert not is_comparison(op)
@with_name(method_name_for_op(op, commute=True))
@... | [
"def",
"reflected_binary_operator",
"(",
"op",
")",
":",
"assert",
"not",
"is_comparison",
"(",
"op",
")",
"@",
"with_name",
"(",
"method_name_for_op",
"(",
"op",
",",
"commute",
"=",
"True",
")",
")",
"@",
"coerce_numbers_to_my_dtype",
"def",
"reflected_binary_... | Factory function for making binary operator methods on a Factor.
Returns a function, "reflected_binary_operator" suitable for implementing
functions like __radd__. | [
"Factory",
"function",
"for",
"making",
"binary",
"operator",
"methods",
"on",
"a",
"Factor",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L204-L240 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | unary_operator | def unary_operator(op):
"""
Factory function for making unary operator methods for Factors.
"""
# Only negate is currently supported.
valid_ops = {'-'}
if op not in valid_ops:
raise ValueError("Invalid unary operator %s." % op)
@with_doc("Unary Operator: '%s'" % op)
@with_name(u... | python | def unary_operator(op):
"""
Factory function for making unary operator methods for Factors.
"""
# Only negate is currently supported.
valid_ops = {'-'}
if op not in valid_ops:
raise ValueError("Invalid unary operator %s." % op)
@with_doc("Unary Operator: '%s'" % op)
@with_name(u... | [
"def",
"unary_operator",
"(",
"op",
")",
":",
"# Only negate is currently supported.",
"valid_ops",
"=",
"{",
"'-'",
"}",
"if",
"op",
"not",
"in",
"valid_ops",
":",
"raise",
"ValueError",
"(",
"\"Invalid unary operator %s.\"",
"%",
"op",
")",
"@",
"with_doc",
"(... | Factory function for making unary operator methods for Factors. | [
"Factory",
"function",
"for",
"making",
"unary",
"operator",
"methods",
"for",
"Factors",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L243-L282 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | function_application | def function_application(func):
"""
Factory function for producing function application methods for Factor
subclasses.
"""
if func not in NUMEXPR_MATH_FUNCS:
raise ValueError("Unsupported mathematical function '%s'" % func)
@with_doc(func)
@with_name(func)
def mathfunc(self):
... | python | def function_application(func):
"""
Factory function for producing function application methods for Factor
subclasses.
"""
if func not in NUMEXPR_MATH_FUNCS:
raise ValueError("Unsupported mathematical function '%s'" % func)
@with_doc(func)
@with_name(func)
def mathfunc(self):
... | [
"def",
"function_application",
"(",
"func",
")",
":",
"if",
"func",
"not",
"in",
"NUMEXPR_MATH_FUNCS",
":",
"raise",
"ValueError",
"(",
"\"Unsupported mathematical function '%s'\"",
"%",
"func",
")",
"@",
"with_doc",
"(",
"func",
")",
"@",
"with_name",
"(",
"fun... | Factory function for producing function application methods for Factor
subclasses. | [
"Factory",
"function",
"for",
"producing",
"function",
"application",
"methods",
"for",
"Factor",
"subclasses",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L285-L308 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | winsorize | def winsorize(row, min_percentile, max_percentile):
"""
This implementation is based on scipy.stats.mstats.winsorize
"""
a = row.copy()
nan_count = isnan(row).sum()
nonnan_count = a.size - nan_count
# NOTE: argsort() sorts nans to the end of the array.
idx = a.argsort()
# Set value... | python | def winsorize(row, min_percentile, max_percentile):
"""
This implementation is based on scipy.stats.mstats.winsorize
"""
a = row.copy()
nan_count = isnan(row).sum()
nonnan_count = a.size - nan_count
# NOTE: argsort() sorts nans to the end of the array.
idx = a.argsort()
# Set value... | [
"def",
"winsorize",
"(",
"row",
",",
"min_percentile",
",",
"max_percentile",
")",
":",
"a",
"=",
"row",
".",
"copy",
"(",
")",
"nan_count",
"=",
"isnan",
"(",
"row",
")",
".",
"sum",
"(",
")",
"nonnan_count",
"=",
"a",
".",
"size",
"-",
"nan_count",... | This implementation is based on scipy.stats.mstats.winsorize | [
"This",
"implementation",
"is",
"based",
"on",
"scipy",
".",
"stats",
".",
"mstats",
".",
"winsorize"
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L1671-L1698 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | Factor.demean | def demean(self, mask=NotSpecified, groupby=NotSpecified):
"""
Construct a Factor that computes ``self`` and subtracts the mean from
row of the result.
If ``mask`` is supplied, ignore values where ``mask`` returns False
when computing row means, and output NaN anywhere the mask ... | python | def demean(self, mask=NotSpecified, groupby=NotSpecified):
"""
Construct a Factor that computes ``self`` and subtracts the mean from
row of the result.
If ``mask`` is supplied, ignore values where ``mask`` returns False
when computing row means, and output NaN anywhere the mask ... | [
"def",
"demean",
"(",
"self",
",",
"mask",
"=",
"NotSpecified",
",",
"groupby",
"=",
"NotSpecified",
")",
":",
"return",
"GroupedRowTransform",
"(",
"transform",
"=",
"demean",
",",
"transform_args",
"=",
"(",
")",
",",
"factor",
"=",
"self",
",",
"groupby... | Construct a Factor that computes ``self`` and subtracts the mean from
row of the result.
If ``mask`` is supplied, ignore values where ``mask`` returns False
when computing row means, and output NaN anywhere the mask is False.
If ``groupby`` is supplied, compute by partitioning each row... | [
"Construct",
"a",
"Factor",
"that",
"computes",
"self",
"and",
"subtracts",
"the",
"mean",
"from",
"row",
"of",
"the",
"result",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L402-L524 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | Factor.zscore | def zscore(self, mask=NotSpecified, groupby=NotSpecified):
"""
Construct a Factor that Z-Scores each day's results.
The Z-Score of a row is defined as::
(row - row.mean()) / row.stddev()
If ``mask`` is supplied, ignore values where ``mask`` returns False
when compu... | python | def zscore(self, mask=NotSpecified, groupby=NotSpecified):
"""
Construct a Factor that Z-Scores each day's results.
The Z-Score of a row is defined as::
(row - row.mean()) / row.stddev()
If ``mask`` is supplied, ignore values where ``mask`` returns False
when compu... | [
"def",
"zscore",
"(",
"self",
",",
"mask",
"=",
"NotSpecified",
",",
"groupby",
"=",
"NotSpecified",
")",
":",
"return",
"GroupedRowTransform",
"(",
"transform",
"=",
"zscore",
",",
"transform_args",
"=",
"(",
")",
",",
"factor",
"=",
"self",
",",
"groupby... | Construct a Factor that Z-Scores each day's results.
The Z-Score of a row is defined as::
(row - row.mean()) / row.stddev()
If ``mask`` is supplied, ignore values where ``mask`` returns False
when computing row means and standard deviations, and output NaN
anywhere the mas... | [
"Construct",
"a",
"Factor",
"that",
"Z",
"-",
"Scores",
"each",
"day",
"s",
"results",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L531-L591 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | Factor.rank | def rank(self,
method='ordinal',
ascending=True,
mask=NotSpecified,
groupby=NotSpecified):
"""
Construct a new Factor representing the sorted rank of each column
within each row.
Parameters
----------
method : str, {'or... | python | def rank(self,
method='ordinal',
ascending=True,
mask=NotSpecified,
groupby=NotSpecified):
"""
Construct a new Factor representing the sorted rank of each column
within each row.
Parameters
----------
method : str, {'or... | [
"def",
"rank",
"(",
"self",
",",
"method",
"=",
"'ordinal'",
",",
"ascending",
"=",
"True",
",",
"mask",
"=",
"NotSpecified",
",",
"groupby",
"=",
"NotSpecified",
")",
":",
"if",
"groupby",
"is",
"NotSpecified",
":",
"return",
"Rank",
"(",
"self",
",",
... | Construct a new Factor representing the sorted rank of each column
within each row.
Parameters
----------
method : str, {'ordinal', 'min', 'max', 'dense', 'average'}
The method used to assign ranks to tied elements. See
`scipy.stats.rankdata` for a full descripti... | [
"Construct",
"a",
"new",
"Factor",
"representing",
"the",
"sorted",
"rank",
"of",
"each",
"column",
"within",
"each",
"row",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L593-L651 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | Factor.pearsonr | def pearsonr(self, target, correlation_length, mask=NotSpecified):
"""
Construct a new Factor that computes rolling pearson correlation
coefficients between `target` and the columns of `self`.
This method can only be called on factors which are deemed safe for use
as inputs to o... | python | def pearsonr(self, target, correlation_length, mask=NotSpecified):
"""
Construct a new Factor that computes rolling pearson correlation
coefficients between `target` and the columns of `self`.
This method can only be called on factors which are deemed safe for use
as inputs to o... | [
"def",
"pearsonr",
"(",
"self",
",",
"target",
",",
"correlation_length",
",",
"mask",
"=",
"NotSpecified",
")",
":",
"from",
".",
"statistical",
"import",
"RollingPearson",
"return",
"RollingPearson",
"(",
"base_factor",
"=",
"self",
",",
"target",
"=",
"targ... | Construct a new Factor that computes rolling pearson correlation
coefficients between `target` and the columns of `self`.
This method can only be called on factors which are deemed safe for use
as inputs to other factors. This includes `Returns` and any factors
created from `Factor.rank... | [
"Construct",
"a",
"new",
"Factor",
"that",
"computes",
"rolling",
"pearson",
"correlation",
"coefficients",
"between",
"target",
"and",
"the",
"columns",
"of",
"self",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L656-L716 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | Factor.spearmanr | def spearmanr(self, target, correlation_length, mask=NotSpecified):
"""
Construct a new Factor that computes rolling spearman rank correlation
coefficients between `target` and the columns of `self`.
This method can only be called on factors which are deemed safe for use
as inpu... | python | def spearmanr(self, target, correlation_length, mask=NotSpecified):
"""
Construct a new Factor that computes rolling spearman rank correlation
coefficients between `target` and the columns of `self`.
This method can only be called on factors which are deemed safe for use
as inpu... | [
"def",
"spearmanr",
"(",
"self",
",",
"target",
",",
"correlation_length",
",",
"mask",
"=",
"NotSpecified",
")",
":",
"from",
".",
"statistical",
"import",
"RollingSpearman",
"return",
"RollingSpearman",
"(",
"base_factor",
"=",
"self",
",",
"target",
"=",
"t... | Construct a new Factor that computes rolling spearman rank correlation
coefficients between `target` and the columns of `self`.
This method can only be called on factors which are deemed safe for use
as inputs to other factors. This includes `Returns` and any factors
created from `Facto... | [
"Construct",
"a",
"new",
"Factor",
"that",
"computes",
"rolling",
"spearman",
"rank",
"correlation",
"coefficients",
"between",
"target",
"and",
"the",
"columns",
"of",
"self",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L721-L781 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | Factor.linear_regression | def linear_regression(self, target, regression_length, mask=NotSpecified):
"""
Construct a new Factor that performs an ordinary least-squares
regression predicting the columns of `self` from `target`.
This method can only be called on factors which are deemed safe for use
as inp... | python | def linear_regression(self, target, regression_length, mask=NotSpecified):
"""
Construct a new Factor that performs an ordinary least-squares
regression predicting the columns of `self` from `target`.
This method can only be called on factors which are deemed safe for use
as inp... | [
"def",
"linear_regression",
"(",
"self",
",",
"target",
",",
"regression_length",
",",
"mask",
"=",
"NotSpecified",
")",
":",
"from",
".",
"statistical",
"import",
"RollingLinearRegression",
"return",
"RollingLinearRegression",
"(",
"dependent",
"=",
"self",
",",
... | Construct a new Factor that performs an ordinary least-squares
regression predicting the columns of `self` from `target`.
This method can only be called on factors which are deemed safe for use
as inputs to other factors. This includes `Returns` and any factors
created from `Factor.rank... | [
"Construct",
"a",
"new",
"Factor",
"that",
"performs",
"an",
"ordinary",
"least",
"-",
"squares",
"regression",
"predicting",
"the",
"columns",
"of",
"self",
"from",
"target",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L786-L843 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | Factor.winsorize | def winsorize(self,
min_percentile,
max_percentile,
mask=NotSpecified,
groupby=NotSpecified):
"""
Construct a new factor that winsorizes the result of this factor.
Winsorizing changes values ranked less than the minimum per... | python | def winsorize(self,
min_percentile,
max_percentile,
mask=NotSpecified,
groupby=NotSpecified):
"""
Construct a new factor that winsorizes the result of this factor.
Winsorizing changes values ranked less than the minimum per... | [
"def",
"winsorize",
"(",
"self",
",",
"min_percentile",
",",
"max_percentile",
",",
"mask",
"=",
"NotSpecified",
",",
"groupby",
"=",
"NotSpecified",
")",
":",
"if",
"not",
"0.0",
"<=",
"min_percentile",
"<",
"max_percentile",
"<=",
"1.0",
":",
"raise",
"Bad... | Construct a new factor that winsorizes the result of this factor.
Winsorizing changes values ranked less than the minimum percentile to
the value at the minimum percentile. Similarly, values ranking above
the maximum percentile are changed to the value at the maximum
percentile.
... | [
"Construct",
"a",
"new",
"factor",
"that",
"winsorizes",
"the",
"result",
"of",
"this",
"factor",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L852-L947 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | Factor.quantiles | def quantiles(self, bins, mask=NotSpecified):
"""
Construct a Classifier computing quantiles of the output of ``self``.
Every non-NaN data point the output is labelled with an integer value
from 0 to (bins - 1). NaNs are labelled with -1.
If ``mask`` is supplied, ignore data p... | python | def quantiles(self, bins, mask=NotSpecified):
"""
Construct a Classifier computing quantiles of the output of ``self``.
Every non-NaN data point the output is labelled with an integer value
from 0 to (bins - 1). NaNs are labelled with -1.
If ``mask`` is supplied, ignore data p... | [
"def",
"quantiles",
"(",
"self",
",",
"bins",
",",
"mask",
"=",
"NotSpecified",
")",
":",
"if",
"mask",
"is",
"NotSpecified",
":",
"mask",
"=",
"self",
".",
"mask",
"return",
"Quantiles",
"(",
"inputs",
"=",
"(",
"self",
",",
")",
",",
"bins",
"=",
... | Construct a Classifier computing quantiles of the output of ``self``.
Every non-NaN data point the output is labelled with an integer value
from 0 to (bins - 1). NaNs are labelled with -1.
If ``mask`` is supplied, ignore data points in locations for which
``mask`` produces False, and ... | [
"Construct",
"a",
"Classifier",
"computing",
"quantiles",
"of",
"the",
"output",
"of",
"self",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L950-L974 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | Factor.top | def top(self, N, mask=NotSpecified, groupby=NotSpecified):
"""
Construct a Filter matching the top N asset values of self each day.
If ``groupby`` is supplied, returns a Filter matching the top N asset
values for each group.
Parameters
----------
N : int
... | python | def top(self, N, mask=NotSpecified, groupby=NotSpecified):
"""
Construct a Filter matching the top N asset values of self each day.
If ``groupby`` is supplied, returns a Filter matching the top N asset
values for each group.
Parameters
----------
N : int
... | [
"def",
"top",
"(",
"self",
",",
"N",
",",
"mask",
"=",
"NotSpecified",
",",
"groupby",
"=",
"NotSpecified",
")",
":",
"if",
"N",
"==",
"1",
":",
"# Special case: if N == 1, we can avoid doing a full sort on every",
"# group, which is a big win.",
"return",
"self",
"... | Construct a Filter matching the top N asset values of self each day.
If ``groupby`` is supplied, returns a Filter matching the top N asset
values for each group.
Parameters
----------
N : int
Number of assets passing the returned filter each day.
mask : zipl... | [
"Construct",
"a",
"Filter",
"matching",
"the",
"top",
"N",
"asset",
"values",
"of",
"self",
"each",
"day",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L1048-L1074 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | Factor.bottom | def bottom(self, N, mask=NotSpecified, groupby=NotSpecified):
"""
Construct a Filter matching the bottom N asset values of self each day.
If ``groupby`` is supplied, returns a Filter matching the bottom N
asset values for each group.
Parameters
----------
N : in... | python | def bottom(self, N, mask=NotSpecified, groupby=NotSpecified):
"""
Construct a Filter matching the bottom N asset values of self each day.
If ``groupby`` is supplied, returns a Filter matching the bottom N
asset values for each group.
Parameters
----------
N : in... | [
"def",
"bottom",
"(",
"self",
",",
"N",
",",
"mask",
"=",
"NotSpecified",
",",
"groupby",
"=",
"NotSpecified",
")",
":",
"return",
"self",
".",
"rank",
"(",
"ascending",
"=",
"True",
",",
"mask",
"=",
"mask",
",",
"groupby",
"=",
"groupby",
")",
"<="... | Construct a Filter matching the bottom N asset values of self each day.
If ``groupby`` is supplied, returns a Filter matching the bottom N
asset values for each group.
Parameters
----------
N : int
Number of assets passing the returned filter each day.
mask ... | [
"Construct",
"a",
"Filter",
"matching",
"the",
"bottom",
"N",
"asset",
"values",
"of",
"self",
"each",
"day",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L1076-L1098 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | Factor.percentile_between | def percentile_between(self,
min_percentile,
max_percentile,
mask=NotSpecified):
"""
Construct a new Filter representing entries from the output of this
Factor that fall within the percentile range defined by min_pe... | python | def percentile_between(self,
min_percentile,
max_percentile,
mask=NotSpecified):
"""
Construct a new Filter representing entries from the output of this
Factor that fall within the percentile range defined by min_pe... | [
"def",
"percentile_between",
"(",
"self",
",",
"min_percentile",
",",
"max_percentile",
",",
"mask",
"=",
"NotSpecified",
")",
":",
"return",
"PercentileFilter",
"(",
"self",
",",
"min_percentile",
"=",
"min_percentile",
",",
"max_percentile",
"=",
"max_percentile",... | Construct a new Filter representing entries from the output of this
Factor that fall within the percentile range defined by min_percentile
and max_percentile.
Parameters
----------
min_percentile : float [0.0, 100.0]
Return True for assets falling above this percenti... | [
"Construct",
"a",
"new",
"Filter",
"representing",
"entries",
"from",
"the",
"output",
"of",
"this",
"Factor",
"that",
"fall",
"within",
"the",
"percentile",
"range",
"defined",
"by",
"min_percentile",
"and",
"max_percentile",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L1103-L1139 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | Rank._validate | def _validate(self):
"""
Verify that the stored rank method is valid.
"""
if self._method not in _RANK_METHODS:
raise UnknownRankMethod(
method=self._method,
choices=set(_RANK_METHODS),
)
return super(Rank, self)._validate() | python | def _validate(self):
"""
Verify that the stored rank method is valid.
"""
if self._method not in _RANK_METHODS:
raise UnknownRankMethod(
method=self._method,
choices=set(_RANK_METHODS),
)
return super(Rank, self)._validate() | [
"def",
"_validate",
"(",
"self",
")",
":",
"if",
"self",
".",
"_method",
"not",
"in",
"_RANK_METHODS",
":",
"raise",
"UnknownRankMethod",
"(",
"method",
"=",
"self",
".",
"_method",
",",
"choices",
"=",
"set",
"(",
"_RANK_METHODS",
")",
",",
")",
"return... | Verify that the stored rank method is valid. | [
"Verify",
"that",
"the",
"stored",
"rank",
"method",
"is",
"valid",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L1382-L1391 | train |
quantopian/zipline | zipline/pipeline/factors/factor.py | Rank._compute | def _compute(self, arrays, dates, assets, mask):
"""
For each row in the input, compute a like-shaped array of per-row
ranks.
"""
return masked_rankdata_2d(
arrays[0],
mask,
self.inputs[0].missing_value,
self._method,
se... | python | def _compute(self, arrays, dates, assets, mask):
"""
For each row in the input, compute a like-shaped array of per-row
ranks.
"""
return masked_rankdata_2d(
arrays[0],
mask,
self.inputs[0].missing_value,
self._method,
se... | [
"def",
"_compute",
"(",
"self",
",",
"arrays",
",",
"dates",
",",
"assets",
",",
"mask",
")",
":",
"return",
"masked_rankdata_2d",
"(",
"arrays",
"[",
"0",
"]",
",",
"mask",
",",
"self",
".",
"inputs",
"[",
"0",
"]",
".",
"missing_value",
",",
"self"... | For each row in the input, compute a like-shaped array of per-row
ranks. | [
"For",
"each",
"row",
"in",
"the",
"input",
"compute",
"a",
"like",
"-",
"shaped",
"array",
"of",
"per",
"-",
"row",
"ranks",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/factors/factor.py#L1393-L1404 | train |
quantopian/zipline | zipline/utils/pandas_utils.py | _time_to_micros | def _time_to_micros(time):
"""Convert a time into microseconds since midnight.
Parameters
----------
time : datetime.time
The time to convert.
Returns
-------
us : int
The number of microseconds since midnight.
Notes
-----
This does not account for leap seconds or... | python | def _time_to_micros(time):
"""Convert a time into microseconds since midnight.
Parameters
----------
time : datetime.time
The time to convert.
Returns
-------
us : int
The number of microseconds since midnight.
Notes
-----
This does not account for leap seconds or... | [
"def",
"_time_to_micros",
"(",
"time",
")",
":",
"seconds",
"=",
"time",
".",
"hour",
"*",
"60",
"*",
"60",
"+",
"time",
".",
"minute",
"*",
"60",
"+",
"time",
".",
"second",
"return",
"1000000",
"*",
"seconds",
"+",
"time",
".",
"microsecond"
] | Convert a time into microseconds since midnight.
Parameters
----------
time : datetime.time
The time to convert.
Returns
-------
us : int
The number of microseconds since midnight.
Notes
-----
This does not account for leap seconds or daylight savings. | [
"Convert",
"a",
"time",
"into",
"microseconds",
"since",
"midnight",
".",
"Parameters",
"----------",
"time",
":",
"datetime",
".",
"time",
"The",
"time",
"to",
"convert",
".",
"Returns",
"-------",
"us",
":",
"int",
"The",
"number",
"of",
"microseconds",
"s... | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/utils/pandas_utils.py#L48-L63 | train |
quantopian/zipline | zipline/utils/pandas_utils.py | mask_between_time | def mask_between_time(dts, start, end, include_start=True, include_end=True):
"""Return a mask of all of the datetimes in ``dts`` that are between
``start`` and ``end``.
Parameters
----------
dts : pd.DatetimeIndex
The index to mask.
start : time
Mask away times less than the sta... | python | def mask_between_time(dts, start, end, include_start=True, include_end=True):
"""Return a mask of all of the datetimes in ``dts`` that are between
``start`` and ``end``.
Parameters
----------
dts : pd.DatetimeIndex
The index to mask.
start : time
Mask away times less than the sta... | [
"def",
"mask_between_time",
"(",
"dts",
",",
"start",
",",
"end",
",",
"include_start",
"=",
"True",
",",
"include_end",
"=",
"True",
")",
":",
"# This function is adapted from",
"# `pandas.Datetime.Index.indexer_between_time` which was originally",
"# written by Wes McKinney... | Return a mask of all of the datetimes in ``dts`` that are between
``start`` and ``end``.
Parameters
----------
dts : pd.DatetimeIndex
The index to mask.
start : time
Mask away times less than the start.
end : time
Mask away times greater than the end.
include_start : ... | [
"Return",
"a",
"mask",
"of",
"all",
"of",
"the",
"datetimes",
"in",
"dts",
"that",
"are",
"between",
"start",
"and",
"end",
".",
"Parameters",
"----------",
"dts",
":",
"pd",
".",
"DatetimeIndex",
"The",
"index",
"to",
"mask",
".",
"start",
":",
"time",
... | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/utils/pandas_utils.py#L72-L111 | train |
quantopian/zipline | zipline/utils/pandas_utils.py | find_in_sorted_index | def find_in_sorted_index(dts, dt):
"""
Find the index of ``dt`` in ``dts``.
This function should be used instead of `dts.get_loc(dt)` if the index is
large enough that we don't want to initialize a hash table in ``dts``. In
particular, this should always be used on minutely trading calendars.
... | python | def find_in_sorted_index(dts, dt):
"""
Find the index of ``dt`` in ``dts``.
This function should be used instead of `dts.get_loc(dt)` if the index is
large enough that we don't want to initialize a hash table in ``dts``. In
particular, this should always be used on minutely trading calendars.
... | [
"def",
"find_in_sorted_index",
"(",
"dts",
",",
"dt",
")",
":",
"ix",
"=",
"dts",
".",
"searchsorted",
"(",
"dt",
")",
"if",
"ix",
"==",
"len",
"(",
"dts",
")",
"or",
"dts",
"[",
"ix",
"]",
"!=",
"dt",
":",
"raise",
"LookupError",
"(",
"\"{dt} is n... | Find the index of ``dt`` in ``dts``.
This function should be used instead of `dts.get_loc(dt)` if the index is
large enough that we don't want to initialize a hash table in ``dts``. In
particular, this should always be used on minutely trading calendars.
Parameters
----------
dts : pd.Datetime... | [
"Find",
"the",
"index",
"of",
"dt",
"in",
"dts",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/utils/pandas_utils.py#L114-L142 | train |
quantopian/zipline | zipline/utils/pandas_utils.py | nearest_unequal_elements | def nearest_unequal_elements(dts, dt):
"""
Find values in ``dts`` closest but not equal to ``dt``.
Returns a pair of (last_before, first_after).
When ``dt`` is less than any element in ``dts``, ``last_before`` is None.
When ``dt`` is greater any element in ``dts``, ``first_after`` is None.
``... | python | def nearest_unequal_elements(dts, dt):
"""
Find values in ``dts`` closest but not equal to ``dt``.
Returns a pair of (last_before, first_after).
When ``dt`` is less than any element in ``dts``, ``last_before`` is None.
When ``dt`` is greater any element in ``dts``, ``first_after`` is None.
``... | [
"def",
"nearest_unequal_elements",
"(",
"dts",
",",
"dt",
")",
":",
"if",
"not",
"dts",
".",
"is_unique",
":",
"raise",
"ValueError",
"(",
"\"dts must be unique\"",
")",
"if",
"not",
"dts",
".",
"is_monotonic_increasing",
":",
"raise",
"ValueError",
"(",
"\"dt... | Find values in ``dts`` closest but not equal to ``dt``.
Returns a pair of (last_before, first_after).
When ``dt`` is less than any element in ``dts``, ``last_before`` is None.
When ``dt`` is greater any element in ``dts``, ``first_after`` is None.
``dts`` must be unique and sorted in increasing order... | [
"Find",
"values",
"in",
"dts",
"closest",
"but",
"not",
"equal",
"to",
"dt",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/utils/pandas_utils.py#L145-L192 | train |
quantopian/zipline | zipline/utils/pandas_utils.py | categorical_df_concat | def categorical_df_concat(df_list, inplace=False):
"""
Prepare list of pandas DataFrames to be used as input to pd.concat.
Ensure any columns of type 'category' have the same categories across each
dataframe.
Parameters
----------
df_list : list
List of dataframes with same columns.... | python | def categorical_df_concat(df_list, inplace=False):
"""
Prepare list of pandas DataFrames to be used as input to pd.concat.
Ensure any columns of type 'category' have the same categories across each
dataframe.
Parameters
----------
df_list : list
List of dataframes with same columns.... | [
"def",
"categorical_df_concat",
"(",
"df_list",
",",
"inplace",
"=",
"False",
")",
":",
"if",
"not",
"inplace",
":",
"df_list",
"=",
"deepcopy",
"(",
"df_list",
")",
"# Assert each dataframe has the same columns/dtypes",
"df",
"=",
"df_list",
"[",
"0",
"]",
"if"... | Prepare list of pandas DataFrames to be used as input to pd.concat.
Ensure any columns of type 'category' have the same categories across each
dataframe.
Parameters
----------
df_list : list
List of dataframes with same columns.
inplace : bool
True if input list can be modified.... | [
"Prepare",
"list",
"of",
"pandas",
"DataFrames",
"to",
"be",
"used",
"as",
"input",
"to",
"pd",
".",
"concat",
".",
"Ensure",
"any",
"columns",
"of",
"type",
"category",
"have",
"the",
"same",
"categories",
"across",
"each",
"dataframe",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/utils/pandas_utils.py#L247-L287 | train |
quantopian/zipline | zipline/utils/pandas_utils.py | check_indexes_all_same | def check_indexes_all_same(indexes, message="Indexes are not equal."):
"""Check that a list of Index objects are all equal.
Parameters
----------
indexes : iterable[pd.Index]
Iterable of indexes to check.
Raises
------
ValueError
If the indexes are not all the same.
"""... | python | def check_indexes_all_same(indexes, message="Indexes are not equal."):
"""Check that a list of Index objects are all equal.
Parameters
----------
indexes : iterable[pd.Index]
Iterable of indexes to check.
Raises
------
ValueError
If the indexes are not all the same.
"""... | [
"def",
"check_indexes_all_same",
"(",
"indexes",
",",
"message",
"=",
"\"Indexes are not equal.\"",
")",
":",
"iterator",
"=",
"iter",
"(",
"indexes",
")",
"first",
"=",
"next",
"(",
"iterator",
")",
"for",
"other",
"in",
"iterator",
":",
"same",
"=",
"(",
... | Check that a list of Index objects are all equal.
Parameters
----------
indexes : iterable[pd.Index]
Iterable of indexes to check.
Raises
------
ValueError
If the indexes are not all the same. | [
"Check",
"that",
"a",
"list",
"of",
"Index",
"objects",
"are",
"all",
"equal",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/utils/pandas_utils.py#L325-L349 | train |
quantopian/zipline | zipline/pipeline/loaders/events.py | required_event_fields | def required_event_fields(next_value_columns, previous_value_columns):
"""
Compute the set of resource columns required to serve
``next_value_columns`` and ``previous_value_columns``.
"""
# These metadata columns are used to align event indexers.
return {
TS_FIELD_NAME,
SID_FIELD... | python | def required_event_fields(next_value_columns, previous_value_columns):
"""
Compute the set of resource columns required to serve
``next_value_columns`` and ``previous_value_columns``.
"""
# These metadata columns are used to align event indexers.
return {
TS_FIELD_NAME,
SID_FIELD... | [
"def",
"required_event_fields",
"(",
"next_value_columns",
",",
"previous_value_columns",
")",
":",
"# These metadata columns are used to align event indexers.",
"return",
"{",
"TS_FIELD_NAME",
",",
"SID_FIELD_NAME",
",",
"EVENT_DATE_FIELD_NAME",
",",
"}",
".",
"union",
"(",
... | Compute the set of resource columns required to serve
``next_value_columns`` and ``previous_value_columns``. | [
"Compute",
"the",
"set",
"of",
"resource",
"columns",
"required",
"to",
"serve",
"next_value_columns",
"and",
"previous_value_columns",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/events.py#L21-L36 | train |
quantopian/zipline | zipline/pipeline/loaders/events.py | validate_column_specs | def validate_column_specs(events, next_value_columns, previous_value_columns):
"""
Verify that the columns of ``events`` can be used by an EventsLoader to
serve the BoundColumns described by ``next_value_columns`` and
``previous_value_columns``.
"""
required = required_event_fields(next_value_co... | python | def validate_column_specs(events, next_value_columns, previous_value_columns):
"""
Verify that the columns of ``events`` can be used by an EventsLoader to
serve the BoundColumns described by ``next_value_columns`` and
``previous_value_columns``.
"""
required = required_event_fields(next_value_co... | [
"def",
"validate_column_specs",
"(",
"events",
",",
"next_value_columns",
",",
"previous_value_columns",
")",
":",
"required",
"=",
"required_event_fields",
"(",
"next_value_columns",
",",
"previous_value_columns",
")",
"received",
"=",
"set",
"(",
"events",
".",
"col... | Verify that the columns of ``events`` can be used by an EventsLoader to
serve the BoundColumns described by ``next_value_columns`` and
``previous_value_columns``. | [
"Verify",
"that",
"the",
"columns",
"of",
"events",
"can",
"be",
"used",
"by",
"an",
"EventsLoader",
"to",
"serve",
"the",
"BoundColumns",
"described",
"by",
"next_value_columns",
"and",
"previous_value_columns",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/events.py#L39-L58 | train |
quantopian/zipline | zipline/pipeline/loaders/events.py | EventsLoader.split_next_and_previous_event_columns | def split_next_and_previous_event_columns(self, requested_columns):
"""
Split requested columns into columns that should load the next known
value and columns that should load the previous known value.
Parameters
----------
requested_columns : iterable[BoundColumn]
... | python | def split_next_and_previous_event_columns(self, requested_columns):
"""
Split requested columns into columns that should load the next known
value and columns that should load the previous known value.
Parameters
----------
requested_columns : iterable[BoundColumn]
... | [
"def",
"split_next_and_previous_event_columns",
"(",
"self",
",",
"requested_columns",
")",
":",
"def",
"next_or_previous",
"(",
"c",
")",
":",
"if",
"c",
"in",
"self",
".",
"next_value_columns",
":",
"return",
"'next'",
"elif",
"c",
"in",
"self",
".",
"previo... | Split requested columns into columns that should load the next known
value and columns that should load the previous known value.
Parameters
----------
requested_columns : iterable[BoundColumn]
Returns
-------
next_cols, previous_cols : iterable[BoundColumn], it... | [
"Split",
"requested",
"columns",
"into",
"columns",
"that",
"should",
"load",
"the",
"next",
"known",
"value",
"and",
"columns",
"that",
"should",
"load",
"the",
"previous",
"known",
"value",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/loaders/events.py#L119-L146 | train |
quantopian/zipline | zipline/lib/labelarray.py | compare_arrays | def compare_arrays(left, right):
"Eq check with a short-circuit for identical objects."
return (
left is right
or ((left.shape == right.shape) and (left == right).all())
) | python | def compare_arrays(left, right):
"Eq check with a short-circuit for identical objects."
return (
left is right
or ((left.shape == right.shape) and (left == right).all())
) | [
"def",
"compare_arrays",
"(",
"left",
",",
"right",
")",
":",
"return",
"(",
"left",
"is",
"right",
"or",
"(",
"(",
"left",
".",
"shape",
"==",
"right",
".",
"shape",
")",
"and",
"(",
"left",
"==",
"right",
")",
".",
"all",
"(",
")",
")",
")"
] | Eq check with a short-circuit for identical objects. | [
"Eq",
"check",
"with",
"a",
"short",
"-",
"circuit",
"for",
"identical",
"objects",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/lib/labelarray.py#L38-L43 | train |
quantopian/zipline | zipline/lib/labelarray.py | LabelArray.from_codes_and_metadata | def from_codes_and_metadata(cls,
codes,
categories,
reverse_categories,
missing_value):
"""
Rehydrate a LabelArray from the codes and metadata.
Parameters
----... | python | def from_codes_and_metadata(cls,
codes,
categories,
reverse_categories,
missing_value):
"""
Rehydrate a LabelArray from the codes and metadata.
Parameters
----... | [
"def",
"from_codes_and_metadata",
"(",
"cls",
",",
"codes",
",",
"categories",
",",
"reverse_categories",
",",
"missing_value",
")",
":",
"ret",
"=",
"codes",
".",
"view",
"(",
"type",
"=",
"cls",
",",
"dtype",
"=",
"np",
".",
"void",
")",
"ret",
".",
... | Rehydrate a LabelArray from the codes and metadata.
Parameters
----------
codes : np.ndarray[integral]
The codes for the label array.
categories : np.ndarray[object]
The unique string categories.
reverse_categories : dict[str, int]
The mapping... | [
"Rehydrate",
"a",
"LabelArray",
"from",
"the",
"codes",
"and",
"metadata",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/lib/labelarray.py#L194-L217 | train |
quantopian/zipline | zipline/lib/labelarray.py | LabelArray.as_int_array | def as_int_array(self):
"""
Convert self into a regular ndarray of ints.
This is an O(1) operation. It does not copy the underlying data.
"""
return self.view(
type=ndarray,
dtype=unsigned_int_dtype_with_size_in_bytes(self.itemsize),
) | python | def as_int_array(self):
"""
Convert self into a regular ndarray of ints.
This is an O(1) operation. It does not copy the underlying data.
"""
return self.view(
type=ndarray,
dtype=unsigned_int_dtype_with_size_in_bytes(self.itemsize),
) | [
"def",
"as_int_array",
"(",
"self",
")",
":",
"return",
"self",
".",
"view",
"(",
"type",
"=",
"ndarray",
",",
"dtype",
"=",
"unsigned_int_dtype_with_size_in_bytes",
"(",
"self",
".",
"itemsize",
")",
",",
")"
] | Convert self into a regular ndarray of ints.
This is an O(1) operation. It does not copy the underlying data. | [
"Convert",
"self",
"into",
"a",
"regular",
"ndarray",
"of",
"ints",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/lib/labelarray.py#L303-L312 | train |
quantopian/zipline | zipline/lib/labelarray.py | LabelArray.as_categorical | def as_categorical(self):
"""
Coerce self into a pandas categorical.
This is only defined on 1D arrays, since that's all pandas supports.
"""
if len(self.shape) > 1:
raise ValueError("Can't convert a 2D array to a categorical.")
with ignore_pandas_nan_catego... | python | def as_categorical(self):
"""
Coerce self into a pandas categorical.
This is only defined on 1D arrays, since that's all pandas supports.
"""
if len(self.shape) > 1:
raise ValueError("Can't convert a 2D array to a categorical.")
with ignore_pandas_nan_catego... | [
"def",
"as_categorical",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"shape",
")",
">",
"1",
":",
"raise",
"ValueError",
"(",
"\"Can't convert a 2D array to a categorical.\"",
")",
"with",
"ignore_pandas_nan_categorical_warning",
"(",
")",
":",
"return",... | Coerce self into a pandas categorical.
This is only defined on 1D arrays, since that's all pandas supports. | [
"Coerce",
"self",
"into",
"a",
"pandas",
"categorical",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/lib/labelarray.py#L322-L338 | train |
quantopian/zipline | zipline/lib/labelarray.py | LabelArray.as_categorical_frame | def as_categorical_frame(self, index, columns, name=None):
"""
Coerce self into a pandas DataFrame of Categoricals.
"""
if len(self.shape) != 2:
raise ValueError(
"Can't convert a non-2D LabelArray into a DataFrame."
)
expected_shape = (le... | python | def as_categorical_frame(self, index, columns, name=None):
"""
Coerce self into a pandas DataFrame of Categoricals.
"""
if len(self.shape) != 2:
raise ValueError(
"Can't convert a non-2D LabelArray into a DataFrame."
)
expected_shape = (le... | [
"def",
"as_categorical_frame",
"(",
"self",
",",
"index",
",",
"columns",
",",
"name",
"=",
"None",
")",
":",
"if",
"len",
"(",
"self",
".",
"shape",
")",
"!=",
"2",
":",
"raise",
"ValueError",
"(",
"\"Can't convert a non-2D LabelArray into a DataFrame.\"",
")... | Coerce self into a pandas DataFrame of Categoricals. | [
"Coerce",
"self",
"into",
"a",
"pandas",
"DataFrame",
"of",
"Categoricals",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/lib/labelarray.py#L340-L364 | train |
quantopian/zipline | zipline/lib/labelarray.py | LabelArray.set_scalar | def set_scalar(self, indexer, value):
"""
Set scalar value into the array.
Parameters
----------
indexer : any
The indexer to set the value at.
value : str
The value to assign at the given locations.
Raises
------
ValueErr... | python | def set_scalar(self, indexer, value):
"""
Set scalar value into the array.
Parameters
----------
indexer : any
The indexer to set the value at.
value : str
The value to assign at the given locations.
Raises
------
ValueErr... | [
"def",
"set_scalar",
"(",
"self",
",",
"indexer",
",",
"value",
")",
":",
"try",
":",
"value_code",
"=",
"self",
".",
"reverse_categories",
"[",
"value",
"]",
"except",
"KeyError",
":",
"raise",
"ValueError",
"(",
"\"%r is not in LabelArray categories.\"",
"%",
... | Set scalar value into the array.
Parameters
----------
indexer : any
The indexer to set the value at.
value : str
The value to assign at the given locations.
Raises
------
ValueError
Raised when ``value`` is not a value elemen... | [
"Set",
"scalar",
"value",
"into",
"the",
"array",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/lib/labelarray.py#L400-L422 | train |
quantopian/zipline | zipline/lib/labelarray.py | LabelArray._equality_check | def _equality_check(op):
"""
Shared code for __eq__ and __ne__, parameterized on the actual
comparison operator to use.
"""
def method(self, other):
if isinstance(other, LabelArray):
self_mv = self.missing_value
other_mv = other.missin... | python | def _equality_check(op):
"""
Shared code for __eq__ and __ne__, parameterized on the actual
comparison operator to use.
"""
def method(self, other):
if isinstance(other, LabelArray):
self_mv = self.missing_value
other_mv = other.missin... | [
"def",
"_equality_check",
"(",
"op",
")",
":",
"def",
"method",
"(",
"self",
",",
"other",
")",
":",
"if",
"isinstance",
"(",
"other",
",",
"LabelArray",
")",
":",
"self_mv",
"=",
"self",
".",
"missing_value",
"other_mv",
"=",
"other",
".",
"missing_valu... | Shared code for __eq__ and __ne__, parameterized on the actual
comparison operator to use. | [
"Shared",
"code",
"for",
"__eq__",
"and",
"__ne__",
"parameterized",
"on",
"the",
"actual",
"comparison",
"operator",
"to",
"use",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/lib/labelarray.py#L462-L496 | train |
quantopian/zipline | zipline/lib/labelarray.py | LabelArray.empty_like | def empty_like(self, shape):
"""
Make an empty LabelArray with the same categories as ``self``, filled
with ``self.missing_value``.
"""
return type(self).from_codes_and_metadata(
codes=np.full(
shape,
self.reverse_categories[self.missin... | python | def empty_like(self, shape):
"""
Make an empty LabelArray with the same categories as ``self``, filled
with ``self.missing_value``.
"""
return type(self).from_codes_and_metadata(
codes=np.full(
shape,
self.reverse_categories[self.missin... | [
"def",
"empty_like",
"(",
"self",
",",
"shape",
")",
":",
"return",
"type",
"(",
"self",
")",
".",
"from_codes_and_metadata",
"(",
"codes",
"=",
"np",
".",
"full",
"(",
"shape",
",",
"self",
".",
"reverse_categories",
"[",
"self",
".",
"missing_value",
"... | Make an empty LabelArray with the same categories as ``self``, filled
with ``self.missing_value``. | [
"Make",
"an",
"empty",
"LabelArray",
"with",
"the",
"same",
"categories",
"as",
"self",
"filled",
"with",
"self",
".",
"missing_value",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/lib/labelarray.py#L605-L619 | train |
quantopian/zipline | zipline/lib/labelarray.py | LabelArray.map_predicate | def map_predicate(self, f):
"""
Map a function from str -> bool element-wise over ``self``.
``f`` will be applied exactly once to each non-missing unique value in
``self``. Missing values will always return False.
"""
# Functions passed to this are of type str -> bool. ... | python | def map_predicate(self, f):
"""
Map a function from str -> bool element-wise over ``self``.
``f`` will be applied exactly once to each non-missing unique value in
``self``. Missing values will always return False.
"""
# Functions passed to this are of type str -> bool. ... | [
"def",
"map_predicate",
"(",
"self",
",",
"f",
")",
":",
"# Functions passed to this are of type str -> bool. Don't ever call",
"# them on None, which is the only non-str value we ever store in",
"# categories.",
"if",
"self",
".",
"missing_value",
"is",
"None",
":",
"def",
"f... | Map a function from str -> bool element-wise over ``self``.
``f`` will be applied exactly once to each non-missing unique value in
``self``. Missing values will always return False. | [
"Map",
"a",
"function",
"from",
"str",
"-",
">",
"bool",
"element",
"-",
"wise",
"over",
"self",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/lib/labelarray.py#L621-L645 | train |
quantopian/zipline | zipline/lib/labelarray.py | LabelArray.map | def map(self, f):
"""
Map a function from str -> str element-wise over ``self``.
``f`` will be applied exactly once to each non-missing unique value in
``self``. Missing values will always map to ``self.missing_value``.
"""
# f() should only return None if None is our mi... | python | def map(self, f):
"""
Map a function from str -> str element-wise over ``self``.
``f`` will be applied exactly once to each non-missing unique value in
``self``. Missing values will always map to ``self.missing_value``.
"""
# f() should only return None if None is our mi... | [
"def",
"map",
"(",
"self",
",",
"f",
")",
":",
"# f() should only return None if None is our missing value.",
"if",
"self",
".",
"missing_value",
"is",
"None",
":",
"allowed_outtypes",
"=",
"self",
".",
"SUPPORTED_SCALAR_TYPES",
"else",
":",
"allowed_outtypes",
"=",
... | Map a function from str -> str element-wise over ``self``.
``f`` will be applied exactly once to each non-missing unique value in
``self``. Missing values will always map to ``self.missing_value``. | [
"Map",
"a",
"function",
"from",
"str",
"-",
">",
"str",
"element",
"-",
"wise",
"over",
"self",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/lib/labelarray.py#L647-L722 | train |
quantopian/zipline | zipline/finance/execution.py | asymmetric_round_price | def asymmetric_round_price(price, prefer_round_down, tick_size, diff=0.95):
"""
Asymmetric rounding function for adjusting prices to the specified number
of places in a way that "improves" the price. For limit prices, this means
preferring to round down on buys and preferring to round up on sells.
F... | python | def asymmetric_round_price(price, prefer_round_down, tick_size, diff=0.95):
"""
Asymmetric rounding function for adjusting prices to the specified number
of places in a way that "improves" the price. For limit prices, this means
preferring to round down on buys and preferring to round up on sells.
F... | [
"def",
"asymmetric_round_price",
"(",
"price",
",",
"prefer_round_down",
",",
"tick_size",
",",
"diff",
"=",
"0.95",
")",
":",
"precision",
"=",
"zp_math",
".",
"number_of_decimal_places",
"(",
"tick_size",
")",
"multiplier",
"=",
"int",
"(",
"tick_size",
"*",
... | Asymmetric rounding function for adjusting prices to the specified number
of places in a way that "improves" the price. For limit prices, this means
preferring to round down on buys and preferring to round up on sells.
For stop prices, it means the reverse.
If prefer_round_down == True:
When .0... | [
"Asymmetric",
"rounding",
"function",
"for",
"adjusting",
"prices",
"to",
"the",
"specified",
"number",
"of",
"places",
"in",
"a",
"way",
"that",
"improves",
"the",
"price",
".",
"For",
"limit",
"prices",
"this",
"means",
"preferring",
"to",
"round",
"down",
... | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/finance/execution.py#L159-L193 | train |
quantopian/zipline | zipline/finance/execution.py | check_stoplimit_prices | def check_stoplimit_prices(price, label):
"""
Check to make sure the stop/limit prices are reasonable and raise
a BadOrderParameters exception if not.
"""
try:
if not isfinite(price):
raise BadOrderParameters(
msg="Attempted to place an order with a {} price "
... | python | def check_stoplimit_prices(price, label):
"""
Check to make sure the stop/limit prices are reasonable and raise
a BadOrderParameters exception if not.
"""
try:
if not isfinite(price):
raise BadOrderParameters(
msg="Attempted to place an order with a {} price "
... | [
"def",
"check_stoplimit_prices",
"(",
"price",
",",
"label",
")",
":",
"try",
":",
"if",
"not",
"isfinite",
"(",
"price",
")",
":",
"raise",
"BadOrderParameters",
"(",
"msg",
"=",
"\"Attempted to place an order with a {} price \"",
"\"of {}.\"",
".",
"format",
"("... | Check to make sure the stop/limit prices are reasonable and raise
a BadOrderParameters exception if not. | [
"Check",
"to",
"make",
"sure",
"the",
"stop",
"/",
"limit",
"prices",
"are",
"reasonable",
"and",
"raise",
"a",
"BadOrderParameters",
"exception",
"if",
"not",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/finance/execution.py#L196-L217 | train |
quantopian/zipline | zipline/data/bundles/csvdir.py | csvdir_bundle | def csvdir_bundle(environ,
asset_db_writer,
minute_bar_writer,
daily_bar_writer,
adjustment_writer,
calendar,
start_session,
end_session,
cache,
show_progress... | python | def csvdir_bundle(environ,
asset_db_writer,
minute_bar_writer,
daily_bar_writer,
adjustment_writer,
calendar,
start_session,
end_session,
cache,
show_progress... | [
"def",
"csvdir_bundle",
"(",
"environ",
",",
"asset_db_writer",
",",
"minute_bar_writer",
",",
"daily_bar_writer",
",",
"adjustment_writer",
",",
"calendar",
",",
"start_session",
",",
"end_session",
",",
"cache",
",",
"show_progress",
",",
"output_dir",
",",
"tfram... | Build a zipline data bundle from the directory with csv files. | [
"Build",
"a",
"zipline",
"data",
"bundle",
"from",
"the",
"directory",
"with",
"csv",
"files",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/data/bundles/csvdir.py#L98-L168 | train |
quantopian/zipline | zipline/pipeline/api_utils.py | restrict_to_dtype | def restrict_to_dtype(dtype, message_template):
"""
A factory for decorators that restrict Term methods to only be callable on
Terms with a specific dtype.
This is conceptually similar to
zipline.utils.input_validation.expect_dtypes, but provides more flexibility
for providing error messages th... | python | def restrict_to_dtype(dtype, message_template):
"""
A factory for decorators that restrict Term methods to only be callable on
Terms with a specific dtype.
This is conceptually similar to
zipline.utils.input_validation.expect_dtypes, but provides more flexibility
for providing error messages th... | [
"def",
"restrict_to_dtype",
"(",
"dtype",
",",
"message_template",
")",
":",
"def",
"processor",
"(",
"term_method",
",",
"_",
",",
"term_instance",
")",
":",
"term_dtype",
"=",
"term_instance",
".",
"dtype",
"if",
"term_dtype",
"!=",
"dtype",
":",
"raise",
... | A factory for decorators that restrict Term methods to only be callable on
Terms with a specific dtype.
This is conceptually similar to
zipline.utils.input_validation.expect_dtypes, but provides more flexibility
for providing error messages that are specifically targeting Term methods.
Parameters
... | [
"A",
"factory",
"for",
"decorators",
"that",
"restrict",
"Term",
"methods",
"to",
"only",
"be",
"callable",
"on",
"Terms",
"with",
"a",
"specific",
"dtype",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/pipeline/api_utils.py#L7-L49 | train |
quantopian/zipline | zipline/sources/benchmark_source.py | BenchmarkSource.daily_returns | def daily_returns(self, start, end=None):
"""Returns the daily returns for the given period.
Parameters
----------
start : datetime
The inclusive starting session label.
end : datetime, optional
The inclusive ending session label. If not provided, treat
... | python | def daily_returns(self, start, end=None):
"""Returns the daily returns for the given period.
Parameters
----------
start : datetime
The inclusive starting session label.
end : datetime, optional
The inclusive ending session label. If not provided, treat
... | [
"def",
"daily_returns",
"(",
"self",
",",
"start",
",",
"end",
"=",
"None",
")",
":",
"if",
"end",
"is",
"None",
":",
"return",
"self",
".",
"_daily_returns",
"[",
"start",
"]",
"return",
"self",
".",
"_daily_returns",
"[",
"start",
":",
"end",
"]"
] | Returns the daily returns for the given period.
Parameters
----------
start : datetime
The inclusive starting session label.
end : datetime, optional
The inclusive ending session label. If not provided, treat
``start`` as a scalar key.
Return... | [
"Returns",
"the",
"daily",
"returns",
"for",
"the",
"given",
"period",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/sources/benchmark_source.py#L124-L145 | train |
quantopian/zipline | zipline/sources/benchmark_source.py | BenchmarkSource._initialize_precalculated_series | def _initialize_precalculated_series(self,
asset,
trading_calendar,
trading_days,
data_portal):
"""
Internal method that pre-calculates the ... | python | def _initialize_precalculated_series(self,
asset,
trading_calendar,
trading_days,
data_portal):
"""
Internal method that pre-calculates the ... | [
"def",
"_initialize_precalculated_series",
"(",
"self",
",",
"asset",
",",
"trading_calendar",
",",
"trading_days",
",",
"data_portal",
")",
":",
"if",
"self",
".",
"emission_rate",
"==",
"\"minute\"",
":",
"minutes",
"=",
"trading_calendar",
".",
"minutes_for_sessi... | Internal method that pre-calculates the benchmark return series for
use in the simulation.
Parameters
----------
asset: Asset to use
trading_calendar: TradingCalendar
trading_days: pd.DateTimeIndex
data_portal: DataPortal
Notes
-----
... | [
"Internal",
"method",
"that",
"pre",
"-",
"calculates",
"the",
"benchmark",
"return",
"series",
"for",
"use",
"in",
"the",
"simulation",
"."
] | 77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe | https://github.com/quantopian/zipline/blob/77ad15e6dc4c1cbcdc133653bac8a63fc704f7fe/zipline/sources/benchmark_source.py#L196-L312 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.