It only happens when I use a custom function to compute the position size,
but it won't happen with a constant size. So it may have something to do
with the splitting of orders. My function uses all available equity
rounding up - it's at the end. I get the following error:

Error in `/.default`(TxnFees, abs(TxnQty)) :
  non-numeric argument to binary operator

It seems that the fault is in ruleOrderProc, the caller of addTxn,
whereabouts txnfees is indeed an xts object. To me the fix is to pass
as.numeric(txnfees) to addTxn.

Regards,
Ivan

PS: Is my osAllEquity a good way to implement the compounding growth or is
there a better alternative? I think it's worth having an example to
illustrate this functionality.

osAllEquity = function(
      timestamp,
      orderqty,
      portfolio.name,
      symbol,
      ...)
{
   verbose = TRUE
   # verbose = FALSE

   if(verbose) cat("\n=====")
   if(verbose) cat(paste( "\n", timestamp, sep=""))

   if(verbose) cat(paste( "\n   orderqty=", orderqty, sep=""))
   portfolio = updatePortf(Portfolio=portfolio.name, Dates=paste('::',
as.Date(timestamp), sep=''))
   # end.eq = getEndEq(portfolio.name, as.Date(timestamp))
   # print( end.eq )
   pnl = sum(getPortfolio(portfolio.name)$summary$Net.Trading.PL)
   end.eq = initEq + pnl
   if(verbose) cat(paste( "\n   pnl=", pnl, sep=""))
   if(verbose) cat(paste( "\n   equity=", end.eq, sep=""))
   close.price = as.numeric(Cl(mktdata[timestamp,]))
   if(verbose) cat(paste("\n   close price=", close.price, sep=""))
   res = as.numeric( ceiling( end.eq / close.price ) ) * sign( orderqty )
   if(verbose) cat(paste("\n   qty=", res, sep=""))
   if(verbose) cat("\n=====\n")
   # return(sign(orderqty*1000))
   # res = 1000*sign(orderqty)
   return(res)
}

        [[alternative HTML version deleted]]

_______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should 
go.

Reply via email to