用于 zipline 的方法的 python 代码在哪里?
Where is the python code for the methods used for zipline?
我是 Python 的新手,但在 java 中,您通常会使用这些导入来准确显示对象的来源。例如,下面的 import 语句告诉我 SpringBootApplication 对象直接来自 Spring Boot class,我可以深入 class 阅读它的所有方法代码:
import org.springframework.boot.autoconfigure.SpringBootApplication;
现在我正在查看 python 中的 zipline 库:
https://github.com/quantopian/zipline
这是来自他们 github 存储库主页上的示例代码:
from zipline.api import (
history,
order_target,
record,
symbol,
)
所以我查看了 zipline 文件夹,看看是否有一个 api 文件从中导入了方法 history, order_target, record, symbol
,因为我想阅读驱动这些方法的底层代码.
代码告诉我的不多 (https://github.com/quantopian/zipline/blob/master/zipline/api.py):
from .finance.asset_restrictions import (
Restriction,
StaticRestrictions,
HistoricalRestrictions,
RESTRICTION_STATES,
)
from .finance import commission, execution, slippage, cancel_policy
from .finance.cancel_policy import (
NeverCancel,
EODCancel
)
from .finance.slippage import (
FixedSlippage,
VolumeShareSlippage,
)
from .utils import math_utils, events
from .utils.events import (
date_rules,
time_rules
)
__all__ = [
'EODCancel',
'FixedSlippage',
'NeverCancel',
'VolumeShareSlippage',
'Restriction',
'StaticRestrictions',
'HistoricalRestrictions',
'RESTRICTION_STATES',
'cancel_policy',
'commission',
'date_rules',
'events',
'execution',
'math_utils',
'slippage',
'time_rules'
]
但是,有一个名为 api.pyi
的文件似乎包含一些关于我感兴趣的方法的作用的文本 (https://github.com/quantopian/zipline/blob/master/zipline/api.pyi)。例如,使用方法 record
,它表示:
def record(*args, **kwargs):
"""Track and record values each day.
Parameters
----------
**kwargs
The names and values to record.
Notes
-----
These values will appear in the performance packets and the performance
dataframe passed to ``analyze`` and returned from
:func:`~zipline.run_algorithm`.
"""
我认为代码可能位于 zipline.run_algorithm
中,还查找了 zipline/run_algorithm
文件,但在回购中找不到它。
python中这些方法的代码保存在哪里?我只是想阅读代码以更好地理解它是如何工作的。
zipline
使用了一个有点复杂和不寻常的导入结构。线索在 api.py
:
的评论中
# Note that part of the API is implemented in TradingAlgorithm as
# methods (e.g. order). These are added to this namespace via the
# decorator ``api_method`` inside of algorithm.py.
如果您查看 algorithm.py
,您可以看到这些 record
以及使用 @api_method
装饰器定义的其余方法。 (如果您查看 zipline/utils/api_support.py
,您可以看到装饰器本身的代码,它通过使用 setattr
将这些方法添加到 zipline.api
。)
我是 Python 的新手,但在 java 中,您通常会使用这些导入来准确显示对象的来源。例如,下面的 import 语句告诉我 SpringBootApplication 对象直接来自 Spring Boot class,我可以深入 class 阅读它的所有方法代码:
import org.springframework.boot.autoconfigure.SpringBootApplication;
现在我正在查看 python 中的 zipline 库:
https://github.com/quantopian/zipline
这是来自他们 github 存储库主页上的示例代码:
from zipline.api import (
history,
order_target,
record,
symbol,
)
所以我查看了 zipline 文件夹,看看是否有一个 api 文件从中导入了方法 history, order_target, record, symbol
,因为我想阅读驱动这些方法的底层代码.
代码告诉我的不多 (https://github.com/quantopian/zipline/blob/master/zipline/api.py):
from .finance.asset_restrictions import (
Restriction,
StaticRestrictions,
HistoricalRestrictions,
RESTRICTION_STATES,
)
from .finance import commission, execution, slippage, cancel_policy
from .finance.cancel_policy import (
NeverCancel,
EODCancel
)
from .finance.slippage import (
FixedSlippage,
VolumeShareSlippage,
)
from .utils import math_utils, events
from .utils.events import (
date_rules,
time_rules
)
__all__ = [
'EODCancel',
'FixedSlippage',
'NeverCancel',
'VolumeShareSlippage',
'Restriction',
'StaticRestrictions',
'HistoricalRestrictions',
'RESTRICTION_STATES',
'cancel_policy',
'commission',
'date_rules',
'events',
'execution',
'math_utils',
'slippage',
'time_rules'
]
但是,有一个名为 api.pyi
的文件似乎包含一些关于我感兴趣的方法的作用的文本 (https://github.com/quantopian/zipline/blob/master/zipline/api.pyi)。例如,使用方法 record
,它表示:
def record(*args, **kwargs):
"""Track and record values each day.
Parameters
----------
**kwargs
The names and values to record.
Notes
-----
These values will appear in the performance packets and the performance
dataframe passed to ``analyze`` and returned from
:func:`~zipline.run_algorithm`.
"""
我认为代码可能位于 zipline.run_algorithm
中,还查找了 zipline/run_algorithm
文件,但在回购中找不到它。
python中这些方法的代码保存在哪里?我只是想阅读代码以更好地理解它是如何工作的。
zipline
使用了一个有点复杂和不寻常的导入结构。线索在 api.py
:
# Note that part of the API is implemented in TradingAlgorithm as
# methods (e.g. order). These are added to this namespace via the
# decorator ``api_method`` inside of algorithm.py.
如果您查看 algorithm.py
,您可以看到这些 record
以及使用 @api_method
装饰器定义的其余方法。 (如果您查看 zipline/utils/api_support.py
,您可以看到装饰器本身的代码,它通过使用 setattr
将这些方法添加到 zipline.api
。)