I simply adapted the code in this post here (
https://www.r-bloggers.com/backtesting-a-simple-stock-trading-strategy/) for the following momentum strategy.
This is a momentum based strategy: Long if current day is <50 days of 200 days high. Nil position otherwise.
Returns are pretty impressive for Singapore market. That being said, it will be useful to try it with different parameters and different markets!
#Inspired by the blog post here–>
https://www.r-bloggers.com/backtesting-a-simple-stock-trading-strategy/ #
http://etfprophet.com/days-since-200-day-highs/ #Simple momentum strategy rm(list = ls(all = TRUE)) library(quantmod) ## Loading required package: xts ## Loading required package: zoo ## ## Attaching package: 'zoo' ## The following objects are masked from 'package:base': ## ## as.