SCM

SCM Repository

[blotter] View of /pkg/quantstrat/demo/luxor.7.exit.and.risk.R
ViewVC logotype

View of /pkg/quantstrat/demo/luxor.7.exit.and.risk.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1544 - (download) (annotate)
Mon Oct 21 18:34:05 2013 UTC (5 years, 7 months ago) by opentrades
File size: 2438 byte(s)
- renamed quantstrat/demo/luxor.7.exit+risk.R to luxor.7.exit.and.risk.R to fix problem using demo(luxor.7.risk+exit.R, package='quantstrat') ie. demo name without quotes

#!/usr/bin/Rscript --vanilla
#
# Jan Humme (@opentrades) - April 2013
#
# Tested and found to work correctly using blotter r1457
#
# After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
#
# Paragraph 3.5: determination of appropriate exit and risk management

require(quantstrat)

source(paste0(path.package("quantstrat"),"/demo/luxor.include.R"))

##### PLACE DEMO AND TEST DATES HERE #################
#
#if(isTRUE(options('in_test')$in_test))
#  # use test dates
#  {initDate="2011-01-01" 
#  endDate="2012-12-31"   
#  } else
#  # use demo defaults
#  {initDate="1999-12-31"
#  endDate=Sys.Date()}

source(paste0(path.package("quantstrat"),"/demo/luxor.getSymbols.R"))

### blotter

initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')

### quantstrat

load.strategy('luxor')

### BEGIN uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules

#enable.rule('luxor', 'chain', 'StopLoss')
#enable.rule('luxor', 'chain', 'StopTrailing')
#enable.rule('luxor', 'chain', 'TakeProfit')

### END uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules

addPosLimit(
            portfolio=portfolio.st,
            symbol='GBPUSD',
            timestamp=initDate,
            maxpos=.orderqty)

initOrders(portfolio.st, initDate=initDate)

applyStrategy(strategy.st, portfolio.st, prefer='Open')

View(getOrderBook(portfolio.st)[[portfolio.st]]$GBPUSD)

###############################################################################

updatePortf(portfolio.st, Symbols='GBPUSD', Dates=paste('::',as.Date(Sys.time()),sep=''))

chart.Posn(portfolio.st, "GBPUSD")

###############################################################################

View(t(tradeStats(portfolio.st, 'GBPUSD')))

###############################################################################

print(tradeQuantiles('forex', 'GBPUSD'))

dev.new()

### Uncomment to choose appropriate MAE of MFE graph

chart.ME(portfolio.st, 'GBPUSD', scale='percent', type='MAE')
dev.new()
chart.ME(portfolio.st, 'GBPUSD', scale='percent', type='MFE')

##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
# book  = getOrderBook(port)
# stats = tradeStats(port)
# rets  = PortfReturns(acct)
################################################################

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