SCM

SCM Repository

[blotter] Annotation of /pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R
ViewVC logotype

Annotation of /pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1711 - (view) (download)

1 : opentrades 1457 #!/usr/bin/Rscript --vanilla
2 :     #
3 :     # Jan Humme (@opentrades) - August 2012
4 :     #
5 : opentrades 1458 # Tested and found to work correctly using blotter r1457
6 : opentrades 1457 #
7 : opentrades 1458 # After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
8 : opentrades 1457 #
9 :     # compute TakeProfit percentage for various paramsets
10 :    
11 :     require(quantstrat)
12 :    
13 :     ##### PLACE DEMO AND TEST DATES HERE #################
14 :     #
15 :     #if(isTRUE(options('in_test')$in_test))
16 :     # # use test dates
17 :     # {initDate="2011-01-01"
18 :     # endDate="2012-12-31"
19 :     # } else
20 :     # # use demo defaults
21 :     # {initDate="1999-12-31"
22 :     # endDate=Sys.Date()}
23 :    
24 : erastus 1515 source(paste0(path.package("quantstrat"),"/demo/luxor.include.R"))
25 :     source(paste0(path.package("quantstrat"),"/demo/luxor.getSymbols.R"))
26 : opentrades 1457
27 :     ###
28 :    
29 :     initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
30 :     addPosLimit(
31 :     portfolio=portfolio.st,
32 :     symbol='GBPUSD',
33 :     timestamp=initDate,
34 :     maxpos=.orderqty)
35 :    
36 :     initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
37 :    
38 :     ###
39 :    
40 :     initOrders(portfolio.st, initDate=initDate)
41 :    
42 :     load.strategy(strategy.st)
43 :    
44 :     ### BEGIN uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules
45 :    
46 :     enable.rule('luxor', 'chain', 'StopLoss')
47 : opentrades 1467 #enable.rule('luxor', 'chain', 'StopTrailing')
48 : opentrades 1457 enable.rule('luxor', 'chain', 'TakeProfit')
49 :    
50 :     ### END uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules
51 :     require(foreach)
52 :     #registerDoSEQ()
53 :    
54 : erastus 1515 if (!"doMC" %in% installed.packages()[,1]) {
55 :     install.packages("doMC")
56 :     }
57 : opentrades 1457 require(doMC)
58 :     registerDoMC(cores=8)
59 :    
60 :     #require(doParallel)
61 :     #registerDoParallel(cores=2)
62 :    
63 :     #require(doRedis)
64 :     #registerDoRedis('jobs')
65 :    
66 :     ############################
67 :    
68 :     results <- apply.paramset(strategy.st, paramset.label='TakeProfit', portfolio.st=portfolio.st, account.st=account.st, nsamples=80, verbose=TRUE)
69 :    
70 :     stats <- results$tradeStats
71 :    
72 : opentrades 1460 View(t(stats))
73 : opentrades 1457
74 :     plot(100*stats$TakeProfitLONG, stats$Net.Trading.PL, type='b', xlab='TakeProfit %', ylab='Net.Trading.PL', main='Luxor')
75 :    
76 :     ##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
77 :     # book = getOrderBook(port)
78 :     # stats = tradeStats(port)
79 :     # rets = PortfReturns(acct)
80 :     ################################################################

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge