@inproceedings{ott2019fairseq,
title = {fairseq: A Fast, Extensible Toolkit for Sequence Modeling},
author = {Myle Ott and Sergey Edunov and Alexei Baevski and Angela Fan and Sam Gross and Nathan Ng and David Grangier and Michael Auli},
booktitle = {Proceedings of NAACL-HLT 2019: Demonstrations},
year = {2019},
}
fromzipline.apiimportorder_target, record, symboldefinitialize(context):
context.i=0context.asset=symbol('AAPL')
defhandle_data(context, data):
# Skip first 300 days to get full windowscontext.i+=1ifcontext.i<300:
return# Compute averages# data.history() has to be called with the same params# from above and returns a pandas dataframe.short_mavg=data.history(context.asset, 'price', bar_count=100, frequency="1d").mean()
long_mavg=data.history(context.asset, 'price', bar_count=300, frequency="1d").mean()
# Trading logicifshort_mavg>long_mavg:
# order_target orders as many shares as needed to# achieve the desired number of shares.order_target(context.asset, 100)
elifshort_mavg<long_mavg:
order_target(context.asset, 0)
# Save values for later inspectionrecord(AAPL=data.current(context.asset, 'price'),
short_mavg=short_mavg,
long_mavg=long_mavg)