Vous êtes sur la page 1sur 12

Manual Strategy

Anthony Singhavong

1 Introduction
There are numerous technical indicators that are used to signal whether a financial asset should be
bought or sold. Some simpler calculations such as Rate of Change and Simple Moving Average help
visualize and determine trends that would be otherwise harder to see by observing an asset’s closing
price. This report will explore a few indicators as it pertains to maximizing returns on JPMorgan
Chase & Company’s stock between the in-sample period of January 1, 2008 to December 31 2009.

2 Indicators
2.1 Simple Moving Average

Given the market’s volatility, it’s important to apply smoothing to the raw adjusted close data to aid in
filtering out the noise. With market data, averages are generally calculated using the closing price of
a stock or in this particular case, the adjusted closing price. The calculation is fairly straightforward,
given a window of time (e.g. 20 days in this case), take the 20 day sum of closing prices divided by
20. It’s also important to note that the SMA drops old data when new data become available which is
why it’s classified as a lagging indicator.

2.2 Exponential Moving Average

A similar indicator to the Simple Moving Average is the Exponential Moving Average, except the
exponential average gives more weight to newer data and thus it’s a leading indicator. To calculate
the EMA, create a multiplier that takes into consideration the time period to be observed (e.g. 20 days
would equal (2/(20+1) = .0952)). Given that multiplier (M), calculate the EMA value by using the
following formula:

EM A(n) = (AdjustedClose − EM A(n − 1)) ∗ (M − EM A(n − 1))

The SMA is used for the initial EMA calculation and is therefore often compliementary when
observing the overall direction of stock prices.

2.3 Bollinger Bands

Bollinger bands are often used to determine the volitility of a particular asset. They are also effective
in determining if a an asset price is particularly high or low relative to the average price. Bollinger
Bands define an upper and lower threshold defined by two standard deviations above and below the
Simple Moving Average respectively. Concretely, the upper and lower bands calculations are:

upper(n) = SM A(n) + 2(ST D(n))


lower(n) = SM A(n) − 2(ST D(n))

2.4 Rate of Change

The Rate of Change calculates the percent change in price from one period to the next. It helps to
visualize overall high/low trends of an asset. To calculate the rate, we can follow the equation:
output_0.png

Figure 1: The 20 day Simple Moving Average of JPM’s Adjusted Closing Price shows a smoothing
of the price that tends to flatten the stock’s growth period from April- October 2009.

rate(n) = (AdjustedClose(n) − AdjustedClose(n − 1))/AdjustedClose(n − 1)

2
output_3.png

Figure 2: The nine day Exponential Moving Average of JPM’s Adjusted Closing Price shows a
smoothing of the price that doesn’t flatten the stock’s growth period from April- October 2009 as
much as Figure 1.

3
output_1.png

Figure 3: The Bollinger Bands plotted on-top and bellow the Adjusted Close prices generally show
strong indication that stock is performing well or not. In the case of JPM, the price seems to fluctuate
to touch the bottom band and upper band repeatedly, though the last date range between 04-2009 to
10-2009 show strong price that could indicate a sell event.

4
output_2.png

Figure 4: Rate of Change plotted ontop of the Adjusted Close prices display the fluctuations of price
at a larger scale which makes it easier to indicate trends of price changes.

5
3 Best Possible Strategy
The challenge with adopting one particarly strategy is the likelihood of overfitting due to biases in the
initial dataset. In the case of the BestPossibleStrategy, future data is given to us so that we could use
it to inform our strategy and trade accordingly. Given a data point such as the price of JPM tomorrow
versus today’s price tremendously simplifies our strategy in the short-term. Mainly, we shouldn’t
buy if we know that the price will go down tomorrow and the opposite is true when selling. Instead,
if the price is lower tomorrow we will buy and if the price is higher tomorrow, we will buy today
then sell tomorrow. Another criteria of the BestPossibleStrategy was to only hold 0, 1000, -1000
shares of JPM in our total portfolio. This affects when and how we trade in addition to taking into
account the future prices of JPM. To observe the differences, it’s important to display the estimated
portfolio value of our strategy with a simple buy and hold strategy. In the buy and hold methodology,
we simply place one order to buy 1000 shares of JPM. Then, we let the market ride and see how
our portfolio value compares to the BestPossibleStrategy. In Figure 5, BestPossibleStrategy is seen
dramatically increasing in value as compared to the benchmark. Though, it’s important to note that
the portfolio values reflect $0 comission fees and 0.0 impact.

output_6.png

Figure 5: By plotting the best possible strategy with the benchmark, we can observe the difference in
portfolio value as time goes on.

6
4 Manual Strategy
In practice, the BestPossibleStrategy doesn’t quite hold up due to the natuarally unknown future
prices. Traditionally, strategies are built on historical data without the benefit of peeking into the
future. In ManualStrategy, we implement a rule based approach based on Bollinger Bands and the
Exponential Moving Average of the Adjusted Closing prices of textitJPM. While also incorporating
the Exponential Moving Average of SPY when making decisions to go long, go short, and or close our
position. Concretely, the following rules were explained in Algorithm 1, which outlines psuedocode
for the rule based strategy. Because this is a more realistic approach to real world trading (albiet
naive), we want to ensure that we take into consideration the cost to trade. Typically, this cost is
represented by a comission fee; in our case, our fee will be a constant $9.95.

Algorithm 1: Psuedocode for trading decisions used in MarketStrategy


1 if isShort and marketIndex < stockEM A or stockP rice < stockEM A and (holdings + qty)
<= maxShares then
2 SHORT ;
3 else if isLong and marketIndex >= marketEM A or stockP rice >= stockEM A and
(holdings − qty) >= minShares then
4 LON G;
5 else if ydayStockP rice > ydayU pperBand and stockP rice > stockU pperBand and
(holdings − qty) >= minShares then
6 OU T ;
7 else if ydayStockP rice > ydayU pperBand and marketIndex < marketEM A and
(holdings − qty) >= minShares then
8 OU T ;
9 else if ydayStockP rice < ydayLowerBand and stockP rice < stockLowerBand and
(holdings + qty) <= maxShares then
10 OU T ;

Table 1: Below are common portfolio statistics that further illustrate the differences of the two
strategies. BestPossible beats Benchmark in ever categroy except Standard Deviation of Returns.
This is due to the low-risk or rather low volatility associated with holding a position for a longer
period of time.

BestPossibleStrategy and Benchmark (in-sample)


Strategy Cumulative return Standard Deviation of Daily Returns Mean of Daily Returns
BestPossibleStrategy 6.1388 0.013603460869 0.00279011382095
Benchmark 0.0123 0.0141346583486 0.000116208281218

7
Table 2: Below are common portfolio statistics that further illustrate the differences of the two
strategies. ManualStrategy beats Benchmark in every categroy except Standard Deviation of Returns.
This is due to the low volatility associated with holding a position for a longer period of time.

ManualStrategy and Benchmark (in-sample)


Strategy Cumulative return Standard Deviation of Daily Returns Mean of Daily Returns
ManualStrategy 0.126097094422 0.0225141071741 0.000415758363477
Benchmark 0.0122252316436 0.0141653050794 0.000116537727004

8
output_7_no_market.png

Figure 6: The portfolio returns of MarketStrategy compared to the Benchmark without considering
SPY. The green and red dotted vertical lines represent the long and short entries respectively. Though,
this strategy outperforms the benchmark, we can do better by utilizing SPY as an additional signal.

9
output_7.png

Figure 7: The final portfolio values considering SPY. Observe the larger gains in value due to
observing the market when considering to go long or short. Also notice much more activity with
shorts and longs since the signals better reflect the state of the market.

10
5 Comparative Analysis
Though we’ve looked at the in-sample date range of January 1, 2008 to December 31 2009. It’s
important to backtest strategies against different date ranges to ensure a strategy can perform better
than the benchmark for more than one date range. Looking at the out-of-sample date range from
January 1, 2010 to December 31 2011, we can observe that the aforementioned ManualStrategy
doesn’t hold up. Because we considered SPY as another indicator to signal trades, the year of 2008
and 2009 would have skewed our strategy since there was a financial crisis during that time. Because
of the crisis, the number of buy signals greatly exceeded the sell signals causing our initial strategy
to trade aggressively. Given the more stable market conditions, we could attempt to improve our
strategy by removing the SPY dependency. This would improve our strategy for the out-of-sample
date range but decrease our gains during the in-sample date range (as observed in Figure 6).

Table 3: Below are common portfolio statistics that further illustrate the differences of the two
strategies. ManualStrategy underperforms when compared to the Benchmark in every category
out-of-sample.

ManualStrategy and Benchmark (out-of-sample)


Strategy Cumulative return Standard Deviation of Daily Returns Mean of Daily Returns
ManualStrategy -0.138917199559 0.00715538327329 -0.000180722080463
Benchmark -0.0836788237192 0.00707830420021 -0.0000954972697668

output_8.png

Figure 8: The Benchmark beats the ManualStrategy during the out-of-sample period.

11
References
[1] Colin Alexander. (May 1993) Trade with Moving Averages, Stocks Commodities V. 11:6, pp.
257-260.
[2] John Bollinger. (Jan 1992) Using Bollinger Bands by John Bollinger, Stocks Commodities V.
10:2, pp. 47-51.
[3] StockCharts. Rate of Change (ROC), http://stockcharts.com/school/doku.php?id=charts chool :
technicali ndicators : rateo fc hanger oca ndm omentum.
[4] Randal S Olsen. (June 2014) How to make beautiful data visualizations in Python with
matplotlib, http://www.randalolson.com/2014/06/28/how-to-make-beautiful-data-visualizations-in-
python-with-matplotlib/.

12

Vous aimerez peut-être aussi