id int64 0 328k | repository_name stringlengths 7 58 | file_path stringlengths 9 302 | class_name stringlengths 5 256 | human_written_code stringlengths 16 2.16M | class_skeleton stringlengths 18 1.49M ⌀ | total_program_units int64 1 1.76k | total_doc_str int64 0 771 | AvgCountLine float64 0 7.89k | AvgCountLineBlank float64 0 297 | AvgCountLineCode float64 0 7.89k | AvgCountLineComment float64 0 7.89k | AvgCyclomatic float64 0 130 | CommentToCodeRatio float64 0 168 | CountClassBase float64 0 40 | CountClassCoupled float64 0 583 | CountClassCoupledModified float64 0 575 | CountClassDerived float64 0 5.35k | CountDeclInstanceMethod float64 0 529 | CountDeclInstanceVariable float64 0 296 | CountDeclMethod float64 0 599 | CountDeclMethodAll float64 0 1.12k | CountLine float64 1 40.4k | CountLineBlank float64 0 8.16k | CountLineCode float64 1 25.7k | CountLineCodeDecl float64 1 8.15k | CountLineCodeExe float64 0 24.2k | CountLineComment float64 0 16.5k | CountStmt float64 1 9.71k | CountStmtDecl float64 1 8.15k | CountStmtExe float64 0 9.69k | MaxCyclomatic float64 0 759 | MaxInheritanceTree float64 0 16 | MaxNesting float64 0 34 | SumCyclomatic float64 0 2.9k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
16,400 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.SymbolNotFound | class SymbolNotFound(ZiplineError):
"""
Raised when a symbol() call contains a non-existant symbol.
"""
msg = "\nSymbol '{symbol}' was not found.\n".strip() | class SymbolNotFound(ZiplineError):
'''
Raised when a symbol() call contains a non-existant symbol.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.75 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 7 | 0 | 4 | 2 | 3 | 3 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,401 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.TermInputsNotSpecified | class TermInputsNotSpecified(ZiplineError):
"""
Raised if a user attempts to construct a term without specifying inputs and
that term does not have class-level default inputs.
"""
msg = '{termname} requires inputs, but no inputs list was passed.' | class TermInputsNotSpecified(ZiplineError):
'''
Raised if a user attempts to construct a term without specifying inputs and
that term does not have class-level default inputs.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 2 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 6 | 0 | 2 | 2 | 1 | 4 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,402 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.TermOutputsEmpty | class TermOutputsEmpty(ZiplineError):
"""
Raised if a user attempts to construct a term with an empty outputs list.
"""
msg = '{termname} requires at least one output when passed an outputs argument.' | class TermOutputsEmpty(ZiplineError):
'''
Raised if a user attempts to construct a term with an empty outputs list.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.6 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 8 | 0 | 5 | 2 | 4 | 3 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,403 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.TradingControlViolation | class TradingControlViolation(ZiplineError):
"""
Raised if an order would violate a constraint set by a TradingControl.
"""
msg = '\nOrder for {amount} shares of {asset} at {datetime} violates trading constraint\n{constraint}.\n'.strip() | class TradingControlViolation(ZiplineError):
'''
Raised if an order would violate a constraint set by a TradingControl.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.6 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 8 | 0 | 5 | 2 | 4 | 3 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,404 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.TransactionVolumeExceedsOrder | class TransactionVolumeExceedsOrder(ZiplineError):
"""
Raised if a transact call returns a transaction with a volume greater than
the corresponding order.
"""
msg = '\nTransaction volume of {txn} exceeds the order volume of {order}.\n'.strip() | class TransactionVolumeExceedsOrder(ZiplineError):
'''
Raised if a transact call returns a transaction with a volume greater than
the corresponding order.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 8 | 0 | 4 | 2 | 3 | 4 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,405 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.TransactionWithNoAmount | class TransactionWithNoAmount(ZiplineError):
"""
Raised if a transact call returns a transaction with zero amount.
"""
msg = '\nTransaction {txn} has an amount of zero.\n'.strip() | class TransactionWithNoAmount(ZiplineError):
'''
Raised if a transact call returns a transaction with zero amount.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.75 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 7 | 0 | 4 | 2 | 3 | 3 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,406 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.TransactionWithNoVolume | class TransactionWithNoVolume(ZiplineError):
"""
Raised if a transact call returns a transaction with zero volume.
"""
msg = '\nTransaction {txn} has a volume of zero.\n'.strip() | class TransactionWithNoVolume(ZiplineError):
'''
Raised if a transact call returns a transaction with zero volume.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.75 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 7 | 0 | 4 | 2 | 3 | 3 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,407 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.TransactionWithWrongDirection | class TransactionWithWrongDirection(ZiplineError):
"""
Raised if a transact call returns a transaction with a direction that
does not match the order.
"""
msg = '\nTransaction {txn} not in same direction as corresponding order {order}.\n'.strip() | class TransactionWithWrongDirection(ZiplineError):
'''
Raised if a transact call returns a transaction with a direction that
does not match the order.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 8 | 0 | 4 | 2 | 3 | 4 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,408 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.UnknownRankMethod | class UnknownRankMethod(ZiplineError):
"""
Raised during construction of a Rank factor when supplied a bad Rank
method.
"""
msg = "Unknown ranking method: '{method}'. `method` must be one of {choices}" | class UnknownRankMethod(ZiplineError):
'''
Raised during construction of a Rank factor when supplied a bad Rank
method.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.8 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 9 | 0 | 5 | 2 | 4 | 4 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,409 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.UnsupportedCancelPolicy | class UnsupportedCancelPolicy(ZiplineError):
"""
Raised if a user script calls set_cancel_policy with an object that isn't
a CancelPolicy.
"""
msg = '\nYou attempted to set the cancel policy with an unsupported class. Please use\nan instance of CancelPolicy.\n'.strip() | class UnsupportedCancelPolicy(ZiplineError):
'''
Raised if a user script calls set_cancel_policy with an object that isn't
a CancelPolicy.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.8 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 9 | 0 | 5 | 2 | 4 | 4 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,410 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.UnsupportedCommissionModel | class UnsupportedCommissionModel(ZiplineError):
"""
Raised if a user script calls the set_commission magic
with a commission object that isn't a PerShare, PerTrade or
PerDollar commission
"""
msg = '\nYou attempted to set commission with an unsupported class. Please use PerShare or PerTrade.\n'.... | class UnsupportedCommissionModel(ZiplineError):
'''
Raised if a user script calls the set_commission magic
with a commission object that isn't a PerShare, PerTrade or
PerDollar commission
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 10 | 0 | 5 | 2 | 4 | 5 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,411 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.UnsupportedDType | class UnsupportedDType(ZiplineError):
"""
Raised when a pipeline Term is constructed with a dtype that's not
supported.
"""
msg = 'Failed to construct {termname}.\nPipeline terms of dtype {dtype} are not yet supported.' | class UnsupportedDType(ZiplineError):
'''
Raised when a pipeline Term is constructed with a dtype that's not
supported.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.8 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 9 | 0 | 5 | 2 | 4 | 4 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,412 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.UnsupportedDataType | class UnsupportedDataType(ZiplineError):
"""
Raised by CustomFactors with unsupported dtypes.
"""
def __init__(self, hint='', **kwargs):
if hint:
hint = ' ' + hint
kwargs['hint'] = hint
super(UnsupportedDataType, self).__init__(**kwargs)
msg = '{typename} instanc... | class UnsupportedDataType(ZiplineError):
'''
Raised by CustomFactors with unsupported dtypes.
'''
def __init__(self, hint='', **kwargs):
pass | 2 | 1 | 5 | 0 | 5 | 0 | 2 | 0.43 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 14 | 11 | 1 | 7 | 3 | 5 | 3 | 7 | 3 | 5 | 2 | 4 | 1 | 2 |
16,413 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.UnsupportedDatetimeFormat | class UnsupportedDatetimeFormat(ZiplineError):
"""
Raised when an unsupported datetime is passed to an API method.
"""
msg = "The input '{input}' passed to '{method}' is not coercible to a pandas.Timestamp object." | class UnsupportedDatetimeFormat(ZiplineError):
'''
Raised when an unsupported datetime is passed to an API method.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 6 | 0 | 3 | 2 | 2 | 3 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,414 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.UnsupportedOrderParameters | class UnsupportedOrderParameters(ZiplineError):
"""
Raised if a set of mutually exclusive parameters are passed to an order
call.
"""
msg = '{msg}' | class UnsupportedOrderParameters(ZiplineError):
'''
Raised if a set of mutually exclusive parameters are passed to an order
call.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 2 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 6 | 0 | 2 | 2 | 1 | 4 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,415 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.UnsupportedPipelineOutput | class UnsupportedPipelineOutput(ZiplineError):
"""
Raised when a 1D term is added as a column to a pipeline.
"""
msg = 'Cannot add column {column_name!r} with term {term}. Adding slices or single-column-output terms as pipeline columns is not currently supported.' | class UnsupportedPipelineOutput(ZiplineError):
'''
Raised when a 1D term is added as a column to a pipeline.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 9 | 0 | 6 | 2 | 5 | 3 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,416 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.UnsupportedSlippageModel | class UnsupportedSlippageModel(ZiplineError):
"""
Raised if a user script calls the set_slippage magic
with a slipage object that isn't a VolumeShareSlippage or
FixedSlipapge
"""
msg = '\nYou attempted to set slippage with an unsupported class. Please use VolumeShareSlippage or FixedSlippage.\n'... | class UnsupportedSlippageModel(ZiplineError):
'''
Raised if a user script calls the set_slippage magic
with a slipage object that isn't a VolumeShareSlippage or
FixedSlipapge
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 10 | 0 | 5 | 2 | 4 | 5 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,417 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.ValueNotFoundForField | class ValueNotFoundForField(ZiplineError):
"""
Raised when a lookup_by_supplementary_mapping() call contains a
value does not exist for the specified mapping type.
"""
msg = "\nValue '{value}' was not found for field '{field}'.\n".strip() | class ValueNotFoundForField(ZiplineError):
'''
Raised when a lookup_by_supplementary_mapping() call contains a
value does not exist for the specified mapping type.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 8 | 0 | 4 | 2 | 3 | 4 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,418 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.WindowLengthNotPositive | class WindowLengthNotPositive(ZiplineError):
"""
Raised when a trailing window would be instantiated with a length less than
1.
"""
msg = 'Expected a window_length greater than 0, got {window_length}.'.strip() | class WindowLengthNotPositive(ZiplineError):
'''
Raised when a trailing window would be instantiated with a length less than
1.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 8 | 0 | 4 | 2 | 3 | 4 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,419 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.WindowLengthNotSpecified | class WindowLengthNotSpecified(ZiplineError):
"""
Raised if a user attempts to construct a term without specifying window
length and that term does not have a class-level default window length.
"""
msg = '{termname} requires a window_length, but no window_length was passed.' | class WindowLengthNotSpecified(ZiplineError):
'''
Raised if a user attempts to construct a term without specifying window
length and that term does not have a class-level default window length.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 8 | 0 | 4 | 2 | 3 | 4 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,420 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.WindowLengthTooLong | class WindowLengthTooLong(ZiplineError):
"""
Raised when a trailing window is instantiated with a lookback greater than
the length of the underlying array.
"""
msg = "Can't construct a rolling window of length {window_length} on an array of length {nrows}.".strip() | class WindowLengthTooLong(ZiplineError):
'''
Raised when a trailing window is instantiated with a lookback greater than
the length of the underlying array.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.8 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 9 | 0 | 5 | 2 | 4 | 4 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,421 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.WrongDataForTransform | class WrongDataForTransform(ZiplineError):
"""
Raised whenever a rolling transform is called on an event that
does not have the necessary properties.
"""
msg = '{transform} requires {fields}. Event cannot be processed.' | class WrongDataForTransform(ZiplineError):
'''
Raised whenever a rolling transform is called on an event that
does not have the necessary properties.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 2 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 6 | 0 | 2 | 2 | 1 | 4 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,422 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.ZeroCapitalError | class ZeroCapitalError(ZiplineError):
"""
Raised if initial capital is set at or below zero
"""
msg = 'initial capital base must be greater than zero' | class ZeroCapitalError(ZiplineError):
'''
Raised if initial capital is set at or below zero
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 13 | 5 | 0 | 2 | 2 | 1 | 3 | 2 | 2 | 1 | 0 | 4 | 0 | 0 |
16,423 | quantopian/zipline | quantopian_zipline/zipline/errors.py | zipline.errors.ZiplineError | from zipline.utils.memoize import lazyval
class ZiplineError(Exception):
msg = None
def __init__(self, **kwargs):
self.kwargs = kwargs
@lazyval
def message(self):
return str(self)
def __str__(self):
msg = self.msg.format(**self.kwargs)
return msg
__unicode__ =... |
class ZiplineError(Exception):
def __init__(self, **kwargs):
pass
@lazyval
def message(self):
pass
def __str__(self):
pass | 5 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 1 | 0 | 75 | 3 | 1 | 3 | 13 | 16 | 4 | 12 | 10 | 7 | 0 | 11 | 9 | 7 | 1 | 3 | 0 | 3 |
16,424 | quantopian/zipline | quantopian_zipline/zipline/extensions.py | zipline.extensions.Namespace | class Namespace(object):
"""
A placeholder object representing a namespace level
""" | class Namespace(object):
'''
A placeholder object representing a namespace level
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 3 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 4 | 0 | 1 | 1 | 0 | 3 | 1 | 1 | 0 | 0 | 1 | 0 | 0 |
16,425 | quantopian/zipline | quantopian_zipline/zipline/extensions.py | zipline.extensions.Registry | from toolz import curry
class Registry(object):
"""
Responsible for managing all instances of custom subclasses of a
given abstract base class - only one instance needs to be created
per abstract base class, and should be created through the
create_registry function/decorator. All management method... |
class Registry(object):
'''
Responsible for managing all instances of custom subclasses of a
given abstract base class - only one instance needs to be created
per abstract base class, and should be created through the
create_registry function/decorator. All management methods
for a given base c... | 8 | 3 | 7 | 1 | 5 | 1 | 2 | 0.61 | 1 | 2 | 0 | 0 | 6 | 2 | 6 | 6 | 62 | 9 | 33 | 10 | 25 | 20 | 23 | 9 | 16 | 2 | 1 | 1 | 9 |
16,426 | quantopian/zipline | quantopian_zipline/zipline/finance/asset_restrictions.py | zipline.finance.asset_restrictions.HistoricalRestrictions | import pandas as pd
from zipline.assets import Asset
from functools import partial, reduce
from numpy import vectorize
from toolz import groupby
from six import with_metaclass, iteritems
class HistoricalRestrictions(Restrictions):
"""
Historical restrictions stored in memory with effective dates for each
a... |
class HistoricalRestrictions(Restrictions):
'''
Historical restrictions stored in memory with effective dates for each
asset.
Parameters
----------
restrictions : iterable of namedtuple Restriction
The restrictions, each defined by an asset, effective date and state
'''
... | 4 | 2 | 10 | 0 | 8 | 2 | 2 | 0.58 | 1 | 3 | 0 | 0 | 3 | 1 | 3 | 5 | 43 | 5 | 24 | 8 | 20 | 14 | 15 | 8 | 11 | 3 | 2 | 2 | 6 |
16,427 | quantopian/zipline | quantopian_zipline/zipline/finance/asset_restrictions.py | zipline.finance.asset_restrictions.NoRestrictions | import pandas as pd
from zipline.assets import Asset
class NoRestrictions(Restrictions):
"""
A no-op restrictions that contains no restrictions.
"""
def is_restricted(self, assets, dt):
if isinstance(assets, Asset):
return False
return pd.Series(index=pd.Index(assets), data... |
class NoRestrictions(Restrictions):
'''
A no-op restrictions that contains no restrictions.
'''
def is_restricted(self, assets, dt):
pass | 2 | 1 | 4 | 0 | 4 | 0 | 2 | 0.6 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 3 | 8 | 0 | 5 | 2 | 3 | 3 | 5 | 2 | 3 | 2 | 2 | 1 | 2 |
16,428 | quantopian/zipline | quantopian_zipline/zipline/finance/asset_restrictions.py | zipline.finance.asset_restrictions.Restrictions | import abc
from six import with_metaclass, iteritems
class Restrictions(with_metaclass(abc.ABCMeta)):
"""
Abstract restricted list interface, representing a set of assets that an
algorithm is restricted from trading.
"""
@abc.abstractmethod
def is_restricted(self, assets, dt):
"""
... |
class Restrictions(with_metaclass(abc.ABCMeta)):
'''
Abstract restricted list interface, representing a set of assets that an
algorithm is restricted from trading.
'''
@abc.abstractmethod
def is_restricted(self, assets, dt):
'''
Is the asset restricted (RestrictionStates.FROZEN)... | 4 | 3 | 14 | 2 | 3 | 9 | 2 | 2.75 | 1 | 2 | 1 | 5 | 2 | 0 | 2 | 2 | 35 | 5 | 8 | 4 | 4 | 22 | 7 | 3 | 4 | 2 | 1 | 1 | 3 |
16,429 | quantopian/zipline | quantopian_zipline/zipline/finance/asset_restrictions.py | zipline.finance.asset_restrictions.SecurityListRestrictions | from zipline.assets import Asset
import pandas as pd
from zipline.utils.numpy_utils import vectorized_is_element
class SecurityListRestrictions(Restrictions):
"""
Restrictions based on a security list.
Parameters
----------
restrictions : zipline.utils.security_list.SecurityList
The restri... |
class SecurityListRestrictions(Restrictions):
'''
Restrictions based on a security list.
Parameters
----------
restrictions : zipline.utils.security_list.SecurityList
The restrictions defined by a SecurityList
'''
def __init__(self, security_list_by_dt):
pass
d... | 3 | 1 | 5 | 0 | 5 | 0 | 2 | 0.64 | 1 | 1 | 0 | 0 | 2 | 1 | 2 | 4 | 21 | 3 | 11 | 5 | 8 | 7 | 8 | 5 | 5 | 2 | 2 | 1 | 3 |
16,430 | quantopian/zipline | quantopian_zipline/zipline/finance/asset_restrictions.py | zipline.finance.asset_restrictions.StaticRestrictions | from zipline.utils.numpy_utils import vectorized_is_element
import pandas as pd
from zipline.assets import Asset
class StaticRestrictions(Restrictions):
"""
Static restrictions stored in memory that are constant regardless of dt
for each asset.
Parameters
----------
restricted_list : iterable ... |
class StaticRestrictions(Restrictions):
'''
Static restrictions stored in memory that are constant regardless of dt
for each asset.
Parameters
----------
restricted_list : iterable of assets
The assets to be restricted
'''
def __init__(self, restricted_list):
pass
... | 3 | 2 | 6 | 0 | 5 | 2 | 2 | 1.1 | 1 | 2 | 0 | 0 | 2 | 1 | 2 | 4 | 24 | 3 | 10 | 4 | 7 | 11 | 7 | 4 | 4 | 2 | 2 | 1 | 3 |
16,431 | quantopian/zipline | quantopian_zipline/zipline/finance/asset_restrictions.py | zipline.finance.asset_restrictions._UnionRestrictions | from zipline.assets import Asset
import operator
from functools import partial, reduce
class _UnionRestrictions(Restrictions):
"""
A union of a number of sub restrictions.
Parameters
----------
sub_restrictions : iterable of Restrictions (but not _UnionRestrictions)
The Restrictions to be ... |
class _UnionRestrictions(Restrictions):
'''
A union of a number of sub restrictions.
Parameters
----------
sub_restrictions : iterable of Restrictions (but not _UnionRestrictions)
The Restrictions to be added together
Notes
-----
- Consumers should not construct instances of thi... | 4 | 2 | 12 | 1 | 9 | 2 | 2 | 0.64 | 1 | 2 | 1 | 0 | 3 | 0 | 3 | 5 | 54 | 8 | 28 | 6 | 24 | 18 | 18 | 6 | 14 | 3 | 2 | 1 | 7 |
16,432 | quantopian/zipline | quantopian_zipline/zipline/finance/blotter/blotter.py | zipline.finance.blotter.blotter.Blotter | from zipline.finance.cancel_policy import NeverCancel
from abc import ABCMeta, abstractmethod
from zipline.extensions import extensible
from six import with_metaclass
@extensible
class Blotter(with_metaclass(ABCMeta)):
def __init__(self, cancel_policy=None):
self.cancel_policy = cancel_policy if cancel_po... | @extensible
class Blotter(with_metaclass(ABCMeta)):
def __init__(self, cancel_policy=None):
pass
def set_date(self, dt):
pass
@abstractmethod
def order(self, asset, amount, style, order_id=None):
'''Place an order.
Parameters
----------
asset : zipline.a... | 23 | 9 | 13 | 2 | 2 | 9 | 1 | 2.97 | 1 | 2 | 1 | 1 | 12 | 2 | 12 | 12 | 180 | 37 | 36 | 25 | 13 | 107 | 26 | 15 | 13 | 2 | 1 | 0 | 13 |
16,433 | quantopian/zipline | quantopian_zipline/zipline/finance/blotter/simulation_blotter.py | zipline.finance.blotter.simulation_blotter.SimulationBlotter | from zipline.finance.commission import DEFAULT_PER_CONTRACT_COST, FUTURE_EXCHANGE_FEES_BY_SYMBOL, PerContract, PerShare
from collections import defaultdict
from .blotter import Blotter
from six import iteritems
from copy import copy
from zipline.finance.order import Order
from zipline.utils.input_validation import expe... | @register(Blotter, 'default')
class SimulationBlotter(Blotter):
def __init__(self, equity_slippage=None, future_slippage=None, equity_commission=None, future_commission=None, cancel_policy=None):
pass
def __repr__(self):
pass
@expect_types(asset=Asset)
def order(self, asset, amount, st... | 14 | 7 | 31 | 4 | 17 | 10 | 4 | 0.57 | 1 | 11 | 5 | 1 | 11 | 7 | 11 | 23 | 351 | 52 | 190 | 51 | 171 | 109 | 110 | 43 | 98 | 6 | 2 | 4 | 42 |
16,434 | quantopian/zipline | quantopian_zipline/zipline/finance/cancel_policy.py | zipline.finance.cancel_policy.CancelPolicy | from abc import abstractmethod
from six import with_metaclass
import abc
class CancelPolicy(with_metaclass(abc.ABCMeta)):
"""Abstract cancellation policy interface.
"""
@abstractmethod
def should_cancel(self, event):
"""Should all open orders be cancelled?
Parameters
---------... |
class CancelPolicy(with_metaclass(abc.ABCMeta)):
'''Abstract cancellation policy interface.
'''
@abstractmethod
def should_cancel(self, event):
'''Should all open orders be cancelled?
Parameters
----------
event : enum-value
An event type, one of:
... | 3 | 2 | 18 | 2 | 2 | 14 | 1 | 4 | 1 | 0 | 0 | 2 | 1 | 0 | 1 | 1 | 23 | 3 | 4 | 3 | 1 | 16 | 3 | 2 | 1 | 1 | 1 | 0 | 1 |
16,435 | quantopian/zipline | quantopian_zipline/zipline/finance/cancel_policy.py | zipline.finance.cancel_policy.EODCancel | from zipline.gens.sim_engine import SESSION_END
class EODCancel(CancelPolicy):
"""This policy cancels open orders at the end of the day. For now,
Zipline will only apply this policy to minutely simulations.
Parameters
----------
warn_on_cancel : bool, optional
Should a warning be raised i... |
class EODCancel(CancelPolicy):
'''This policy cancels open orders at the end of the day. For now,
Zipline will only apply this policy to minutely simulations.
Parameters
----------
warn_on_cancel : bool, optional
Should a warning be raised if this causes an order to be cancelled?
'''
... | 3 | 1 | 2 | 0 | 2 | 0 | 1 | 1.4 | 1 | 0 | 0 | 0 | 2 | 1 | 2 | 3 | 14 | 2 | 5 | 4 | 2 | 7 | 5 | 4 | 2 | 1 | 2 | 0 | 2 |
16,436 | quantopian/zipline | quantopian_zipline/zipline/finance/cancel_policy.py | zipline.finance.cancel_policy.NeverCancel | class NeverCancel(CancelPolicy):
"""Orders are never automatically canceled.
"""
def __init__(self):
self.warn_on_cancel = False
def should_cancel(self, event):
return False | class NeverCancel(CancelPolicy):
'''Orders are never automatically canceled.
'''
def __init__(self):
pass
def should_cancel(self, event):
pass | 3 | 1 | 2 | 0 | 2 | 0 | 1 | 0.4 | 1 | 0 | 0 | 0 | 2 | 1 | 2 | 3 | 8 | 1 | 5 | 4 | 2 | 2 | 5 | 4 | 2 | 1 | 2 | 0 | 2 |
16,437 | quantopian/zipline | quantopian_zipline/zipline/finance/commission.py | zipline.finance.commission.CommissionModel | from abc import abstractmethod
from six import with_metaclass
from zipline.finance.shared import AllowedAssetMarker, FinancialModelMeta
from zipline.assets import Equity, Future
class CommissionModel(with_metaclass(FinancialModelMeta)):
"""Abstract base class for commission models.
Commission models are respo... |
class CommissionModel(with_metaclass(FinancialModelMeta)):
'''Abstract base class for commission models.
Commission models are responsible for accepting order/transaction pairs and
calculating how much commission should be charged to an algorithm's account
on each transaction.
To implement a new co... | 3 | 2 | 25 | 4 | 2 | 19 | 1 | 5.6 | 1 | 1 | 0 | 4 | 1 | 0 | 1 | 1 | 41 | 8 | 5 | 4 | 2 | 28 | 4 | 3 | 2 | 1 | 1 | 0 | 1 |
16,438 | quantopian/zipline | quantopian_zipline/zipline/finance/commission.py | zipline.finance.commission.EquityCommissionModel | from zipline.assets import Equity, Future
from zipline.finance.shared import AllowedAssetMarker, FinancialModelMeta
from six import with_metaclass
class EquityCommissionModel(with_metaclass(AllowedAssetMarker, CommissionModel)):
"""
Base class for commission models which only support equities.
"""
allo... |
class EquityCommissionModel(with_metaclass(AllowedAssetMarker, CommissionModel)):
'''
Base class for commission models which only support equities.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 5 | 0 | 0 | 0 | 0 | 6 | 0 | 3 | 3 | 1 | 3 | 2 | 2 | 1 | 0 | 1 | 0 | 0 |
16,439 | quantopian/zipline | quantopian_zipline/zipline/finance/commission.py | zipline.finance.commission.FutureCommissionModel | from six import with_metaclass
from zipline.finance.shared import AllowedAssetMarker, FinancialModelMeta
from zipline.assets import Equity, Future
class FutureCommissionModel(with_metaclass(AllowedAssetMarker, CommissionModel)):
"""
Base class for commission models which only support futures.
"""
allow... |
class FutureCommissionModel(with_metaclass(AllowedAssetMarker, CommissionModel)):
'''
Base class for commission models which only support futures.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 4 | 0 | 0 | 0 | 0 | 6 | 0 | 3 | 3 | 1 | 3 | 2 | 2 | 1 | 0 | 1 | 0 | 0 |
16,440 | quantopian/zipline | quantopian_zipline/zipline/finance/commission.py | zipline.finance.commission.NoCommission | class NoCommission(CommissionModel):
"""Model commissions as free.
Notes
-----
This is primarily used for testing.
"""
@staticmethod
def calculate(order, transaction):
return 0.0 | class NoCommission(CommissionModel):
'''Model commissions as free.
Notes
-----
This is primarily used for testing.
'''
@staticmethod
def calculate(order, transaction):
pass | 3 | 1 | 2 | 0 | 2 | 0 | 1 | 1.25 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 11 | 2 | 4 | 3 | 1 | 5 | 3 | 2 | 1 | 1 | 2 | 0 | 1 |
16,441 | quantopian/zipline | quantopian_zipline/zipline/finance/commission.py | zipline.finance.commission.PerContract | from collections import defaultdict
from toolz import merge
from zipline.utils.dummy import DummyMapping
from zipline.finance.constants import FUTURE_EXCHANGE_FEES_BY_SYMBOL
class PerContract(FutureCommissionModel):
"""
Calculates a commission for a transaction based on a per contract cost with
an optional... |
class PerContract(FutureCommissionModel):
'''
Calculates a commission for a transaction based on a per contract cost with
an optional minimum cost per trade.
Parameters
----------
cost : float or dict
The amount of commissions paid per contract traded. If given a float,
the comm... | 4 | 1 | 21 | 2 | 16 | 4 | 2 | 0.65 | 1 | 3 | 1 | 1 | 3 | 3 | 3 | 3 | 88 | 9 | 48 | 15 | 41 | 31 | 22 | 12 | 18 | 3 | 2 | 1 | 7 |
16,442 | quantopian/zipline | quantopian_zipline/zipline/finance/commission.py | zipline.finance.commission.PerDollar | class PerDollar(EquityCommissionModel):
"""
Model commissions by applying a fixed cost per dollar transacted.
Parameters
----------
cost : float, optional
The flat amount of commissions paid per dollar of equities
traded. Default is a commission of $0.0015 per dollar transacted.
... | class PerDollar(EquityCommissionModel):
'''
Model commissions by applying a fixed cost per dollar transacted.
Parameters
----------
cost : float, optional
The flat amount of commissions paid per dollar of equities
traded. Default is a commission of $0.0015 per dollar transacted.
... | 4 | 3 | 5 | 0 | 3 | 2 | 1 | 1.5 | 1 | 1 | 0 | 0 | 3 | 1 | 3 | 3 | 28 | 3 | 10 | 6 | 6 | 15 | 8 | 6 | 4 | 1 | 2 | 0 | 3 |
16,443 | quantopian/zipline | quantopian_zipline/zipline/finance/commission.py | zipline.finance.commission.PerFutureTrade | from zipline.utils.dummy import DummyMapping
class PerFutureTrade(PerContract):
"""
Calculates a commission for a transaction based on a per trade cost.
Parameters
----------
cost : float or dict
The flat amount of commissions paid per trade, regardless of the number
of contracts b... |
class PerFutureTrade(PerContract):
'''
Calculates a commission for a transaction based on a per trade cost.
Parameters
----------
cost : float or dict
The flat amount of commissions paid per trade, regardless of the number
of contracts being traded. If given a float, the commission ... | 3 | 1 | 9 | 0 | 7 | 2 | 2 | 1 | 1 | 2 | 1 | 0 | 2 | 1 | 2 | 5 | 31 | 3 | 14 | 5 | 11 | 14 | 9 | 5 | 6 | 2 | 3 | 1 | 3 |
16,444 | quantopian/zipline | quantopian_zipline/zipline/finance/commission.py | zipline.finance.commission.PerShare | class PerShare(EquityCommissionModel):
"""
Calculates a commission for a transaction based on a per share cost with
an optional minimum cost per trade.
Parameters
----------
cost : float, optional
The amount of commissions paid per share traded. Default is one tenth
of a cent pe... | class PerShare(EquityCommissionModel):
'''
Calculates a commission for a transaction based on a per share cost with
an optional minimum cost per trade.
Parameters
----------
cost : float, optional
The amount of commissions paid per share traded. Default is one tenth
of a cent per... | 4 | 1 | 8 | 0 | 8 | 0 | 1 | 0.63 | 1 | 1 | 0 | 0 | 3 | 2 | 3 | 3 | 44 | 5 | 24 | 8 | 18 | 15 | 8 | 6 | 4 | 1 | 2 | 0 | 3 |
16,445 | quantopian/zipline | quantopian_zipline/zipline/finance/commission.py | zipline.finance.commission.PerTrade | class PerTrade(CommissionModel):
"""
Calculates a commission for a transaction based on a per trade cost.
For orders that require multiple fills, the full commission is charged to
the first fill.
Parameters
----------
cost : float, optional
The flat amount of commissions paid per e... | class PerTrade(CommissionModel):
'''
Calculates a commission for a transaction based on a per trade cost.
For orders that require multiple fills, the full commission is charged to
the first fill.
Parameters
----------
cost : float, optional
The flat amount of commissions paid per equ... | 4 | 3 | 8 | 0 | 4 | 5 | 1 | 1.92 | 1 | 1 | 0 | 0 | 3 | 1 | 3 | 4 | 40 | 5 | 12 | 5 | 8 | 23 | 9 | 5 | 5 | 2 | 2 | 1 | 4 |
16,446 | quantopian/zipline | quantopian_zipline/zipline/finance/controls.py | zipline.finance.controls.AccountControl | from six import with_metaclass
import abc
from zipline.errors import AccountControlViolation, TradingControlViolation
class AccountControl(with_metaclass(abc.ABCMeta)):
"""
Abstract base class representing a fail-safe control on the behavior of any
algorithm.
"""
def __init__(self, **kwargs):
... |
class AccountControl(with_metaclass(abc.ABCMeta)):
'''
Abstract base class representing a fail-safe control on the behavior of any
algorithm.
'''
def __init__(self, **kwargs):
'''
Track any arguments that should be printed in the error message
generated by self.fail.
... | 6 | 4 | 8 | 1 | 3 | 4 | 1 | 1.33 | 1 | 2 | 1 | 2 | 4 | 1 | 4 | 4 | 41 | 6 | 15 | 11 | 5 | 20 | 9 | 6 | 4 | 1 | 1 | 0 | 4 |
16,447 | quantopian/zipline | quantopian_zipline/zipline/finance/controls.py | zipline.finance.controls.MinLeverage | from zipline.utils.input_validation import expect_bounded, expect_types
from datetime import datetime
class MinLeverage(AccountControl):
"""AccountControl representing a limit on the minimum leverage allowed
by the algorithm after a threshold period of time.
Parameters
----------
min_leverage : fl... |
class MinLeverage(AccountControl):
'''AccountControl representing a limit on the minimum leverage allowed
by the algorithm after a threshold period of time.
Parameters
----------
min_leverage : float
The gross leverage in decimal form.
deadline : datetime
The date the min levera... | 5 | 2 | 9 | 0 | 7 | 2 | 2 | 0.75 | 1 | 1 | 0 | 0 | 2 | 2 | 2 | 6 | 39 | 4 | 20 | 14 | 7 | 15 | 8 | 5 | 5 | 2 | 2 | 1 | 3 |
16,448 | quantopian/zipline | quantopian_zipline/zipline/finance/controls.py | zipline.finance.controls.TradingControl | from six import with_metaclass
from zipline.errors import AccountControlViolation, TradingControlViolation
import abc
from datetime import datetime
class TradingControl(with_metaclass(abc.ABCMeta)):
"""
Abstract base class representing a fail-safe control on the behavior of any
algorithm.
"""
def ... |
class TradingControl(with_metaclass(abc.ABCMeta)):
'''
Abstract base class representing a fail-safe control on the behavior of any
algorithm.
'''
def __init__(self, on_error, **kwargs):
'''
Track any arguments that should be printed in the error message
generated by self.fa... | 7 | 4 | 11 | 1 | 7 | 4 | 2 | 0.64 | 1 | 2 | 1 | 6 | 5 | 2 | 5 | 5 | 68 | 9 | 36 | 16 | 24 | 23 | 18 | 10 | 12 | 3 | 1 | 1 | 8 |
16,449 | quantopian/zipline | quantopian_zipline/zipline/finance/execution.py | zipline.finance.execution.ExecutionStyle | import abc
from six import with_metaclass
class ExecutionStyle(with_metaclass(abc.ABCMeta)):
"""Base class for order execution styles.
"""
_exchange = None
@abc.abstractmethod
def get_limit_price(self, is_buy):
"""
Get the limit price for this order.
Returns either None or ... |
class ExecutionStyle(with_metaclass(abc.ABCMeta)):
'''Base class for order execution styles.
'''
@abc.abstractmethod
def get_limit_price(self, is_buy):
'''
Get the limit price for this order.
Returns either None or a numerical value >= 0.
'''
pass
@abc.ab... | 7 | 4 | 6 | 0 | 2 | 4 | 1 | 1.18 | 1 | 1 | 0 | 4 | 3 | 0 | 3 | 3 | 28 | 4 | 11 | 8 | 4 | 13 | 8 | 5 | 4 | 1 | 1 | 0 | 3 |
16,450 | quantopian/zipline | quantopian_zipline/zipline/finance/execution.py | zipline.finance.execution.LimitOrder | class LimitOrder(ExecutionStyle):
"""
Execution style for orders to be filled at a price equal to or better than
a specified limit price.
Parameters
----------
limit_price : float
Maximum price for buys, or minimum price for sells, at which the order
should be filled.
"""
... | class LimitOrder(ExecutionStyle):
'''
Execution style for orders to be filled at a price equal to or better than
a specified limit price.
Parameters
----------
limit_price : float
Maximum price for buys, or minimum price for sells, at which the order
should be filled.
'''
... | 4 | 1 | 5 | 0 | 4 | 0 | 1 | 0.64 | 1 | 0 | 0 | 0 | 3 | 3 | 3 | 6 | 27 | 4 | 14 | 7 | 10 | 9 | 10 | 7 | 6 | 2 | 2 | 0 | 4 |
16,451 | quantopian/zipline | quantopian_zipline/zipline/finance/execution.py | zipline.finance.execution.MarketOrder | class MarketOrder(ExecutionStyle):
"""
Execution style for orders to be filled at current market price.
This is the default for orders placed with :func:`~zipline.api.order`.
"""
def __init__(self, exchange=None):
self._exchange = exchange
def get_limit_price(self, _is_buy):
r... | class MarketOrder(ExecutionStyle):
'''
Execution style for orders to be filled at current market price.
This is the default for orders placed with :func:`~zipline.api.order`.
'''
def __init__(self, exchange=None):
pass
def get_limit_price(self, _is_buy):
pass
def get_s... | 4 | 1 | 2 | 0 | 2 | 0 | 1 | 0.57 | 1 | 0 | 0 | 0 | 3 | 1 | 3 | 6 | 15 | 4 | 7 | 5 | 3 | 4 | 7 | 5 | 3 | 1 | 2 | 0 | 3 |
16,452 | quantopian/zipline | quantopian_zipline/zipline/finance/execution.py | zipline.finance.execution.StopLimitOrder | class StopLimitOrder(ExecutionStyle):
"""
Execution style representing a limit order to be placed if market price
reaches a threshold.
Parameters
----------
limit_price : float
Maximum price for buys, or minimum price for sells, at which the order
should be filled, if placed.
... | class StopLimitOrder(ExecutionStyle):
'''
Execution style representing a limit order to be placed if market price
reaches a threshold.
Parameters
----------
limit_price : float
Maximum price for buys, or minimum price for sells, at which the order
should be filled, if placed.
... | 4 | 1 | 7 | 0 | 6 | 0 | 2 | 0.65 | 1 | 0 | 0 | 0 | 3 | 4 | 3 | 6 | 37 | 4 | 20 | 8 | 16 | 13 | 12 | 8 | 8 | 2 | 2 | 0 | 5 |
16,453 | quantopian/zipline | quantopian_zipline/zipline/finance/execution.py | zipline.finance.execution.StopOrder | class StopOrder(ExecutionStyle):
"""
Execution style representing a market order to be placed if market price
reaches a threshold.
Parameters
----------
stop_price : float
Price threshold at which the order should be placed. For sells, the
order will be placed if market price fa... | class StopOrder(ExecutionStyle):
'''
Execution style representing a market order to be placed if market price
reaches a threshold.
Parameters
----------
stop_price : float
Price threshold at which the order should be placed. For sells, the
order will be placed if market price fal... | 4 | 1 | 5 | 0 | 4 | 0 | 1 | 0.71 | 1 | 0 | 0 | 0 | 3 | 3 | 3 | 6 | 28 | 4 | 14 | 7 | 10 | 10 | 10 | 7 | 6 | 2 | 2 | 0 | 4 |
16,454 | quantopian/zipline | quantopian_zipline/zipline/finance/ledger.py | zipline.finance.ledger.Ledger | import numpy as np
from six import iteritems, itervalues, PY2
from collections import namedtuple, OrderedDict
from zipline.assets import Future
import zipline.protocol as zp
import pandas as pd
class Ledger(object):
"""The ledger tracks all orders and transactions as well as the current
state of the portfolio ... | null | 34 | 11 | 17 | 2 | 11 | 4 | 2 | 0.45 | 1 | 8 | 4 | 0 | 25 | 16 | 26 | 26 | 499 | 78 | 290 | 111 | 236 | 131 | 184 | 79 | 157 | 5 | 1 | 3 | 45 |
16,455 | quantopian/zipline | quantopian_zipline/zipline/finance/ledger.py | zipline.finance.ledger.PositionTracker | from math import isnan
from ._finance_ext import PositionStats, calculate_position_tracker_stats, update_position_last_sale_prices
from .position import Position
from zipline.finance.transaction import Transaction
from collections import namedtuple, OrderedDict
from six import iteritems, itervalues, PY2
from functools ... |
class PositionTracker(object):
'''The current state of the positions held.
Parameters
----------
data_frequency : {'daily', 'minute'}
The data frequency of the simulation.
'''
def __init__(self, data_frequency):
pass
def update_position(self, asset, amount=None, last_sale_... | 14 | 5 | 20 | 3 | 13 | 5 | 3 | 0.38 | 1 | 6 | 3 | 0 | 12 | 7 | 12 | 12 | 265 | 49 | 158 | 54 | 136 | 60 | 113 | 44 | 100 | 6 | 1 | 2 | 37 |
16,456 | quantopian/zipline | quantopian_zipline/zipline/finance/metrics/metric.py | zipline.finance.metrics.metric.AlphaBeta | import numpy as np
import empyrical as ep
class AlphaBeta(object):
"""End of simulation alpha and beta to the benchmark.
"""
def start_of_simulation(self, ledger, emission_rate, trading_calendar, sessions, benchmark_source):
self._daily_returns_array = benchmark_source.daily_returns(sessions[0], s... |
class AlphaBeta(object):
'''End of simulation alpha and beta to the benchmark.
'''
def start_of_simulation(self, ledger, emission_rate, trading_calendar, sessions, benchmark_source):
pass
def end_of_bar(self, packet, ledger, dt, session_ix, data_portal):
pass | 3 | 1 | 15 | 1 | 14 | 0 | 2 | 0.07 | 1 | 0 | 0 | 0 | 2 | 1 | 2 | 2 | 35 | 4 | 29 | 17 | 16 | 2 | 13 | 7 | 10 | 3 | 1 | 1 | 4 |
16,457 | quantopian/zipline | quantopian_zipline/zipline/finance/metrics/metric.py | zipline.finance.metrics.metric.BenchmarkReturnsAndVolatility | import numpy as np
from zipline.finance._finance_ext import minute_annual_volatility
from zipline.utils.exploding_object import NamedExplodingObject
import pandas as pd
class BenchmarkReturnsAndVolatility(object):
"""Tracks daily and cumulative returns for the benchmark as well as the
volatility of the benchma... |
class BenchmarkReturnsAndVolatility(object):
'''Tracks daily and cumulative returns for the benchmark as well as the
volatility of the benchmark returns.
'''
def start_of_simulation(self, ledger, emission_rate, trading_calendar, sessions, benchmark_source):
pass
def end_of_bar(self, packe... | 4 | 1 | 24 | 1 | 23 | 0 | 3 | 0.04 | 1 | 2 | 1 | 0 | 3 | 5 | 3 | 3 | 78 | 5 | 70 | 32 | 51 | 3 | 32 | 17 | 28 | 3 | 1 | 1 | 8 |
16,458 | quantopian/zipline | quantopian_zipline/zipline/finance/metrics/metric.py | zipline.finance.metrics.metric.CashFlow | class CashFlow(object):
"""Tracks daily and cumulative cash flow.
Notes
-----
For historical reasons, this field is named 'capital_used' in the packets.
"""
def start_of_simulation(self, ledger, emission_rate, trading_calendar, sessions, benchmark_source):
self._previous_cash_flow = 0.... | class CashFlow(object):
'''Tracks daily and cumulative cash flow.
Notes
-----
For historical reasons, this field is named 'capital_used' in the packets.
'''
def start_of_simulation(self, ledger, emission_rate, trading_calendar, sessions, benchmark_source):
pass
def end_of_bar(self,... | 4 | 1 | 10 | 0 | 10 | 0 | 1 | 0.16 | 1 | 0 | 0 | 0 | 3 | 1 | 3 | 3 | 39 | 3 | 31 | 22 | 12 | 5 | 12 | 7 | 8 | 1 | 1 | 0 | 3 |
16,459 | quantopian/zipline | quantopian_zipline/zipline/finance/metrics/metric.py | zipline.finance.metrics.metric.DailyLedgerField | import operator as op
class DailyLedgerField(object):
"""Like :class:`~zipline.finance.metrics.metric.SimpleLedgerField` but
also puts the current value in the ``cumulative_perf`` section.
Parameters
----------
ledger_field : str
The ledger field to read.
packet_field : str, optional
... |
class DailyLedgerField(object):
'''Like :class:`~zipline.finance.metrics.metric.SimpleLedgerField` but
also puts the current value in the ``cumulative_perf`` section.
Parameters
----------
ledger_field : str
The ledger field to read.
packet_field : str, optional
The name of the ... | 4 | 1 | 9 | 0 | 9 | 0 | 1 | 0.37 | 1 | 1 | 0 | 0 | 3 | 2 | 3 | 3 | 40 | 3 | 27 | 18 | 13 | 10 | 12 | 8 | 8 | 2 | 1 | 1 | 4 |
16,460 | quantopian/zipline | quantopian_zipline/zipline/finance/metrics/metric.py | zipline.finance.metrics.metric.MaxLeverage | class MaxLeverage(object):
"""Tracks the maximum account leverage.
"""
def start_of_simulation(self, *args):
self._max_leverage = 0.0
def end_of_bar(self, packet, ledger, dt, session_ix, data_portal):
self._max_leverage = max(self._max_leverage, ledger.account.leverage)
packet[... | class MaxLeverage(object):
'''Tracks the maximum account leverage.
'''
def start_of_simulation(self, *args):
pass
def end_of_bar(self, packet, ledger, dt, session_ix, data_portal):
pass | 3 | 1 | 5 | 0 | 5 | 0 | 1 | 0.17 | 1 | 0 | 0 | 0 | 2 | 1 | 2 | 2 | 16 | 2 | 12 | 10 | 4 | 2 | 7 | 5 | 4 | 1 | 1 | 0 | 2 |
16,461 | quantopian/zipline | quantopian_zipline/zipline/finance/metrics/metric.py | zipline.finance.metrics.metric.NumTradingDays | class NumTradingDays(object):
"""Report the number of trading days.
"""
def start_of_simulation(self, *args):
self._num_trading_days = 0
def start_of_session(self, *args):
self._num_trading_days += 1
def end_of_bar(self, packet, ledger, dt, session_ix, data_portal):
packet... | class NumTradingDays(object):
'''Report the number of trading days.
'''
def start_of_simulation(self, *args):
pass
def start_of_session(self, *args):
pass
def end_of_bar(self, packet, ledger, dt, session_ix, data_portal):
pass | 4 | 1 | 4 | 0 | 4 | 0 | 1 | 0.13 | 1 | 0 | 0 | 0 | 3 | 1 | 3 | 3 | 20 | 3 | 15 | 11 | 6 | 2 | 8 | 6 | 4 | 1 | 1 | 0 | 3 |
16,462 | quantopian/zipline | quantopian_zipline/zipline/finance/metrics/metric.py | zipline.finance.metrics.metric.Orders | class Orders(object):
"""Tracks daily orders.
"""
def end_of_bar(self, packet, ledger, dt, session_ix, data_portal):
packet['minute_perf']['orders'] = ledger.orders(dt)
def end_of_session(self, packet, ledger, dt, session_ix, data_portal):
packet['daily_perf']['orders'] = ledger.orders... | class Orders(object):
'''Tracks daily orders.
'''
def end_of_bar(self, packet, ledger, dt, session_ix, data_portal):
pass
def end_of_session(self, packet, ledger, dt, session_ix, data_portal):
pass | 3 | 1 | 7 | 0 | 7 | 0 | 1 | 0.13 | 1 | 0 | 0 | 0 | 2 | 0 | 2 | 2 | 18 | 1 | 15 | 13 | 2 | 2 | 5 | 3 | 2 | 1 | 1 | 0 | 2 |
16,463 | quantopian/zipline | quantopian_zipline/zipline/finance/metrics/metric.py | zipline.finance.metrics.metric.PNL | class PNL(object):
"""Tracks daily and cumulative PNL.
"""
def start_of_simulation(self, ledger, emission_rate, trading_calendar, sessions, benchmark_source):
self._previous_pnl = 0.0
def start_of_session(self, ledger, session, data_portal):
self._previous_pnl = ledger.portfolio.pnl
... | class PNL(object):
'''Tracks daily and cumulative PNL.
'''
def start_of_simulation(self, ledger, emission_rate, trading_calendar, sessions, benchmark_source):
pass
def start_of_session(self, ledger, session, data_portal):
pass
def _end_of_period(self, field, packet, ledger):
... | 6 | 1 | 5 | 0 | 5 | 0 | 1 | 0.07 | 1 | 0 | 0 | 0 | 5 | 1 | 5 | 5 | 34 | 4 | 28 | 23 | 7 | 2 | 13 | 8 | 7 | 1 | 1 | 0 | 5 |
16,464 | quantopian/zipline | quantopian_zipline/zipline/finance/metrics/metric.py | zipline.finance.metrics.metric.PeriodLabel | class PeriodLabel(object):
"""Backwards compat, please kill me.
"""
def start_of_session(self, ledger, session, data_portal):
self._label = session.strftime('%Y-%m')
def end_of_bar(self, packet, *args):
packet['cumulative_risk_metrics']['period_label'] = self._label
end_of_session ... | class PeriodLabel(object):
'''Backwards compat, please kill me.
'''
def start_of_session(self, ledger, session, data_portal):
pass
def end_of_bar(self, packet, *args):
pass | 3 | 1 | 2 | 0 | 2 | 0 | 1 | 0.33 | 1 | 0 | 0 | 0 | 2 | 1 | 2 | 2 | 10 | 2 | 6 | 5 | 3 | 2 | 6 | 5 | 3 | 1 | 1 | 0 | 2 |
16,465 | quantopian/zipline | quantopian_zipline/zipline/finance/metrics/metric.py | zipline.finance.metrics.metric.Positions | class Positions(object):
"""Tracks daily positions.
"""
def end_of_bar(self, packet, ledger, dt, session_ix, data_portal):
packet['minute_perf']['positions'] = ledger.positions(dt)
def end_of_session(self, packet, ledger, dt, session_ix, data_portal):
packet['daily_perf']['positions'] ... | class Positions(object):
'''Tracks daily positions.
'''
def end_of_bar(self, packet, ledger, dt, session_ix, data_portal):
pass
def end_of_session(self, packet, ledger, dt, session_ix, data_portal):
pass | 3 | 1 | 7 | 0 | 7 | 0 | 1 | 0.13 | 1 | 0 | 0 | 0 | 2 | 0 | 2 | 2 | 18 | 1 | 15 | 13 | 2 | 2 | 5 | 3 | 2 | 1 | 1 | 0 | 2 |
16,466 | quantopian/zipline | quantopian_zipline/zipline/finance/metrics/metric.py | zipline.finance.metrics.metric.Returns | from functools import partial
class Returns(object):
"""Tracks the daily and cumulative returns of the algorithm.
"""
def _end_of_period(field, packet, ledger, dt, session_ix, data_portal):
packet[field]['returns'] = ledger.todays_returns
packet['cumulative_perf']['returns'] = ledger.portf... |
class Returns(object):
'''Tracks the daily and cumulative returns of the algorithm.
'''
def _end_of_period(field, packet, ledger, dt, session_ix, data_portal):
pass | 2 | 1 | 11 | 0 | 11 | 0 | 1 | 0.14 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 17 | 1 | 14 | 9 | 7 | 2 | 7 | 4 | 5 | 1 | 1 | 0 | 1 |
16,467 | quantopian/zipline | quantopian_zipline/zipline/finance/metrics/metric.py | zipline.finance.metrics.metric.ReturnsStatistic | import numpy as np
class ReturnsStatistic(object):
"""A metric that reports an end of simulation scalar or time series
computed from the algorithm returns.
Parameters
----------
function : callable
The function to call on the daily returns.
field_name : str, optional
The name o... |
class ReturnsStatistic(object):
'''A metric that reports an end of simulation scalar or time series
computed from the algorithm returns.
Parameters
----------
function : callable
The function to call on the daily returns.
field_name : str, optional
The name of the field. If not ... | 3 | 1 | 8 | 1 | 8 | 0 | 2 | 0.59 | 1 | 0 | 0 | 0 | 2 | 2 | 2 | 2 | 31 | 4 | 17 | 12 | 9 | 10 | 12 | 7 | 9 | 2 | 1 | 1 | 4 |
16,468 | quantopian/zipline | quantopian_zipline/zipline/finance/metrics/metric.py | zipline.finance.metrics.metric.SimpleLedgerField | import operator as op
class SimpleLedgerField(object):
"""Emit the current value of a ledger field every bar or every session.
Parameters
----------
ledger_field : str
The ledger field to read.
packet_field : str, optional
The name of the field to populate in the packet. If not pro... |
class SimpleLedgerField(object):
'''Emit the current value of a ledger field every bar or every session.
Parameters
----------
ledger_field : str
The ledger field to read.
packet_field : str, optional
The name of the field to populate in the packet. If not provided,
``ledger... | 4 | 1 | 8 | 0 | 8 | 0 | 1 | 0.36 | 1 | 1 | 0 | 0 | 3 | 2 | 3 | 3 | 37 | 3 | 25 | 16 | 11 | 9 | 10 | 6 | 6 | 2 | 1 | 1 | 4 |
16,469 | quantopian/zipline | quantopian_zipline/zipline/finance/metrics/metric.py | zipline.finance.metrics.metric.StartOfPeriodLedgerField | import operator as op
class StartOfPeriodLedgerField(object):
"""Keep track of the value of a ledger field at the start of the period.
Parameters
----------
ledger_field : str
The ledger field to read.
packet_field : str, optional
The name of the field to populate in the packet. If... |
class StartOfPeriodLedgerField(object):
'''Keep track of the value of a ledger field at the start of the period.
Parameters
----------
ledger_field : str
The ledger field to read.
packet_field : str, optional
The name of the field to populate in the packet. If not provided,
... | 7 | 1 | 6 | 0 | 6 | 0 | 1 | 0.26 | 1 | 1 | 0 | 0 | 6 | 4 | 6 | 6 | 49 | 6 | 34 | 27 | 12 | 9 | 18 | 12 | 11 | 2 | 1 | 1 | 7 |
16,470 | quantopian/zipline | quantopian_zipline/zipline/finance/metrics/metric.py | zipline.finance.metrics.metric.Transactions | class Transactions(object):
"""Tracks daily transactions.
"""
def end_of_bar(self, packet, ledger, dt, session_ix, data_portal):
packet['minute_perf']['transactions'] = ledger.transactions(dt)
def end_of_session(self, packet, ledger, dt, session_ix, data_portal):
packet['daily_perf']['... | class Transactions(object):
'''Tracks daily transactions.
'''
def end_of_bar(self, packet, ledger, dt, session_ix, data_portal):
pass
def end_of_session(self, packet, ledger, dt, session_ix, data_portal):
pass | 3 | 1 | 7 | 0 | 7 | 0 | 1 | 0.13 | 1 | 0 | 0 | 0 | 2 | 0 | 2 | 2 | 18 | 1 | 15 | 13 | 2 | 2 | 5 | 3 | 2 | 1 | 1 | 0 | 2 |
16,471 | quantopian/zipline | quantopian_zipline/zipline/finance/metrics/metric.py | zipline.finance.metrics.metric._ClassicRiskMetrics | import datetime
from six import iteritems
import pandas as pd
from dateutil.relativedelta import relativedelta
from functools import partial
import numpy as np
import empyrical as ep
class _ClassicRiskMetrics(object):
"""Produces original risk packet.
"""
def start_of_simulation(self, ledger, emission_rat... |
class _ClassicRiskMetrics(object):
'''Produces original risk packet.
'''
def start_of_simulation(self, ledger, emission_rate, trading_calendar, sessions, benchmark_source):
pass
def end_of_session(self, packet, ledger, dt, session_ix, data_portal):
pass
@classmethod
def risk_m... | 10 | 2 | 32 | 3 | 22 | 8 | 2 | 0.36 | 1 | 4 | 0 | 0 | 3 | 1 | 6 | 6 | 206 | 23 | 135 | 56 | 94 | 48 | 36 | 22 | 29 | 4 | 1 | 2 | 11 |
16,472 | quantopian/zipline | quantopian_zipline/zipline/finance/metrics/metric.py | zipline.finance.metrics.metric._ConstantCumulativeRiskMetric | class _ConstantCumulativeRiskMetric(object):
"""A metric which does not change, ever.
Notes
-----
This exists to maintain the existing structure of the perf packets. We
should kill this as soon as possible.
"""
def __init__(self, field, value):
self._field = field
self._val... | class _ConstantCumulativeRiskMetric(object):
'''A metric which does not change, ever.
Notes
-----
This exists to maintain the existing structure of the perf packets. We
should kill this as soon as possible.
'''
def __init__(self, field, value):
pass
def end_of_bar(self, packet,... | 4 | 1 | 2 | 0 | 2 | 0 | 1 | 0.75 | 1 | 0 | 0 | 0 | 3 | 2 | 3 | 3 | 17 | 3 | 8 | 6 | 4 | 6 | 8 | 6 | 4 | 1 | 1 | 0 | 3 |
16,473 | quantopian/zipline | quantopian_zipline/zipline/finance/metrics/tracker.py | zipline.finance.metrics.tracker.MetricsTracker | from zipline.utils.exploding_object import NamedExplodingObject
from ..ledger import Ledger
class MetricsTracker(object):
"""The algorithm's interface to the registered risk and performance
metrics.
Parameters
----------
trading_calendar : TrandingCalendar
The trading calendar used in the ... |
class MetricsTracker(object):
'''The algorithm's interface to the registered risk and performance
metrics.
Parameters
----------
trading_calendar : TrandingCalendar
The trading calendar used in the simulation.
first_session : pd.Timestamp
The label of the first trading session i... | 28 | 5 | 12 | 1 | 9 | 2 | 1 | 0.29 | 1 | 3 | 2 | 0 | 18 | 15 | 19 | 19 | 328 | 51 | 216 | 77 | 172 | 62 | 102 | 57 | 78 | 5 | 1 | 3 | 30 |
16,474 | quantopian/zipline | quantopian_zipline/zipline/finance/order.py | zipline.finance.order.Order | from six import text_type
import math
from zipline.utils.input_validation import expect_types
from zipline.assets import Asset
import zipline.protocol as zp
import uuid
class Order(object):
__slots__ = ['id', 'dt', 'reason', 'created', 'asset', 'amount', 'filled', 'commission', '_status', 'stop', 'limit', 'stop_re... |
class Order(object):
@expect_types(asset=Asset)
def __init__(self, dt, asset, amount, stop=None, limit=None, filled=0, commission=0, id=None):
'''
@dt - datetime.datetime that the order was placed
@asset - asset for the order.
@amount - the number of shares to buy/sell
... | 27 | 6 | 10 | 1 | 7 | 3 | 3 | 0.37 | 1 | 2 | 1 | 0 | 17 | 16 | 18 | 18 | 218 | 37 | 132 | 53 | 104 | 49 | 109 | 44 | 90 | 19 | 1 | 3 | 46 |
16,475 | quantopian/zipline | quantopian_zipline/zipline/finance/position.py | zipline.finance.position.Position | import numpy as np
from zipline.assets import Future
import zipline.protocol as zp
from math import copysign
class Position(object):
__slots__ = ('inner_position', 'protocol_position')
def __init__(self, asset, amount=0, cost_basis=0.0, last_sale_price=0.0, last_sale_date=None):
inner = zp.InnerPositi... |
class Position(object):
def __init__(self, asset, amount=0, cost_basis=0.0, last_sale_price=0.0, last_sale_date=None):
pass
def __getattr__(self, attr):
pass
def __setattr__(self, attr, value):
pass
def earn_dividend(self, dividend):
'''
Register the number o... | 11 | 5 | 17 | 2 | 10 | 5 | 2 | 0.56 | 1 | 4 | 1 | 0 | 10 | 5 | 10 | 10 | 181 | 30 | 97 | 38 | 81 | 54 | 64 | 32 | 53 | 6 | 1 | 3 | 20 |
16,476 | quantopian/zipline | quantopian_zipline/zipline/finance/shared.py | zipline.finance.shared.AllowedAssetMarker | class AllowedAssetMarker(FinancialModelMeta):
pass | class AllowedAssetMarker(FinancialModelMeta):
pass | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 21 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 4 | 0 | 0 |
16,477 | quantopian/zipline | quantopian_zipline/zipline/finance/shared.py | zipline.finance.shared.FinancialModelMeta | from itertools import chain
from abc import ABCMeta
class FinancialModelMeta(ABCMeta):
"""
This metaclass allows users to create custom slippage and commission models
that support both equities and futures by subclassing the appropriate
individualized classes.
Take for example the following custom... |
class FinancialModelMeta(ABCMeta):
'''
This metaclass allows users to create custom slippage and commission models
that support both equities and futures by subclassing the appropriate
individualized classes.
Take for example the following custom model, which subclasses both
EquitySlippageModel... | 2 | 1 | 15 | 1 | 14 | 0 | 3 | 1 | 1 | 4 | 1 | 1 | 1 | 0 | 1 | 21 | 35 | 5 | 15 | 3 | 13 | 15 | 7 | 3 | 5 | 3 | 3 | 2 | 3 |
16,478 | quantopian/zipline | quantopian_zipline/zipline/finance/slippage.py | zipline.finance.slippage.EquitySlippageModel | from zipline.finance.shared import AllowedAssetMarker, FinancialModelMeta
from zipline.assets import Equity, Future
from six import with_metaclass
class EquitySlippageModel(with_metaclass(AllowedAssetMarker, SlippageModel)):
"""
Base class for slippage models which only support equities.
"""
allowed_as... |
class EquitySlippageModel(with_metaclass(AllowedAssetMarker, SlippageModel)):
'''
Base class for slippage models which only support equities.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1.5 | 1 | 0 | 0 | 3 | 0 | 0 | 0 | 0 | 5 | 0 | 2 | 2 | 1 | 3 | 2 | 2 | 1 | 0 | 1 | 0 | 0 |
16,479 | quantopian/zipline | quantopian_zipline/zipline/finance/slippage.py | zipline.finance.slippage.FixedBasisPointsSlippage | from zipline.utils.input_validation import expect_bounded, expect_strictly_bounded
class FixedBasisPointsSlippage(SlippageModel):
"""
Model slippage as a fixed percentage difference from historical minutely
close price, limiting the size of fills to a fixed percentage of historical
minutely volume.
... |
class FixedBasisPointsSlippage(SlippageModel):
'''
Model slippage as a fixed percentage difference from historical minutely
close price, limiting the size of fills to a fixed percentage of historical
minutely volume.
Orders to buy are filled at::
historical_price * (1 + (basis_points * 0.00... | 6 | 1 | 11 | 1 | 9 | 0 | 1 | 0.65 | 1 | 3 | 1 | 0 | 3 | 3 | 3 | 8 | 75 | 14 | 37 | 15 | 25 | 24 | 16 | 11 | 12 | 2 | 2 | 1 | 4 |
16,480 | quantopian/zipline | quantopian_zipline/zipline/finance/slippage.py | zipline.finance.slippage.FixedSlippage | class FixedSlippage(SlippageModel):
"""
Simple model assuming a fixed-size spread for all assets.
Parameters
----------
spread : float, optional
Size of the assumed spread for all assets.
Orders to buy will be filled at ``close + (spread / 2)``.
Orders to sell will be filled... | class FixedSlippage(SlippageModel):
'''
Simple model assuming a fixed-size spread for all assets.
Parameters
----------
spread : float, optional
Size of the assumed spread for all assets.
Orders to buy will be filled at ``close + (spread / 2)``.
Orders to sell will be filled ... | 4 | 1 | 5 | 0 | 4 | 0 | 1 | 1.07 | 1 | 1 | 0 | 0 | 3 | 1 | 3 | 8 | 34 | 5 | 14 | 6 | 10 | 15 | 9 | 6 | 5 | 1 | 2 | 0 | 3 |
16,481 | quantopian/zipline | quantopian_zipline/zipline/finance/slippage.py | zipline.finance.slippage.FutureSlippageModel | from six import with_metaclass
from zipline.assets import Equity, Future
from zipline.finance.shared import AllowedAssetMarker, FinancialModelMeta
class FutureSlippageModel(with_metaclass(AllowedAssetMarker, SlippageModel)):
"""
Base class for slippage models which only support futures.
"""
allowed_ass... |
class FutureSlippageModel(with_metaclass(AllowedAssetMarker, SlippageModel)):
'''
Base class for slippage models which only support futures.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1.5 | 1 | 0 | 0 | 3 | 0 | 0 | 0 | 0 | 5 | 0 | 2 | 2 | 1 | 3 | 2 | 2 | 1 | 0 | 1 | 0 | 0 |
16,482 | quantopian/zipline | quantopian_zipline/zipline/finance/slippage.py | zipline.finance.slippage.LiquidityExceeded | class LiquidityExceeded(Exception):
pass | class LiquidityExceeded(Exception):
pass | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 10 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 3 | 0 | 0 |
16,483 | quantopian/zipline | quantopian_zipline/zipline/finance/slippage.py | zipline.finance.slippage.MarketImpactBase | import math
import numpy as np
from zipline.errors import HistoryWindowStartsBeforeData
from zipline.utils.cache import ExpiringCache
from abc import abstractmethod
class MarketImpactBase(SlippageModel):
"""
Base class for slippage models which compute a simulated price impact
according to a history lookba... |
class MarketImpactBase(SlippageModel):
'''
Base class for slippage models which compute a simulated price impact
according to a history lookback.
'''
def __init__(self):
pass
@abstractmethod
def get_txn_volume(self, data, order):
'''
Return the number of shares we w... | 8 | 4 | 26 | 3 | 13 | 10 | 2 | 0.77 | 1 | 6 | 2 | 1 | 5 | 1 | 5 | 10 | 145 | 23 | 69 | 27 | 55 | 53 | 41 | 19 | 35 | 6 | 2 | 2 | 12 |
16,484 | quantopian/zipline | quantopian_zipline/zipline/finance/slippage.py | zipline.finance.slippage.NoSlippage | class NoSlippage(SlippageModel):
"""A slippage model where all orders fill immediately and completely at the
current close price.
Notes
-----
This is primarily used for testing.
"""
@staticmethod
def process_order(data, order):
return (data.current(order.asset, 'close'), order.... | class NoSlippage(SlippageModel):
'''A slippage model where all orders fill immediately and completely at the
current close price.
Notes
-----
This is primarily used for testing.
'''
@staticmethod
def process_order(data, order):
pass | 3 | 1 | 5 | 0 | 5 | 0 | 1 | 0.86 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 6 | 14 | 1 | 7 | 3 | 4 | 6 | 3 | 2 | 1 | 1 | 2 | 0 | 1 |
16,485 | quantopian/zipline | quantopian_zipline/zipline/finance/slippage.py | zipline.finance.slippage.SlippageModel | from pandas import isnull
from zipline.finance.shared import AllowedAssetMarker, FinancialModelMeta
from zipline.assets import Equity, Future
from abc import abstractmethod
from six import with_metaclass
from zipline.finance.transaction import create_transaction
class SlippageModel(with_metaclass(FinancialModelMeta)):... |
class SlippageModel(with_metaclass(FinancialModelMeta)):
'''
Abstract base class for slippage models.
Slippage models are responsible for the rates and prices at which orders
fill during a simulation.
To implement a new slippage model, create a subclass of
:class:`~zipline.finance.slippage.Slip... | 8 | 2 | 18 | 3 | 8 | 8 | 3 | 1.47 | 1 | 2 | 1 | 9 | 5 | 1 | 5 | 5 | 132 | 26 | 43 | 16 | 35 | 63 | 35 | 14 | 29 | 9 | 1 | 3 | 13 |
16,486 | quantopian/zipline | quantopian_zipline/zipline/finance/slippage.py | zipline.finance.slippage.VolatilityVolumeShare | from zipline.finance.constants import ROOT_SYMBOL_TO_ETA
from zipline.utils.dummy import DummyMapping
import math
from toolz import merge
from zipline.assets import Equity, Future
class VolatilityVolumeShare(MarketImpactBase):
"""
Model slippage for futures contracts according to the following formula:
... |
class VolatilityVolumeShare(MarketImpactBase):
'''
Model slippage for futures contracts according to the following formula:
new_price = price + (price * MI / 10000),
where 'MI' is market impact, which is defined as:
MI = eta * sigma * sqrt(psi)
- ``eta`` is a constant which varies by ro... | 5 | 1 | 11 | 1 | 8 | 3 | 2 | 0.85 | 1 | 4 | 1 | 0 | 4 | 2 | 4 | 14 | 76 | 13 | 34 | 20 | 23 | 29 | 22 | 14 | 17 | 2 | 3 | 1 | 6 |
16,487 | quantopian/zipline | quantopian_zipline/zipline/finance/slippage.py | zipline.finance.slippage.VolumeShareSlippage | from pandas import isnull
import math
class VolumeShareSlippage(SlippageModel):
"""
Model slippage as a quadratic function of percentage of historical volume.
Orders to buy will be filled at::
price * (1 + price_impact * (volume_share ** 2))
Orders to sell will be filled at::
price * ... |
class VolumeShareSlippage(SlippageModel):
'''
Model slippage as a quadratic function of percentage of historical volume.
Orders to buy will be filled at::
price * (1 + price_impact * (volume_share ** 2))
Orders to sell will be filled at::
price * (1 - price_impact * (volume_share ** 2))
... | 4 | 1 | 21 | 4 | 13 | 4 | 2 | 0.78 | 1 | 3 | 1 | 0 | 3 | 2 | 3 | 8 | 92 | 21 | 40 | 17 | 34 | 31 | 26 | 15 | 22 | 5 | 2 | 1 | 7 |
16,488 | quantopian/zipline | quantopian_zipline/zipline/finance/trading.py | zipline.finance.trading.SimulationParameters | import pandas as pd
from zipline.utils.pandas_utils import normalize_date
from zipline.utils.memoize import remember_last
class SimulationParameters(object):
def __init__(self, start_session, end_session, trading_calendar, capital_base=DEFAULT_CAPITAL_BASE, emission_rate='daily', data_frequency='daily', arena='ba... |
class SimulationParameters(object):
def __init__(self, start_session, end_session, trading_calendar, capital_base=DEFAULT_CAPITAL_BASE, emission_rate='daily', data_frequency='daily', arena='backtest'):
pass
@property
def capital_base(self):
pass
@property
def emission_rate(self):
... | 29 | 0 | 8 | 1 | 7 | 1 | 1 | 0.08 | 1 | 1 | 0 | 0 | 15 | 9 | 15 | 15 | 146 | 24 | 113 | 44 | 77 | 9 | 51 | 25 | 35 | 3 | 1 | 1 | 18 |
16,489 | quantopian/zipline | quantopian_zipline/zipline/finance/transaction.py | zipline.finance.transaction.Transaction | from zipline.utils.input_validation import expect_types
from zipline.protocol import DATASOURCE_TYPE
from zipline.assets import Asset
from copy import copy
class Transaction(object):
@expect_types(asset=Asset)
def __init__(self, asset, amount, dt, price, order_id):
self.asset = asset
self.amou... |
class Transaction(object):
@expect_types(asset=Asset)
def __init__(self, asset, amount, dt, price, order_id):
pass
def __getitem__(self, name):
pass
def __repr__(self):
pass
def to_dict(self):
pass | 6 | 0 | 9 | 1 | 7 | 1 | 1 | 0.13 | 1 | 1 | 0 | 0 | 4 | 6 | 4 | 4 | 41 | 7 | 30 | 14 | 24 | 4 | 20 | 13 | 15 | 1 | 1 | 0 | 4 |
16,490 | quantopian/zipline | quantopian_zipline/zipline/gens/tradesimulation.py | zipline.gens.tradesimulation.AlgorithmSimulator | from six import viewkeys
from copy import copy
from zipline.finance.order import ORDER_STATUS
from zipline.utils.compat import ExitStack
from zipline.utils.api_support import ZiplineAPI
from zipline.protocol import BarData
from logbook import Logger, Processor
from zipline.gens.sim_engine import BAR, SESSION_START, SES... |
class AlgorithmSimulator(object):
def __init__(self, algo, sim_params, data_portal, clock, benchmark_source, restrictions, universe_func):
pass
def inject_algo_dt(record):
pass
def get_simulation_dt(self):
pass
def _create_bar_data(self, universe_func):
p... | 17 | 4 | 22 | 4 | 14 | 5 | 2 | 0.37 | 1 | 1 | 1 | 0 | 7 | 9 | 7 | 7 | 273 | 52 | 161 | 62 | 141 | 60 | 116 | 58 | 99 | 10 | 1 | 4 | 37 |
16,491 | quantopian/zipline | quantopian_zipline/zipline/lib/adjusted_array.py | zipline.lib.adjusted_array.AdjustedArray | from ._labelwindow import AdjustedArrayWindow as LabelWindow
from zipline.lib.labelarray import LabelArray
from six import iteritems
from textwrap import dedent
from toolz import merge_with
from zipline.utils.memoize import lazyval
class AdjustedArray(object):
"""
An array that can be iterated with a variable-... |
class AdjustedArray(object):
'''
An array that can be iterated with a variable-length window, and which can
provide different views on data from different perspectives.
Parameters
----------
data : np.ndarray
The baseline data values. This array may be mutated by
``traverse(...,... | 13 | 9 | 16 | 1 | 9 | 5 | 2 | 0.7 | 1 | 5 | 1 | 0 | 9 | 5 | 9 | 9 | 177 | 22 | 91 | 26 | 74 | 64 | 43 | 19 | 33 | 4 | 1 | 2 | 17 |
16,492 | quantopian/zipline | quantopian_zipline/zipline/lib/labelarray.py | zipline.lib.labelarray.CategoryMismatch | import numpy as np
class CategoryMismatch(ValueError):
"""
Error raised on attempt to perform operations between LabelArrays with
mismatched category arrays.
"""
def __init__(self, left, right):
mismatches, = np.where(left != right)
assert len(mismatches), 'Not actually a mismatch!... |
class CategoryMismatch(ValueError):
'''
Error raised on attempt to perform operations between LabelArrays with
mismatched category arrays.
'''
def __init__(self, left, right):
pass | 2 | 1 | 13 | 0 | 13 | 0 | 1 | 0.29 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 12 | 18 | 0 | 14 | 3 | 12 | 4 | 5 | 3 | 3 | 1 | 4 | 0 | 1 |
16,493 | quantopian/zipline | quantopian_zipline/zipline/lib/labelarray.py | zipline.lib.labelarray.LabelArray | from operator import eq, ne
from functools import partial, total_ordering
import numpy as np
from toolz import compose
from zipline.utils.preprocess import preprocess
from zipline.utils.input_validation import coerce, expect_kinds, expect_types, optional
from zipline.utils.pandas_utils import ignore_pandas_nan_categori... |
class LabelArray(ndarray):
'''
An ndarray subclass for working with arrays of strings.
Factorizes the input array into integers, but overloads equality on strings
to check against the factor label.
Parameters
----------
values : array-like
Array of values that can be passed to np.as... | 46 | 21 | 19 | 2 | 10 | 6 | 2 | 0.7 | 1 | 18 | 3 | 0 | 29 | 5 | 31 | 31 | 723 | 106 | 363 | 99 | 295 | 254 | 176 | 70 | 141 | 6 | 1 | 2 | 68 |
16,494 | quantopian/zipline | quantopian_zipline/zipline/lib/labelarray.py | zipline.lib.labelarray.MissingValueMismatch | class MissingValueMismatch(ValueError):
"""
Error raised on attempt to perform operations between LabelArrays with
mismatched missing_values.
"""
def __init__(self, left, right):
super(MissingValueMismatch, self).__init__("LabelArray missing_values don't match: left={}, right={}".format(lef... | class MissingValueMismatch(ValueError):
'''
Error raised on attempt to perform operations between LabelArrays with
mismatched missing_values.
'''
def __init__(self, left, right):
pass | 2 | 1 | 5 | 0 | 5 | 0 | 1 | 0.67 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 12 | 10 | 0 | 6 | 2 | 4 | 4 | 3 | 2 | 1 | 1 | 4 | 0 | 1 |
16,495 | quantopian/zipline | quantopian_zipline/zipline/lib/labelarray.py | zipline.lib.labelarray._sortable_sentinel | from functools import partial, total_ordering
from zipline.utils.functional import instance
@instance
@total_ordering
class _sortable_sentinel(object):
"""Dummy object that sorts before any other python object.
"""
def __eq__(self, other):
return self is other
def __lt__(self, other):
... | @instance
@total_ordering
class _sortable_sentinel(object):
'''Dummy object that sorts before any other python object.
'''
def __eq__(self, other):
pass
def __lt__(self, other):
pass | 5 | 1 | 2 | 0 | 2 | 0 | 1 | 0.4 | 1 | 0 | 0 | 0 | 2 | 0 | 2 | 2 | 8 | 1 | 5 | 3 | 2 | 2 | 5 | 3 | 2 | 1 | 1 | 0 | 2 |
16,496 | quantopian/zipline | quantopian_zipline/zipline/pipeline/classifiers/Classifier.py | zipline.pipeline.classifiers.Classifier.Classifier | from zipline.utils.numpy_utils import categorical_dtype, int64_dtype, vectorized_is_element
from functools import partial
from zipline.lib.labelarray import LabelArray
from zipline.utils.compat import unicode
from zipline.pipeline.sentinels import NotSpecified
import pandas as pd
from zipline.pipeline.term import Compu... |
class Classifier(RestrictedDTypeMixin, ComputableTerm):
'''
A Pipeline expression computing a categorical output.
Classifiers are most commonly useful for describing grouping keys for
complex transformations on Factor outputs. For example, Factor.demean() and
Factor.zscore() can be passed a Classif... | 26 | 12 | 22 | 2 | 11 | 9 | 2 | 0.79 | 2 | 17 | 6 | 4 | 13 | 1 | 14 | 49 | 373 | 45 | 183 | 34 | 156 | 145 | 76 | 26 | 59 | 7 | 3 | 2 | 31 |
16,497 | quantopian/zipline | quantopian_zipline/zipline/pipeline/classifiers/Classifier.py | zipline.pipeline.classifiers.Classifier.CustomClassifier | from zipline.errors import UnsupportedDataType
from ..mixins import CustomTermMixin, LatestMixin, PositiveWindowLengthMixin, RestrictedDTypeMixin, SingleInputMixin, StandardOutputs
from zipline.pipeline.dtypes import CLASSIFIER_DTYPES, FACTOR_DTYPES, FILTER_DTYPES
from zipline.utils.numpy_utils import categorical_dtype... |
class CustomClassifier(PositiveWindowLengthMixin, StandardOutputs, CustomTermMixin, Classifier):
'''
Base class for user-defined Classifiers.
Does not suppport multiple outputs.
See Also
--------
zipline.pipeline.CustomFactor
zipline.pipeline.CustomFilter
'''
def _validate(self):
... | 3 | 2 | 16 | 1 | 12 | 4 | 3 | 0.54 | 4 | 3 | 1 | 1 | 2 | 1 | 2 | 59 | 47 | 4 | 28 | 7 | 22 | 15 | 13 | 3 | 10 | 4 | 4 | 2 | 6 |
16,498 | quantopian/zipline | quantopian_zipline/zipline/pipeline/classifiers/Classifier.py | zipline.pipeline.classifiers.Classifier.Quantiles | from numpy import where, isnan, nan, zeros
from ..mixins import CustomTermMixin, LatestMixin, PositiveWindowLengthMixin, RestrictedDTypeMixin, SingleInputMixin, StandardOutputs
from zipline.utils.numpy_utils import categorical_dtype, int64_dtype, vectorized_is_element
from zipline.lib.quantiles import quantiles
class ... |
class Quantiles(SingleInputMixin, Classifier):
'''
A classifier computing quantiles over an input.
'''
def _compute(self, arrays, dates, assets, mask):
pass
def graph_repr(self):
'''Short repr to use when rendering Pipeline graphs.'''
pass | 3 | 2 | 6 | 0 | 5 | 2 | 1 | 0.43 | 2 | 1 | 0 | 0 | 2 | 0 | 2 | 52 | 22 | 2 | 14 | 11 | 11 | 6 | 14 | 11 | 11 | 1 | 4 | 0 | 2 |
16,499 | quantopian/zipline | quantopian_zipline/zipline/pipeline/classifiers/Classifier.py | zipline.pipeline.classifiers.Classifier.Relabel | from zipline.lib.labelarray import LabelArray
from zipline.utils.input_validation import expect_types, expect_dtypes
from zipline.utils.numpy_utils import categorical_dtype, int64_dtype, vectorized_is_element
from ..mixins import CustomTermMixin, LatestMixin, PositiveWindowLengthMixin, RestrictedDTypeMixin, SingleInput... |
class Relabel(SingleInputMixin, Classifier):
'''
A classifier applying a relabeling function on the result of another
classifier.
Parameters
----------
arg : zipline.pipeline.Classifier
Term produceing the input to be relabeled.
relabel_func : function(LabelArray) -> LabelArray
... | 5 | 1 | 11 | 1 | 10 | 0 | 2 | 0.44 | 2 | 3 | 1 | 0 | 2 | 0 | 2 | 52 | 40 | 4 | 25 | 9 | 20 | 11 | 13 | 8 | 10 | 2 | 4 | 1 | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.