First Project Report Algorithmic Trading Strategy
First Project Report Algorithmic Trading Strategy
The Algorithm need to specify the list of constraints to satisfy the target
portfolio. Defining some threshold values in ’initialize’ and storing them in the
’context’ variable.
Also, the Pipeline API is a powerful tool for cross-sectional analysis of asset
data. It allows us to define a set of calculations on multiple data inputs and
analyze a large amount of assets at a time. By using the functions contained
within the quantopian.pipeline class.
1
To use the data pipeline in an algorithm, must add a reference to it in the
algorithm’s ’initialize’ function. This is done using the attach pipeline method,
which requires two inputs: a reference to the Pipeline object (which is con-
structed using make pipeline), and a String name to identify it.
def i n i t i a l i z e ( context ) :
##### C o n s t r a i n t s t o s a t i s f y t he t a r g e t p o r t f o l i o #####
context . max leverage = 1.0
context . max pos size = 0.01
c o n t e x t . max turnover = 0.95
In this algorithm, the trading strategy uses the US equity pricing taken from
the last entry of the previous day’s portfolio as the inputs for the following
computational calculations. Through which the algorithm can obtain the alpha
scores for the corresponding optimization of the strategy.
2
d i f f i c u l t t o n e g o t i a t e #####
b a s e u n i v e r s e = QTradableStocksUS ( )
#s e n t i m e n t s c o r e = SimpleMovingAverage (
# i n p u t s =[ s t o c k t w i t s . b u l l m i n u s b e a r ] ,
# window length =3,
# mask=QTradableStocksUS ( )
#)
# Factor of yesterday ’ s c l o s e p r i c e .
y e s t e r d a y c l o s e = USEquityPricing . c l o s e . l a t e s t
return Pipeline (
columns={
’ close ’ : yesterday close ,
},
s c r e e n=b a s e u n i v e r s e
)
The algorithm gets the pipeline’s output in before trading start using the pipeline output
function, which takes the pipeline name that was specified in ’initialize’, and re-
turns the pandas DataFrame generated by the pipeline.
d e f b e f o r e t r a d i n g s t a r t ( c o n t e x t , data ) :
##### Get p i p e l i n e and r i s k f a c t o r s o u t p u t s
and s t o r e them i n ’ c o n t e x t ’ #####
c o n t e x t . output = a l g o . p i p e l i n e o u t p u t ( ’ d a t a p i p e ’ )
3
exposure” instead of abstract matrix products.
o b j e c t i v e = opt . MaximizeAlpha (
c o n t e x t . output . c l o s e
)
c o n s t r a i n p o s s i z e = opt . P o s i t i o n C o n c e n t r a t i o n . w i t h e q u a l b o u n d s (
−c o n t e x t . m a x p o s s i z e ,
context . max pos size
)
f a c t o r r i s k c o n s t r a i n t s = opt . e x p e r i m e n t a l . RiskModelExposure (
context . r i s k f a c t o r b e t a s ,
v e r s i o n=opt . Newest
)
m a x l e v e r a g e = opt . MaxGrossExposure ( c o n t e x t . m a x l e v e r a g e )
##### Rebalance p o r t f o l i o u s i n g o b j e c t i v e
and l i s t o f c o n s t r a i n t s #####
4
2 Backtesting
In order to participate in the contest, algorithms need to meet a special set
of criteria. These criteria select for cross-sectional, long-short equity strategies
and are aligned with our allocation process. Algorithms are required to have the
following properties in order to participate in the contest:
• Positive returns.
• Low beta-to-SPY.
• Mid-range turnover.
5
6
3 Contest position: