mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-30 14:03:08 +08:00
MAINT: Moves create_trade out of gens.utils
Slight refactoring of moving create_trade so that it's alongside other testing/mock data utilities, instead of part of the gens module.
This commit is contained in:
+1
-23
@@ -19,10 +19,7 @@ import numbers
|
||||
|
||||
from hashlib import md5
|
||||
from datetime import datetime
|
||||
from zipline.protocol import (
|
||||
DATASOURCE_TYPE,
|
||||
Event
|
||||
)
|
||||
from zipline.protocol import DATASOURCE_TYPE
|
||||
|
||||
|
||||
def hash_args(*args, **kwargs):
|
||||
@@ -37,25 +34,6 @@ def hash_args(*args, **kwargs):
|
||||
return hasher.hexdigest()
|
||||
|
||||
|
||||
def create_trade(sid, price, amount, datetime, source_id="test_factory"):
|
||||
|
||||
trade = Event()
|
||||
|
||||
trade.source_id = source_id
|
||||
trade.type = DATASOURCE_TYPE.TRADE
|
||||
trade.sid = sid
|
||||
trade.dt = datetime
|
||||
trade.price = price
|
||||
trade.close = price
|
||||
trade.open = price
|
||||
trade.low = price * .95
|
||||
trade.high = price * 1.05
|
||||
trade.volume = amount
|
||||
trade.TRANSACTION = None
|
||||
|
||||
return trade
|
||||
|
||||
|
||||
def assert_datasource_protocol(event):
|
||||
"""Assert that an event meets the protocol for datasource outputs."""
|
||||
|
||||
|
||||
@@ -23,10 +23,33 @@ from itertools import cycle, ifilter, izip
|
||||
from datetime import datetime, timedelta
|
||||
import numpy as np
|
||||
|
||||
from zipline.gens.utils import hash_args, create_trade
|
||||
from zipline.protocol import (
|
||||
Event,
|
||||
DATASOURCE_TYPE
|
||||
)
|
||||
from zipline.gens.utils import hash_args
|
||||
from zipline.utils.tradingcalendar import trading_days
|
||||
|
||||
|
||||
def create_trade(sid, price, amount, datetime, source_id="test_factory"):
|
||||
|
||||
trade = Event()
|
||||
|
||||
trade.source_id = source_id
|
||||
trade.type = DATASOURCE_TYPE.TRADE
|
||||
trade.sid = sid
|
||||
trade.dt = datetime
|
||||
trade.price = price
|
||||
trade.close = price
|
||||
trade.open = price
|
||||
trade.low = price * .95
|
||||
trade.high = price * 1.05
|
||||
trade.volume = amount
|
||||
trade.TRANSACTION = None
|
||||
|
||||
return trade
|
||||
|
||||
|
||||
def date_gen(start=datetime(2006, 6, 6, 12, tzinfo=pytz.utc),
|
||||
delta=timedelta(minutes=1),
|
||||
count=100,
|
||||
|
||||
@@ -31,10 +31,12 @@ from zipline.protocol import DailyReturn, Event, DATASOURCE_TYPE
|
||||
from zipline.sources import (SpecificEquityTrades,
|
||||
DataFrameSource,
|
||||
DataPanelSource)
|
||||
from zipline.gens.utils import create_trade
|
||||
from zipline.finance.trading import SimulationParameters
|
||||
import zipline.finance.trading as trading
|
||||
from zipline.sources.test_source import date_gen
|
||||
from zipline.sources.test_source import (
|
||||
date_gen,
|
||||
create_trade
|
||||
)
|
||||
|
||||
|
||||
def create_simulation_parameters(year=2006, start=None, end=None,
|
||||
|
||||
Reference in New Issue
Block a user