zipline的Poloniex数据包,是Python算法交易库。
项目描述
Poloniex数据包为zipline,Python算法交易库。
描述
只需使用pip安装数据包
pip install zipline-poloniex
并创建一个文件 $HOME/.zipline/extension.py,调用zipline的 register 函数。 create_bundle 函数返回 register 所需的摄取函数。使用 Pairs 记录获取常见的美元与加密货币对的记录。
示例
将以下内容添加到 $HOME/.zipline/extension.py
import pandas as pd
from zipline_poloniex import create_bundle, Pairs, register
# adjust the following lines to your needs
start_session = pd.Timestamp('2016-01-01', tz='utc')
end_session = pd.Timestamp('2016-12-31', tz='utc')
assets = [Pairs.usdt_eth]
register(
'poloniex',
create_bundle(
assets,
start_session,
end_session,
),
calendar_name='POLONIEX',
minutes_per_day=24*60,
start_session=start_session,
end_session=end_session
)
使用以下命令摄取数据
zipline ingest -b poloniex
创建您的交易算法,例如 my_algorithm.py 使用
import logging
from zipline.api import order, record, symbol
from zipline_poloniex.utils import setup_logging
__author__ = "Florian Wilhelm"
__copyright__ = "Florian Wilhelm"
__license__ = "new-bsd"
# setup logging and all
setup_logging(logging.INFO)
_logger = logging.getLogger(__name__)
_logger.info("Dummy agent loaded")
def initialize(context):
_logger.info("Initializing agent...")
# There seems no "nice" way to set the emission rate to minute
context.sim_params._emission_rate = 'minute'
def handle_data(context, data):
_logger.debug("Handling data...")
order(symbol('ETH'), 10)
record(ETH=data.current(symbol('ETH'), 'price'))
在 my_algorithm.py 中运行您的算法
zipline run -f ./my_algorithm.py -s 2016-01-01 -e 2016-12-31 -o results.pickle --data-frequency minute -b poloniex
使用Pandas读取 results.pickle 以分析性能。
注意
该项目已使用PyScaffold 2.5.7设置。有关PyScaffold的详细信息和使用信息,请参阅 http://pyscaffold.readthedocs.org/。
项目详情
关闭
zipline-poloniex-0.1.2.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 27c4387b68ed9a7337c41e0243a92b9a4d680d21d0d2786d718df5a3da62b4f0 |
|
MD5 | fdc494d65d5fcbd9b3cca9f7785843e9 |
|
BLAKE2b-256 | 74702977296c4722e3d3ffc20ec720411a0ab39b79cd4a13e4df9e02eb87f6ba |