STA457 Time Series Analysis Assignment
R Language Assignment Question
Statistical properties of (movingaverage) rule returns
1. Introduction
Technical indicator is widely used to generate trading signals by practitioners to make trading decisions. The usual rule is to trade with the trend. In this case, the trader initiates a position early in the trend and maintains that position as long as the trend continues.
In this assignment, you are asked to study the statistical properties of returns for applying the oldest and most widely used method in technical indicators—moving averages.1
The structure of this paper is given as follows. Section 2 defines the trading rule (or strategy). In Section 3 and 4, we formulate the trading return based on a given trading rule and state the corresponding statistical properties, respectively. The questions for you to answer are listed in Section 5. Finally, references and appendix are given in Section 6 and 7, respectively.
2. Trading rule
Suppose that at each time π‘, market participants predict the direction of the trend of asset prices using a pricebased forecast πΉ , where πΉ is a function of past asset prices
##
πΉ =π(π,…,π ,…). # # #*+,
1 The simplest rule of this family is the single moving average which says when the rate penetrates from below (above) a moving average of a given length, a buy (sell) signal is generated.
2 The above predictor is then converted to buy and sell trading signals π΅#: buy (+1) and sell (1)
using, i.e.
{“ππππ” ⇔ π΅#=−1 ⇔ πΉ#<0 “π΅π’π¦” ⇔ π΅#=+1 ⇔ πΉ#>0
Note that the signal of a trading rule is completely defined by one of the inequalities giving a sell or buy order (if the position is not short, it is long).
For example, consider a trading rule based on the moving average of order five rule (π = 5). In this case, π is given by
∑C π π(π,…,π )=π− BDE #*B.
# #*+, #
5 In this case, we buy the asset (π΅# = +1) at time π‘ + 1when
∑C π
πΉ >0βΊπ > BDE #*B;
and sell the asset (π΅# = −1) when
∑C π
πΉ <0βΊπ < BDE #*B.
The Figure below illustrates the dynamics of the above 5periods moving average method— when the rate penetrates from below (above) the moving average of order five, a buy (sell) signal is generated.
##
5
##
5
2.45
24
2.35
Price
2.25
2.2
Signal
006
006 _
004 _ IN
9 13 17 21 25 29 33 37 II 45 Day
a
5 9 13 17 21 25 29 33 37 41 45 Day
Return oscillator
i A
i‘\ 002 – i 1
i\r,
it\ Logretum t
.402
004
036
•
Sett’, ‘,s1
\ 13:.C,. 1 01/
N,‘0
sax”
i 3.11
I
9 13 17 21 25
33 37 41 45
3
:Simple moving average method 5days moving average
For your assignment, we consider πΉ based on a movingaverage technical indicator. In #
= ππ(π ⁄π
where π
# ##* K
Figure 3.1: The simple moving average method.
general, for a given movingaverage indicator, πΉ may be expressed as (a function of log #
a. price series, b. signal time series, c return oscillator
+*M
returns):
), πΏ and π are defined by a given trading rule (See Appendix for more details). For this assignment, we assume πΏ = 0.
πΉ=πΏ+Iππ , (1)
#
KDE
K #*K
48
3. Rule returns
For the period [π‘ − 1, π‘), a trader following a given technical rule establishes a position (long or short) at time π‘ − 1, π΅#*. The returns at time t made by applying such a decision rule is called “ruled returns” and denoted as π # . Their value can be expressed as
π # =π΅#*π# ⇔Rπ # =−π# ππ π΅#* =−1T, π #=+π# ππ π΅#*=+1
where π = ππ(π ⁄π ) denote the logarithm return over this period (assume no dividend # ##*
payout during period π‘).
Remark: π
# is unconditional and unrealized returns. By unrealized we mean that rule returns
are recorded every day even if the position is neither closed nor reversed, but simply carries on. Remark: We may define the realized returns as
W
π U # = I π # , V , VD
where π· represents the stochastic duration of the position which will last π days if {π·=π}⇔{π΅#* β π΅#,π΅# =π΅#, =β―=π΅#,W*,π΅#*W, β π΅#,W }.
4
5
4. Statistical properties of rule returns
Under the assumption that π# follows a stationary Gaussian process, several statistical properties of rule returns can be derived:
1. Unconditional expected return:
2 πM π
πΈ(π )=^ π ⋅ππππ(π,πΉ )⋅ππ₯πi− k l+πm1−2π·o− kpq, (2) #πb##*2πM π
kk
where π·(h) = ∫x t√2πv* ππ₯π{−π₯M/2} ππ₯, π = πΈ(π ), π = π£ππ(π ), π = πΈ(πΉ ), and
*y
2. Unconditional variance:
π£ππ(π ) = πΈ(πM) − πΈ(π )M = πM + πM − πΈ(π )M. ##bb#
Additionally, Kedem (1986) shows that the expected zero crossing rate for a stationary process as the expected zerocrossing rate for a discretetime, zeromean, stationary Gaussian sequence π# is given by
1 πππ * π(1), π
where π(1) denotes the autocorrelation function of {π#} at lag one. Using the same assumption, we can show that πΉ is stationary. Using this result, we may approximate the
expected length of the holding period2 for a given trading rule as
2 Intuitively, the longer holding period, the larger the expected return on a trading rule.
πM = π£ππ(πΉ ). k#
k#b#k#
#
>π»= π . (3) πππ * πk(1)
5. Questions
1. Derive the variance of the predictor πΉ given in Equation (1). #
Hint: πM = π£ππ(∑+*M π π ). k BDE B #*B
2. Derive the expectation of the predictor πΉ . #
Hint: π = πΈ(∑+*M π π ). k BDE B #*B
3. Derive the autocorrelation function at lag one for the predictor. Hint: π (1) = ππππ(πΉ , πΉ ).
6
k # #*
4. Write a R function to calculate the expectation of the rule return for a given double MA trading rule (See Appendix) and the expected length of the holding period.
5. Use a R function to download daily, weekly S&P500 index from Oct/01/2009 to Sep/30/2018 from yahoo finance
Hint: adjusted Close and R quantmod library.
6. Write a R function to choose the optimal daily and weekly double MA trading rules (that maximize the expected rule returns) for S&P500 index.
7. Write a R function to calculate the insample trading statistics (cumulative return and holding time) of your choice and compare them with your theoretical results.
8. (Optional) Run and backtest your daily trading rule using six months of rolling window. Show the empirical trading statistics and show the difference between the theoretical results.
Hint: Given asset price time series and a pair of integers, π and π (function arguments),
your function calculates the expected rule return πΈ(π #) and the expected length of holding
periods π»
Hint: Find the π and π pair that has the highest πΈ(π #). For simplicity, let the maximum
values of π be 250 and 52 for daily and weekly data, respectively
Hint: Use the ratio of the cumulative return over the number of trading periods as the
estimate πΈ(π #).
6. Reference
 Acar, E. (1993). Economic evaluation of financial forecasting. (Unpublished Doctoral thesis, City University London.)
 Acar E. (200?), “Advanced trading rule”, Second edition. (Chapter 4. Expected returns of directional forecasters).
 Kedem (1986), “Spectral analysis and discrimination by zerocrossings”, Proceedings of IEEE, Vol 74, No. 11, page 14771493.
7. Appendix
134 Advanced Trading Rules
Table 1: Return/Price signals equivalence
Table 4.1
Return/price signals equivalence
Return sell signals
dj τ°τ°mτ°jτ°τ°mτ°jτ°1τ° 2
see generalization
djτ°1
Xmτ°2
jτ°0
dj τ°τ°mτ°rτ°τ°jτ° 1τ°
for0τ° jτ° rτ°1 dj τ°rτ°mτ°jτ°1τ°
forrτ° jτ° mτ°1 mτ°2
τ° X dj Xtτ°j ` 0Ywith:
jτ°0 mτ°1 mτ°1 dj τ° τ° X ai and τ° X aj
iτ°jτ° 1 jτ°0
Parameter(s) 
Price sell signals 
Pt ` Xmτ°1 jτ°0 ajPtτ°j 

mτ°2 
a j τ° m1 
mτ°2 
ajτ° mτ°j τ°mτ°m τ° 1τ°τ°a2 
1 b a b 0 Ym τ° 2 
aj τ°aτ°1τ°aτ°j 
mτ°2 
aj τ°1forjτ°mτ°1Y aj τ°0forj6τ°mτ°1 
rτ°1 mτ°1 XbjPtτ°j `XajPtτ°j jτ°0 jτ°0 

mbrτ°1 
bj τ°1rY aj τ°m1 
Xmτ°1 ajPtτ°j `0 jτ°0 
Rule
Simple order
Simple MA
Weighted MA
Exponential MA
Momentum
Double orders
Double MA
Generalization
Xmτ°2 jτ°0
djXtτ°j `0 dj τ°τ°mτ°jτ°1τ°
djXtτ°j `0
for the simple and weighted moving average rule.4 As can be seen from Tables 4.2 and 4.3, signals are diτ°erent in less than 3 per cent of all cases for simulated series. The largest deviation comes from ” τ° 0.001 and ‘ τ° 0.03, for m τ° 200. Even then, returns signals are identical to price signals in at least 97 per cent of all cases. This case represents an upper bound in terms of both volatility and average returns over ten years for ®nancial series (Taylor, 1986: Tables 3 and 4, pp. 33 and 34). On the basis of the empirical results presented in Tables 4.2 and 4.3, one can safely conclude that return signals lead to essentially the same investment strategies as price signals for values of m as large as 200.
 24 x 7 Availability
 Plagiarism Free
 Trained and Certified Experts.
 Deadline Guaranteed
 Privacy Guaranteed
 Assignment Help Reward
 Online help for all project.
 Service for everyone
 Online Tutoring
 Free download.
 Free study help whitepapers
 Assignment Help
 Homework Help
 Writing Help
 Academic Writing Assistance
 Editing Services
 Plagiarism Checker Online
 Proofreading
 Research Writing Help
 Services