[R-SIG-Finance] Jegadeesh & Titman Strategy Implementation (ROUX, Nicolas)

Robert Wages robert at rwages.com
Fri Feb 17 21:42:16 CET 2017


Hi Nicolas,

I created custom functions to determine the weights of long-short portfolios
to  backtest Jegadeesh & Titman strategies using the return.portfolio
function.  The custom functions could accomplish steps 1:6 in your example.
In addition, I could vary the number of long and short securities, the
lookback period, the hold period, and make an estimate of transaction fees
based on the period turnover.  I typically use the cumulative return over
the lookback period to rank the securities, but I could change the function
to be the average return or the standard deviation of the return
(volatility), or whatever other function I could apply to the lookback
period returns.  If I wished, I could have modified the weighting scheme to
be based on something other than equal weight very easily.  Ultimately, I
found I could accurately backtest a very wide variety of Jegadeesh & Titman
inspired momentum strategies using this setup with return.portfolio.  (I
exactly replicated results from published papers, building confidence in my
approach.)

I did try to accomplish the same thing with Quanstrat, but gave up, since it
would be substantially harder.  As designed, Quanstrat executes trades based
on signals generated by each security's market data.  One can add the
desired portfolio weight of each security to the market data dataframe to
generate trading signals on fixed lots of the securities, but to generate
trading signals for lots proportional to the whole portfolio (which is what
the strategy calls for) is not at all obvious (to me anyway).  There is
probably a way to create a custom order sizing function that can use the
whole portfolio value as an input, but I could not figure it out in the time
I had available.

There are other trading strategies that I would like to test that involve
the whole portfolio, so I would certainly be interested in hearing anyone
else's ideas of using Quantstrat for that.  But for the momentum strategies
of Jegadeesh & Titman, I found  the return.portfolio function to be
perfectly adequate.

Robert C Wages
USA Mobile: +1 717 618 2828
robert at rwages.com

-----Original Message-----
From: R-SIG-Finance [mailto:r-sig-finance-bounces at r-project.org] On Behalf
Of r-sig-finance-request at r-project.org
Sent: Friday, February 17, 2017 6:00 AM
To: r-sig-finance at r-project.org
Subject: R-SIG-Finance Digest, Vol 153, Issue 6

Send R-SIG-Finance mailing list submissions to
	r-sig-finance at r-project.org

To subscribe or unsubscribe via the World Wide Web, visit
	https://stat.ethz.ch/mailman/listinfo/r-sig-finance
or, via email, send a message with subject or body 'help' to
	r-sig-finance-request at r-project.org

You can reach the person managing the list at
	r-sig-finance-owner at r-project.org

When replying, please edit your Subject line so it is more specific than
"Re: Contents of R-SIG-Finance digest..."


Today's Topics:

   1. Jegadeesh & Titman Strategy Implementation (ROUX, Nicolas)
   2. Using rgenoud to fit LPPL model (K. Upadhyay)


----------------------------------------------------------------------

Message: 1
Date: Thu, 16 Feb 2017 15:21:35 +0100
From: "ROUX, Nicolas" <nicolas.roux at hec.edu>
To: r-sig-finance at r-project.org
Subject: [R-SIG-Finance] Jegadeesh & Titman Strategy Implementation
Message-ID:
	<CAFF3=2qfvaGaoR2pSj3NKzwaUkNKg9TWrodvZK=5m_ZoGDXvWA at mail.gmail.com>
Content-Type: text/plain; charset="UTF-8"

Hello all,

Is there a package/function capable of implementing a momentum strategy
described in Jegadeesh & Titman (1993) and backtesting it? General steps of
the strategy are:
1- taking monthly stock prices/returns,
2- ranking monthly/period returns,
3- create equally weighted portfolio of top and bottom stock returns,
4- hold for "n" months (quarter, semester, year) with no updating in
between,
5- rebalance portfolio after holding period,
6- return results.

I have created a roundabout way using return.portfolio from
performanceanalytics but would like to use a package which allows the
possibility to progressively more complex strategies.
I cannot find a way to implement the holding period in the quantstrat
package or the ranking conditions and holding period in portfolioanalytics
package (uses only a complex ranking method).

Cheers,

Nicolas Roux

	[[alternative HTML version deleted]]



------------------------------

Message: 2
Date: Fri, 17 Feb 2017 00:50:30 +0000
From: "K. Upadhyay" <ku218 at cam.ac.uk>
To: r-sig-finance at r-project.org
Subject: [R-SIG-Finance] Using rgenoud to fit LPPL model
Message-ID: <f106bf7d3970658cf5fdc7e4e59cf278 at cam.ac.uk>
Content-Type: text/plain; charset=US-ASCII; format=flowed

apologies if this appears too simplistic/poorly worded a question, this is
my first time coding in R

I am attempting to fit the LPPL model to a price series in order to test for
its predictive power for financial crashes. As I understand the difficulty
in fitting the model is due to the number of variables leading to multiple
local minima. So far I have attempted to fit the model using the nls.lm
function, my code is below:

mydata<-fread("data.csv", sep="," , header=TRUE)

f <- function(pars, xx)
    with(pars,(a + b*(tc - xx)^m * (1 + c * cos(omega*log(tc - xx) +
phi))))`

resids <- function(p, observed, xx) {mydata$Logp - f(p,xx)}

nls.out <- nls.lm(par=list(a=1,b=-1,tc=100, m=0.5, omega=1, phi=1, c=1 ),
               fn = resids, observed = mydata$Logp, xx = mydata$day,
               control=nls.lm.control(maxiter=10000, ftol=1e-6,
maxfev=1e6))

However the fit for this model is still poor and irrespective of how I alter
the starting parameters it fails to predict a crash occurring one day later
with any degree of accuracy. This is troublesome as the data I have fitted
the model to has been successfully modelled using the LPPL model in numerous
papers.

 From what I have read online I believe using the rgenoud package is a more
powerful global optimiser tool. However I am not able to generate the
correct code to run the package successfully. Any help in doing so would be
greatly appreciated.



------------------------------

Subject: Digest Footer

_______________________________________________
R-SIG-Finance mailing list
R-SIG-Finance at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-finance

------------------------------

End of R-SIG-Finance Digest, Vol 153, Issue 6



More information about the R-SIG-Finance mailing list