Given historical price/volume data for any exchange traded ticker symbol, widely available on the web, either free or via paid subscription, we saw earlier how the TTR package can spew out any number of common technical indicators used often in developing and implementing trading strategies.
Indeed there are many sites on the web that provide space and resources to examine trading strategies. Quantconnect has a free signup and if one is somewhat familiar with C## although there is a Python interface as well can start using their library of user submitted algorithms. Personally, I had some difficulty in installing and running their desktop version. The site has a very active forum with lots of examples, quite a few just concentrating on technical analysis. In a similar vein Quantopian provides many of the same features for setting up strategies and backtesting – this time in a Python setting. Not to be outdone, TradingView is another similar site with a free component, but here one has to learn what is known as the “pine” script. But there are some impressive algorithms with fantastic sounding names such as this RSI Alligator which uses RSI and the Williams indicator together (with due attribution) – actually quite simple to understand.
All of the above are quite excellent places to visit and hone one’s skills. However, adding a capability to do some further in-depth independent analysis on a personal desktop in a language such as R definitely increases one’s confidence.
In order to test a strategy or set of strategies it is essential to have some software that can do all the backtesting and derive key performance metrics that can help one gauge success or failure possibilities. Enter R package quantstrat, a package specifically designed to do just this.
There are many good references available. This is good for a start. Another little more deeper intro is a presentation from an R conference. There is however, a lack of detailed technical documentation but several sites have some good examples that cover a variety of situations. A reasonably complete one is here, followed by one whichs explore some of the more interesting features such as stoploss/stoptrailing type of trades, as well as testing various different sets of indicator or other parameters (from Guy Yollin at the Univ of Washington) are provided. The quantstrat package itself comes with many sample strategies and programs.
At this time, quantstrat is not available from a CRAN site but must be installed from github quite easily by doing the following:
install.packages("devtools")
require(devtools)
install_github("braverock/blotter") # dependency
install_github("braverock/quantstrat")
Alternately, package can be installed from a zip file obtained from here. Or it can also be downloaded from here as a zip file and installed thereafter. Installing in R Studio Console is quite simple. Open tab Tools; then Install Packages and then choose Package Archive File from “Install From” dropdown menu of Install. Enter Install from zip and follow directions to redirect to the folder where zip is downloaded,select it and all done.
For all of our backtest programs going forward, we will follow this architecture in terms of setting up the code:
Next a template will be provided to perform backtest runs. A very simple strategy that just looks at a moving average, the EMA in this case. Only long positions will be shown for now. Entry is whenever the Close price moves above the n-period moving average ( we can pick any number for n or leave it at default value). Exit from trade is when Close goes below this average.
Blocks of reusable code are presented below which we can resuse for more complex strategies going forward. They should be kept in separate files and sourced into the template code. The example below is a very simple example and the references cited have many more.
The template code for the actual run is shown below. For this example we will be using all of the sector ETFs as our test symbols for the trades. Also every trade incurs a transaction fee of $5.
Results can be printed with the printRunStats custom command and a flavor of the metrics collected are shown below. We will explore these in greater detail along with visual charts.
For now, it can be noted that the performance of this strategy is actually quite poor as can be seen from the numbers. The end equity numbers are less than impressive over the period of 8 years or so. On top of all that, a large number of trades appear to have been triggered thereby lessening the net profit available.
> getEndEquityFromBlotter() End.Eq 1949-12-31 16:00:00 1000000 2010-12-30 16:00:00 1017286 2011-12-29 16:00:00 991349 2012-12-30 16:00:00 996388 2013-12-30 16:00:00 1049124 2014-12-30 16:00:00 1079138 2015-12-30 16:00:00 1035770 2016-12-29 16:00:00 1050601 2017-12-28 16:00:00 1095840 2018-12-30 16:00:00 1069110 2019-02-03 16:00:00 1097110
Now we will run the same strategy but this time using our previously selected dividend stocks. We can see that for these stocks the strategy was definitely better than for the ETF case. Reminder note – none of strategies on this site is being recommended – we are just providing ourselves the capacity to analyze these as any professional money manager or trader would do with equivalent tools and software.
Running the same strategy but with all our previously selected dividend stocks
Symbols = c(“MO” , “UVV”, “MMP”, “GTY”, “ORI”, “CINF” ,“BWLA”, “VVC”, “ATO”, “RPM”, “IFF”, “LMT”,
“RTN”, “NOC” , “ODC” , “CPB”, “R”, “MMP” , “GTY” , “THFF”, “ABT”, “MMM”, “MXIM”, “ITW” , “MSFT” )
##########################################
#### Corresponding trade statistics for these 20+ symbols
##########################################
MO UVV MMP GTY ORI CINF BWLA
Num.Txns 376.00 452.00 429.00 435.00 404.00 461.00 359.00
Num.Trades 187.00 222.00 214.00 217.00 197.00 231.00 157.00
Net.Trading.PL 26830.00 –30220.00 23156.20 1065.00 1900.00 13787.50 –33920.60
Avg.Trade.PL 153.53 –125.95 118.23 14.93 19.90 69.66 –204.62
Med.Trade.PL 50.00 –260.00 –160.00 –60.00 –20.00 –40.00 –210.00
Largest.Winner 6505.00 17395.00 9155.00 4335.00 3345.00 7105.00 1045.00
Largest.Loser –5575.00 –12105.00 –5205.00 –5675.00 –1655.00 –4655.00 –1805.00
Gross.Profits 93565.00 128370.00 147560.00 55580.00 34810.00 102862.50 13373.40
Gross.Losses –64855.00 –156330.00 –122258.80 –52340.00 –30890.00 –86770.00 –45499.00
Std.Dev.Trade.PL 1296.32 2324.53 2001.65 826.19 538.95 1337.45 436.86
Percent.Positive 51.87 38.74 43.93 46.54 47.21 48.05 28.03
Percent.Negative 48.13 61.26 56.07 53.46 52.79 51.95 71.97
Profit.Factor 1.44 0.82 1.21 1.06 1.13 1.19 0.29
Avg.Win.Trade 964.59 1492.67 1569.79 550.30 374.30 926.69 303.94
Med.Win.Trade 570.00 935.00 785.00 340.00 220.00 430.00 207.90
Avg.Losing.Trade –720.61 –1149.49 –1018.82 –451.21 –297.02 –723.08 –402.65
Med.Losing.Trade –465.00 –655.00 –735.00 –330.00 –210.00 –495.00 –350.00
Avg.Daily.PL 147.71 –128.72 108.09 4.22 14.41 56.05 –191.88
Med.Daily.PL 40.00 –255.00 –165.00 –65.00 –15.00 –55.00 –155.00
Std.Dev.Daily.PL 1292.90 2303.84 2000.53 821.95 532.22 1333.93 398.98
Ann.Sharpe 1.81 –0.89 0.86 0.08 0.43 0.67 –7.63
Max.Drawdown –11180.00 –36720.00 –32110.00 –10910.00 –5590.00 –23740.00 –35970.20
Profit.To.Max.Draw 2.40 –0.82 0.72 0.10 0.34 0.58 –0.94
Avg.WinLoss.Ratio 1.34 1.30 1.54 1.22 1.26 1.28 0.75
Med.WinLoss.Ratio 1.23 1.43 1.07 1.03 1.05 0.87 0.59
Max.Equity 33705.00 2355.00 42926.20 7395.00 5915.00 35227.50 0.00
Min.Equity –1140.00 –34365.00 –6975.00 –3515.00 –1505.00 –3877.50 –35970.20
End.Equity 26830.00 –30220.00 23156.20 1065.00 1900.00 13787.50 –33920.60
[1] ” Aggregate Profit Ratio is 1.030733 “
[1] ” Percentage Positive Trades is 43.481429 “
[1] ” Total Number trades is 1425 “
[1] ” Mean Win-Loss Ratio is 1.241429 “
VVC ATO RPM IFF LMT RTN NOC
Num.Txns 457.00 451.00 385.00 433.00 441.00 453.00 419.00
Num.Trades 227.00 226.00 193.00 216.00 221.00 227.00 209.00
Net.Trading.PL 27425.00 10495.00 19935.00 21115.00 50735.00 46695.00 89655.00
Avg.Trade.PL 130.88 56.42 113.26 107.78 239.55 215.68 439.00
Med.Trade.PL –20.00 20.00 –100.00 –70.00 –50.00 –160.00 170.00
Largest.Winner 5375.00 7525.00 11735.00 13035.00 17605.00 11925.00 19785.00
Largest.Loser –3835.00 –4975.00 –4435.00 –7255.00 –15695.00 –8795.00 –17985.00
Gross.Profits 90760.00 107580.00 98420.00 201230.00 359950.00 236440.00 320390.00
Gross.Losses –61050.00 –94830.00 –76560.00 –177950.00 –307010.00 –187480.00 –228640.00
Std.Dev.Trade.PL 1103.32 1448.35 1638.31 2530.48 4858.68 2912.73 4438.65
Percent.Positive 48.02 50.44 43.01 48.15 48.87 44.93 54.07
Percent.Negative 51.98 49.56 56.99 51.85 51.13 55.07 45.93
Profit.Factor 1.49 1.13 1.29 1.13 1.17 1.26 1.40
Avg.Win.Trade 832.66 943.68 1185.78 1934.90 3332.87 2318.04 2835.31
Med.Win.Trade 440.00 525.00 550.00 1060.00 1625.00 1250.00 1170.00
Avg.Losing.Trade –517.37 –846.70 –696.00 –1588.84 –2716.90 –1499.84 –2381.67
Med.Losing.Trade –325.00 –560.00 –460.00 –1175.00 –1580.00 –1070.00 –1545.00
Avg.Daily.PL 125.26 49.58 108.59 103.98 149.45 165.62 323.90
Med.Daily.PL –25.00 15.00 –110.00 –65.00 –55.00 –180.00 155.00
Std.Dev.Daily.PL 1100.92 1451.32 1642.59 2530.37 4701.81 2838.78 4152.24
Ann.Sharpe 1.81 0.54 1.05 0.65 0.50 0.93 1.24
Max.Drawdown –7810.00 –22620.00 –13580.00 –28920.00 –82530.00 –44510.00 –87700.00
Profit.To.Max.Draw 3.51 0.46 1.47 0.73 0.61 1.05 1.02
Avg.WinLoss.Ratio 1.61 1.11 1.70 1.22 1.23 1.55 1.19
Med.WinLoss.Ratio 1.35 0.94 1.20 0.90 1.03 1.17 0.76
Max.Equity 29125.00 30235.00 23755.00 47835.00 113965.00 80805.00 146375.00
Min.Equity –4445.00 –7875.00 –6545.00 –5365.00 –3255.00 –17145.00 –525.00
End.Equity 27425.00 10495.00 19935.00 21115.00 50735.00 46695.00 89655.00
[1] ” Aggregate Profit Ratio is 1.248121 “
[1] ” Percentage Positive Trades is 48.212857 “
[1] ” Total Number trades is 1519 “
[1] ” Mean Win-Loss Ratio is 1.372857 “
ODC CPB R MMP GTY THFF ABT
Num.Txns 464.00 458.00 421.00 429.00 435.00 511.00 403.00
Num.Trades 226.00 228.00 209.00 214.00 217.00 255.00 199.00
Net.Trading.PL 12660.00 13290.00 –14845.00 23156.20 1065.00 –15895.00 4755.00
Avg.Trade.PL 66.28 68.33 –60.96 118.23 14.93 –52.31 34.02
Med.Trade.PL –140.00 –70.00 –180.00 –160.00 –60.00 –180.00 –60.00
Largest.Winner 6285.00 10845.00 12745.00 9155.00 4335.00 8295.00 5045.00
Largest.Loser –3515.00 –4075.00 –9565.00 –5205.00 –5675.00 –2805.00 –5495.00
Gross.Profits 102810.00 91620.00 195500.00 147560.00 55580.00 89320.00 95910.00
Gross.Losses –87830.00 –76040.00 –208240.00 –122258.80 –52340.00 –102660.00 –89140.00
Std.Dev.Trade.PL 1310.75 1336.75 2873.63 2001.65 826.19 1120.47 1350.01
Percent.Positive 41.15 45.18 46.41 43.93 46.54 39.22 47.24
Percent.Negative 58.85 54.82 53.59 56.07 53.46 60.78 52.76
Profit.Factor 1.17 1.20 0.94 1.21 1.06 0.87 1.08
Avg.Win.Trade 1105.48 889.51 2015.46 1569.79 550.30 893.20 1020.32
Med.Win.Trade 630.00 420.00 1000.00 785.00 340.00 495.00 685.00
Avg.Losing.Trade –660.38 –608.32 –1859.29 –1018.82 –451.21 –662.32 –848.95
Med.Losing.Trade –550.00 –390.00 –1440.00 –735.00 –330.00 –540.00 –620.00
Avg.Daily.PL 59.57 63.03 –65.67 108.09 4.22 –57.16 28.68
Med.Daily.PL –125.00 –75.00 –180.00 –165.00 –65.00 –185.00 –35.00
Std.Dev.Daily.PL 1293.65 1333.82 2866.76 2000.53 821.95 1120.47 1343.25
Ann.Sharpe 0.73 0.75 –0.36 0.86 0.08 –0.81 0.34
Max.Drawdown –17940.00 –17250.00 –56690.00 –32110.00 –10910.00 –19790.00 –16820.00
Profit.To.Max.Draw 0.71 0.77 –0.26 0.72 0.10 –0.80 0.28
Avg.WinLoss.Ratio 1.67 1.46 1.08 1.54 1.22 1.35 1.20
Med.WinLoss.Ratio 1.15 1.08 0.69 1.07 1.03 0.92 1.10
Max.Equity 18225.00 28105.00 37325.00 42926.20 7395.00 2985.00 18035.00
Min.Equity –7815.00 –9605.00 –19365.00 –6975.00 –3515.00 –16805.00 –8025.00
End.Equity 12660.00 13290.00 –14845.00 23156.20 1065.00 –15895.00 4755.00
[1] ” Aggregate Profit Ratio is 1.053880 “
[1] ” Percentage Positive Trades is 44.238571 “
[1] ” Total Number trades is 1548 “
[1] ” Mean Win-Loss Ratio is 1.360000 “
#######################
######## Ending Equity Yearly Progress
#######################
getEndEquityFromBlotter()
End.Eq
1949–12–31 16:00:00 1000000.0
2010–12–30 16:00:00 1034262.3
2011–12–29 16:00:00 944420.0
2012–12–30 16:00:00 992778.6
2013–12–30 16:00:00 1196897.9
2014–12–30 16:00:00 1300055.3
2015–12–30 16:00:00 1267206.6
2016–12–29 16:00:00 1404506.1
2017–12–28 16:00:00 1572141.1
2018–12–30 16:00:00 1366022.4
2019–01–24 16:00:00 1431727.4
We can also plot out rolling cumulative performance by symbols and compare it to a Buy & Hold. Code and plots are shown below
Thanx for reading
Register and take part in the drawing, [url=https://yourbonus.life/?u=2rek60a&o=y59p896&t=211222x]click here[/url]
[url=https://mosmedspravki.ru/spravka-kek/]Справка КЭК в Москве, получить заключение КЭК – Витбиомед+ [/url]
Tegs: Справка Манту для ребёнка в Москве – Витбиомед+ https://mosmedspravki.ru/spravka-mantu-dlya-rebyonka/
[u]Справка в свободной форме от врача медицинская – Витбиомед+ [/u]
[i]Справка для ребенка в Москве | Витбиомед+ [/i]
[b]Справку для учебы 086у купить медицинскую в Москве | Витбиомед+ [/b]
промокод на хбет. Click Here:👉 http://www.newlcn.com/pages/news/promo_kod_1xbet_na_segodnya_pri_registracii.html
👉 $5,000 FREE EXCHANGE BONUSES BELOW 📈 👉 PlaseFuture FREE $3,000 BONUS + 0% Maker Fees 📈 + PROMOCODE FOR NEWS USERS OF THE EXCHANGE 👉 [M0345IHZFN] — 0.01 BTC 👉 site: https://buycrypto.in.net Our site is a secure platform that makes it easy to buy, sell, and store cryptocurrency like Bitcoin, Ethereum, and More. We are available in over 30 countries worldwide.