diff --git a/blog/2015-11-14-welcome/_article.md b/blog/2015-11-14-welcome/_article.md new file mode 100644 index 0000000..29157af --- /dev/null +++ b/blog/2015-11-14-welcome/_article.md @@ -0,0 +1,59 @@ +Title: Welcome, and an algorithm +Date: 2015-11-19 +Tags: introduction, trading +Modified: 2015-12-05 +Category: Blog + + +Hello! Glad to meet you. I'm currently a student at Columbia University +studying Financial Engineering, and want to give an overview of the projects +I'm working on! + +To start things off, Columbia has been hosting a trading competition that +myself and another partner are competing in. I'm including a notebook of the +algorithm that we're using, just to give a simple overview of a miniature +algorithm. + +The competition is scored in 3 areas: + +- Total return +- [Sharpe ratio](1) +- Maximum drawdown + +Our algorithm uses a basic momentum strategy: in the given list of potential +portfolios, pick the stocks that have been performing well in the past 30 +days. Then, optimize for return subject to the drawdown being below a specific +level. We didn't include the Sharpe ratio as a constraint, mostly because +we were a bit late entering the competition. + +I'll be updating this post with the results of our algorithm as they come along! + +--- + +**UPDATE 12/5/2015**: Now that the competition has ended, I wanted to update +how the algorithm performed. Unfortunately, it didn't do very well. I'm planning +to make some tweaks over the coming weeks, and do another forward test in January. + +- After week 1: Down .1% +- After week 2: Down 1.4% +- After week 3: Flat + +And some statistics for all teams participating in the competition: + +| | | +|--------------------|--------| +| Max Return | 74.1% | +| Min Return | -97.4% | +| Average Return | -.1% | +| Std Dev of Returns | 19.6% | + +--- + +{% notebook 2015-11-14-welcome.ipynb %} + + + + +[1]: https://en.wikipedia.org/wiki/Sharpe_ratio diff --git a/blog/2015-11-14-welcome/2015-11-14-welcome.ipynb b/blog/2015-11-14-welcome/_notebook.ipynb similarity index 100% rename from blog/2015-11-14-welcome/2015-11-14-welcome.ipynb rename to blog/2015-11-14-welcome/_notebook.ipynb diff --git a/blog/2015-11-14-welcome/_notebook.md b/blog/2015-11-14-welcome/_notebook.md index aa875ed..53262c7 100644 --- a/blog/2015-11-14-welcome/_notebook.md +++ b/blog/2015-11-14-welcome/_notebook.md @@ -1,4 +1,6 @@ -**Goal: Max return given maximum Sharpe and Drawdown** +# Trading Competition Optimization + +### Goal: Max return given maximum Sharpe and Drawdown ```python @@ -15,7 +17,7 @@ data = {tick: Quandl.get('YAHOO/{}'.format(tick))[-lookback:] for tick in ticker market = Quandl.get(market_ticker) ``` -## Calculating the Return +# Calculating the Return We first want to know how much each ticker returned over the prior period. @@ -25,16 +27,16 @@ returns = {tick: data[tick][d_col].pct_change() for tick in tickers} display({tick: returns[tick].mean() for tick in tickers}) ``` -``` + {'CLB': -0.0016320202164526894, 'CVX': 0.0010319531629488911, 'OXY': 0.00093418904454400551, 'SLB': 0.00098431254720448159, 'XOM': 0.00044165797556096868} -``` -## Calculating the Sharpe ratio -Sharpe: $R - R_M \over \sigma$ + +# Calculating the Sharpe ratio +Sharpe: ${R - R_M \over \sigma}$ We use the average return over the lookback period, minus the market average return, over the ticker standard deviation to calculate the Sharpe. Shorting a stock turns a negative Sharpe positive. @@ -48,15 +50,15 @@ sharpes = {tick: sharpe(returns[tick]) for tick in tickers} display(sharpes) ``` -``` + {'CLB': -0.10578734457846127, 'CVX': 0.027303529817677398, 'OXY': 0.022622210057414487, 'SLB': 0.026950946344858676, 'XOM': -0.0053519259698605499} -``` -## Calculating the drawdown + +# Calculating the drawdown This one is easy - what is the maximum daily change over the lookback period? That is, because we will allow short positions, we are not concerned strictly with maximum downturn, but in general, what is the largest 1-day change? @@ -67,25 +69,23 @@ drawdowns = {tick: drawdown(returns[tick]) for tick in tickers} display(drawdowns) ``` -``` + {'CLB': 0.043551495607375035, 'CVX': 0.044894389686214398, 'OXY': 0.051424517867144637, 'SLB': 0.034774627850375328, 'XOM': 0.035851524605672758} -``` -## Performing the optimization -$$ -\begin{align*} - max\ \ & \mu \cdot \omega \\ - s.t.\ \ & \vec{1} \omega = 1\\ - & \vec{S} \omega \ge s\\ - & \vec{D} \cdot | \omega | \le d\\ - & \left|\omega\right| \le l\\ -\end{align*} -$$ +# Performing the optimization + +$\begin{align} +max\ \ & \mu \cdot \omega\\ +s.t.\ \ & \vec{1} \omega = 1\\ +& \vec{S} \omega \ge s\\ +& \vec{D} \cdot | \omega | \le d\\ +& \left|\omega\right| \le l\\ +\end{align}$ We want to maximize average return subject to having a full portfolio, Sharpe above a specific level, drawdown below a level, and leverage not too high - that is, don't have huge long/short positions. @@ -156,12 +156,18 @@ display("Expected Max Drawdown: {0:.2f}%".format(expected_drawdown)) # TODO: Calculate expected Sharpe ``` -``` + 'Optimization terminated successfully.' + + "Holdings: [('XOM', 5.8337945679814904), ('CVX', 42.935064321851307), ('CLB', -124.5), ('OXY', 36.790387773552119), ('SLB', 39.940753336615096)]" + + 'Expected Return: 32.375%' + + 'Expected Max Drawdown: 4.34%' -``` + diff --git a/blog/2015-11-14-welcome/index.mdx b/blog/2015-11-14-welcome/index.mdx index 32e67e8..f3c8ec1 100644 --- a/blog/2015-11-14-welcome/index.mdx +++ b/blog/2015-11-14-welcome/index.mdx @@ -1,45 +1,32 @@ --- title: Welcome, and an algorithm -date: 2015-11-19 +date: 2015-11-19 12:00:00 last_update: - date: 2015-12-05 + date: 2015-12-05 12:00:00 slug: 2015/11/welcome authors: [bspeice] tags: [trading] --- -import Notebook from './_notebook.md' - -Hello! Glad to meet you. I'm currently a student at Columbia University -studying Financial Engineering, and want to give an overview of the projects -I'm working on! +Hello! Glad to meet you. I'm currently a student at Columbia University studying Financial Engineering, and want to give an overview of the projects I'm working on! -To start things off, Columbia has been hosting a trading competition that -myself and another partner are competing in. I'm including a notebook of the -algorithm that we're using, just to give a simple overview of a miniature -algorithm. +To start things off, Columbia has been hosting a trading competition that myself and another partner are competing in. I'm including a notebook of the algorithm that we're using, just to give a simple overview of a miniature algorithm. The competition is scored in 3 areas: - Total return -- [Sharpe ratio](https://en.wikipedia.org/wiki/Sharpe_ratio) +- [Sharpe ratio](1) - Maximum drawdown -Our algorithm uses a basic momentum strategy: in the given list of potential -portfolios, pick the stocks that have been performing well in the past 30 -days. Then, optimize for return subject to the drawdown being below a specific -level. We didn't include the Sharpe ratio as a constraint, mostly because -we were a bit late entering the competition. +Our algorithm uses a basic momentum strategy: in the given list of potential portfolios, pick the stocks that have been performing well in the past 30 days. Then, optimize for return subject to the drawdown being below a specific level. We didn't include the Sharpe ratio as a constraint, mostly because we were a bit late entering the competition. I'll be updating this post with the results of our algorithm as they come along! --- -**UPDATE 12/5/2015**: Now that the competition has ended, I wanted to update -how the algorithm performed. Unfortunately, it didn't do very well. I'm planning -to make some tweaks over the coming weeks, and do another forward test in January. +**UPDATE 12/5/2015**: Now that the competition has ended, I wanted to update how the algorithm performed. Unfortunately, it didn't do very well. I'm planning to make some tweaks over the coming weeks, and do another forward test in January. - After week 1: Down .1% - After week 2: Down 1.4% @@ -47,25 +34,189 @@ to make some tweaks over the coming weeks, and do another forward test in Januar And some statistics for all teams participating in the competition: -
Max Return | -74.1% | -
Min Return | --97.4% | -
Average Return | --.1% | -
Std Dev of Returns | -19.6% | -