Sunday, December 4, 2016

Quantopian Based Trading: Tangency Portfolio & Option Strategy

2016 Fall MATH5800-030 Group3 Final Project
by Jingwen Sun and Qintian Sun

Youtube link:
https://youtu.be/wolYv_S8rWI


.Project Objectives
In this project, we have four objects:
1.     We want to select several stocks whose price have tendency to rise.
2.     We form a tangency portfolio based on the selected stocks since tangency portfolio has the largest sharperatio and is most efficient. The portfolio will be adjusted daily according to their current prices.
3.     For every stock, we apply Fourier transformation to get a clearer trend.
4.     Based on the stock trend, we aim to build a bull spread strategy or a bear spread strategy on every stock.


. Methodology
1.     We select five stocks based on the 30-day moving average and 10-day moving average using pipeline. These five stocks’ 10-day moving averages are larger than 30-day’s, which means the prices have tendency to rise. Then we save the adj close price from 6/30/2016 to 10/30/2016 for these five stocks in an EXCEL.
2.     We compute the tangency portfolio formed by these five stocks using slovers.qp. And use the weights in the quantopian framework by setting target portfolio weights and adjust the portfolio daily.
3.     For every stock, we apply Fourier transformation and set the ones at high frequencies to zero. Then use inverse Fourier transformation to get a clearer trend.

4.     Based on the stock trends, we set a threshold to decide whether to build a bull spread or a bear spread since they expect to profit on opposite movement of stock prices. Then we calculate the payoff and profit for each option strategy using binomial tree method. Theoretically, all the stocks should build bull spread since they’re selected to have rising tendency.


. Results
1.     Stock Selection
File: <stockselect.py>; < quantopian.py>
We compute the simple moving average and select five stocks based on the critieron that 10-day sma should be larger than 30-day sma to obtain stocks which prices have tendency to rise.


















Select 5 stocks.

 We use the result on 10/27/2016.













So the five stocks are: AAME, AAPL, ABAX, DDC, ARCB.






We save the adj close prices for these stocks in EXCEL ‘adjcloseprice.xlsx’.



2.     Tangency Portfolio and Trading in Quantopian
File: <project.py>; < quantopian.py>
Before computing the tangency portfolio, we first calculate the return for these stocks.



Then we calcuate the weights of tangency portfolio using solver.qp by minimizing the denominator.












Set the weight in quantopian.













Rebalance the portfolio based on the given percentage every day, one hour after market open










Record the profit of this portfolio at the end of each day.



3.     Fourier Transformation
File: <project.py>
We apply FFT to each stock to eliminate noise.



4.     Option Strategy
File: <project.py>; <BTBullSpread.py>; < BTBearSpread.py>
We set the threshold equals to one. If the ratio of Fourier trend larger than one, then it has tendency to rise and should build a bull spread; otherwise we’ll build bear spread.

For bull spread, we build it by call options. For bear spread, we build it by put options to get positive payoff. The exercise price is set to be 160% of original price.


















Function file: <BTBullSpread.py>

Before computing the option prices and the payoff of the strategy, we first compute the stock prices at maturity using binomial tree methods. The stock prices at maturity are the only prices that needed for calculating a European option.


We compute the option values at maturity under different stock prices, then calculate backward to get the present value of two call options.













Next, we calculate the payoff of the strategy and discount it to today then use normal distribution to simulate the average value.














Function file: <BTBearSpread.py>
Similar to bull spread.

5.     Result:

Tangency portfolio performance (comparision in different holding period):


01/01/2016-10/27/2016


06/30/2016-10/27/2016




















































06/30/2016-12/02/2016


























Since we select the stock and build the tangency portfolio based on the period from 6/30/2016 to 10/30/2016, it clearly performs better with a return of 13.7% and always has a positive profit in this period than longer period, e.g. 01/01/2016-10/27/2016, which return is 4.9%. We also test the portfolio in a forward period from 06/30/2016 to 12/02/2016, which also has a good performance with a return of 20.39%.

Option Strategy Performance:








As we can see from the result, all these five stocks build bull spread strategy, which is in line with our choice of stocks that have rising tendency in the first place. All earn positive profit under the bull spread strategy.