r - Capital aware position sizing in quantstrat -


i looking make maximum allowed position particular asset(symbol) function of capital(initial allocation+ pl), , indicators. tried going through replacing osmaxpos. add @ top, initial value hardcoded, , ddq indicator,

updateportf(portfolio, symbol, dates=paste('::',as.date(timestamp),sep='')) cumpl <- sum(getportfolio(portfolio)$symbols[[symbol]]$pospl$net.trading.pl) print(paste0("expfluct", data$ddq[timestamp]*2)) maxposval <- (10e6+cumpl) * data$ddq[timestamp]*2 print(paste0("maxposval = ", maxposval)) addposlimit(portfolio,            symbol=symbol,            timestamp = first(index(data)),           maxpos = maxposval ) 

this works takes execution of intraday strategy 2 years of 1 min data minutes hours portfolio being marked on every call. can point out more efficient way of doing this? thanks.

use rebalancing rule instead, rulepctequity.

see

demo('macdrebalancing')

for example.

most real portfolios not rebalanced on every trade, since that's not particularly practical, on intraday data.

rulepctequity call updateportf, you'll little value in practice adjusting trade size on every new observation.

it differs example marking whole portfolio, , looking @ total equity, not accumulated p&l in 1 instrument.

if want adjust more frequently, or want adjust based on p&l in single instrument, don't need updateportf @ all. if want initial allocation plus p&l in single instrument, should sum realized p&l instrument txns table, , calculate unrealized p&l difference in open position , current market price. several hundreds of times faster calls updateportf in cases.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -