mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-28 15:55:02 +08:00
ef4f642e62
This patch lays the groundwork for a compute engine designed to facilitate construction of factor-based universe screening and portfolio allocation. It contains: A new module, `zipline.modelling`, containing entities that can be used to express computations as dependency graphs. Each node in such a graph is an instance of the base `Term` class, defined in `zipline.modelling.term`. Dependency graphs are executed by instances of `FFCEngine`, defined in `zipline.modelling.engine`. A new module, `zipline.data.ffc`, containing loaders and dataset definitions for inputs to the modelling API. New `TradingAlgorithm` api methods: `add_factor`, and `add_filter`. These methods can only be called from `initialize`, and are used to inform the algorithm that each day it should compute the given terms. Computed factor results are made available through a new attribute of the `data` object in `before_trading_start` and `handle_data`. Computed filter results control which assets are available in the factor matrix on each day.
37 lines
913 B
Python
37 lines
913 B
Python
"""
|
|
Quick and dirty script to generate test case inputs.
|
|
"""
|
|
from __future__ import print_function
|
|
from os.path import (
|
|
dirname,
|
|
join,
|
|
)
|
|
from pandas.io.data import get_data_yahoo
|
|
|
|
here = join(dirname(__file__))
|
|
|
|
|
|
def main():
|
|
symbols = ['AAPL', 'MSFT', 'BRK-A']
|
|
# Specifically chosen to include the AAPL split on June 9, 2014.
|
|
for symbol in symbols:
|
|
data = get_data_yahoo(symbol, start='2014-03-01', end='2014-09-01')
|
|
data.rename(
|
|
columns={
|
|
'Open': 'open',
|
|
'High': 'high',
|
|
'Low': 'low',
|
|
'Close': 'close',
|
|
'Volume': 'volume',
|
|
},
|
|
inplace=True,
|
|
)
|
|
del data['Adj Close']
|
|
|
|
dest = join(here, symbol + '.csv')
|
|
print("Writing %s -> %s" % (symbol, dest))
|
|
data.to_csv(dest, index_label='day')
|
|
|
|
if __name__ == '__main__':
|
|
main()
|