##### 当前位置 |首页 > 作业代写 > R语言代写 >

STA457 Time series analysis assignment (Fall 2018)

Statistical properties of (moving-average) rule returns

Date: 23 October 2018 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. Suppose that at each time t, market participants predict the direction of the trend of asset prices using a price-based 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.

The above predictor is then converted to buy and sell trading signals Bt: buy (+1) and sell (-1) using, i.e. 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 (m = 5). In this case, f is given by In this case, we buy the asset (Bt= +1) at time t + 1when and sell the asset (Bt = −1) when The Figure below illustrates the dynamics of the above 5-periods moving average method— when the rate penetrates from below (above) the moving average of order five, a buy (sell) signal is generated. For your assignment, we consider Ft  based on a moving-average technical indicator. In general, for a given moving-average indicator, Ft may be expressed as (a function of log returns): where are defined by a given trading rule (See Appendix for more details). For this assignment, we assume = 0. For the period [t − 1, t), a trader following a given technical rule establishes a position (long or short) at time t  1, Bt-1 *-. The returns at time t made by applying such a decision rule is called “ruled returns” and denoted as Rt. Their value can be expressed as   where denote the logarithm return over this period (assume no dividend payout during period t).

Remark: Rt 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 where D represents the stochastic duration of the position which will last n days if  Under the assumption that Bt follows a stationary Gaussian process, several statistical properties of rule returns can be derived:

1. Unconditional expected return: (2) 2. Unconditional variance: # b b

Additionally, Kedem (1986) shows that the expected zero crossing rate for a stationary process as the expected zero-crossing rate for a discrete-time, zero-mean, stationary Gaussian sequence Zt is given by where Pz(1) denotes the autocorrelation function of {Zt} at lag one. Using the same assumption, we can show that Ft 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. 1. Derive the variance of the predictor Bt given in Equation (1). 2. Derive the expectation of the predictor Bt.  3. Derive the autocorrelation function at lag one for the predictor. Hint: 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. Hint: Given asset price time series and a pair of integers, m and r (function arguments), your function calculates the expected rule return ) and the expected length of holding periods H.

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.

Hint: Find the m and r  pair that has the highest E(Rt). For simplicity, let the maximum values of m be 250 and 52 for daily and weekly data, respectively.

7. Write a R function to calculate the in-sample trading statistics (cumulative return and

holding time) of your choice and compare them with your theoretical results. Hint: Use the ratio of the cumulative return over the number of trading periods as the estimate E(Rt).

8. (Optional) Run and back-test your daily trading rule using six months of rolling window. Show the empirical trading statistics and show the difference between the theoretical results. 1. Acar, E. (1993). Economic evaluation of financial forecasting. (Unpublished Doctoral thesis, City University London.)

2. Acar E. (200?), “Advanced trading rule”, Second edition. (Chapter 4. Expected returns of directional forecasters).

3. Kedem (1986), “Spectral analysis and discrimination by zero-crossings”, Proceedings of IEEE, Vol 74, No. 11, page 1477-1493.

Table 1: Return/Price signals equivalence Rational distributed lag model

Koyck distributed lag model Sizing

1. Stronger signal bigger position…

2. Standardized or normalized signals…

Assignment

Data: Stock Price Signal/Filter: Technical indicator Sizing: Rule return:  ruleRet<-function(Price, m, r){

lnP<-ln(Price)

X<-diff(lnP)

rho<-acf(X,plot=FALSE, cov???)\$acf

gamma<- acf(X,plot=FALSE)\$acf

d<-f(…m,r.)

mu.F<-sum(d*mean(X))

var.F<-…..gamma…d^2..

} 