<div dir="ltr"><div><div><div>Hi Brian,<br><br>return(as.numeric(res)) - same thing, I tried it before posting here. There is no problem if I use return(100*sign(orderqty)), which indicates the path dependency I was trying to imply. The problem doesn't seem to occur for long only positions - it gotta be switching. I believe, the problem is outside os.all.equity. Notice, it has a lot of debug output and it clearly indicates that the function returns, and returns a numeric before the problem is hit. For me it's easy to repro it (although it takes longer) with the attached script (it needs some adjustments). The problem is hit for 2001-04-08. I don't touch txnFees anywhere in my code, so I have no control over this behaviour - it needs to be type casted somewhere - from what you are saying - taking the type into account.<br>
<br></div><div></div>Thanks for the comments about the testing.<br><br>Can you point me to code which computes the portfolio size as you suggested?<br><br></div>From my experience, it's often needed to be able to show the strategy performance over years, with all the system on. That's an area quanstrat lacks - both in terms of examples and testing (I am pretty sure this is a regression since the last time I looked at it).<br>
<br></div>Thanks,<br>Ivan<br><div><div><br><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jan 14, 2014 at 9:26 AM, Brian G. Peterson <span dir="ltr"><<a href="mailto:brian@braverock.com" target="_blank">brian@braverock.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You don't actually include how you're calculating txnfees, and your example is not reproducible, so I'm forced to guess.<br>
<br>
try<br>
<br>
return(as.numeric(res))<br>
<br>
in your function.<br>
<br>
As noted in the documentation, txnFees can be a string name of a function, so forcing it to as.numeric is a really bad idea.<br>
<br>
I'll also note that you don't need to call updatePortf every time. That's extremely expensive by comparison to just adding up the realized P&L (from closed transaction) and Unrealized P&L (from your open position) yourself. You should also be aware that this approach (or yours) will only capture equity changes in a single instrument (since instruments are processed one at a time).<br>
<br>
Most literature on evaluating trading strategies (see e.g. Aronson or Tomasini and Jaekle) tends to do system design on fixed trade sizes because it is much easier to evaluate whether or not your system really has any edge, or is just participating in market drift. I tend to separate the order sizing decisions till very late in the strategy development process.<br>
<br>
Regards,<br>
<br>
Brian<div><div class="h5"><br>
<br>
On 01/13/2014 07:15 PM, Ivan Popivanov wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
It only happens when I use a custom function to compute the position size,<br>
but it won't happen with a constant size. So it may have something to do<br>
with the splitting of orders. My function uses all available equity<br>
rounding up - it's at the end. I get the following error:<br>
<br>
Error in `/.default`(TxnFees, abs(TxnQty)) :<br>
non-numeric argument to binary operator<br>
<br>
It seems that the fault is in ruleOrderProc, the caller of addTxn,<br>
whereabouts txnfees is indeed an xts object. To me the fix is to pass<br>
as.numeric(txnfees) to addTxn.<br>
<br>
Regards,<br>
Ivan<br>
<br>
PS: Is my osAllEquity a good way to implement the compounding growth or is<br>
there a better alternative? I think it's worth having an example to<br>
illustrate this functionality.<br>
<br>
osAllEquity = function(<br>
timestamp,<br>
orderqty,<br>
<a href="http://portfolio.name" target="_blank">portfolio.name</a>,<br>
symbol,<br>
...)<br>
{<br>
verbose = TRUE<br>
# verbose = FALSE<br>
<br>
if(verbose) cat("\n=====")<br>
if(verbose) cat(paste( "\n", timestamp, sep=""))<br>
<br>
if(verbose) cat(paste( "\n orderqty=", orderqty, sep=""))<br>
portfolio = updatePortf(Portfolio=<a href="http://portfolio.name" target="_blank">portfoli<u></u>o.name</a>, Dates=paste('::',<br>
as.Date(timestamp), sep=''))<br>
# end.eq = getEndEq(<a href="http://portfolio.name" target="_blank">portfolio.name</a>, as.Date(timestamp))<br>
# print( end.eq )<br>
pnl = sum(getPortfolio(<a href="http://portfolio.name" target="_blank">portfolio.<u></u>name</a>)$summary$<a href="http://Net.Trading.PL" target="_blank">Net.Trading.PL</a>)<br>
end.eq = initEq + pnl<br>
if(verbose) cat(paste( "\n pnl=", pnl, sep=""))<br>
if(verbose) cat(paste( "\n equity=", end.eq, sep=""))<br>
close.price = as.numeric(Cl(mktdata[<u></u>timestamp,]))<br>
if(verbose) cat(paste("\n close price=", close.price, sep=""))<br>
res = as.numeric( ceiling( end.eq / close.price ) ) * sign( orderqty )<br>
if(verbose) cat(paste("\n qty=", res, sep=""))<br>
if(verbose) cat("\n=====\n")<br>
# return(sign(orderqty*1000))<br>
# res = 1000*sign(orderqty)<br>
return(res)<br>
}<br>
<br></div></div>
[[alternative HTML version deleted]]<br>
<br>
______________________________<u></u>_________________<br>
<a href="mailto:R-SIG-Finance@r-project.org" target="_blank">R-SIG-Finance@r-project.org</a> mailing list<br>
<a href="https://stat.ethz.ch/mailman/listinfo/r-sig-finance" target="_blank">https://stat.ethz.ch/mailman/<u></u>listinfo/r-sig-finance</a><br>
-- Subscriber-posting only. If you want to post, subscribe first.<br>
-- Also note that this is not the r-help list where general R questions should go.<br>
<br><span class="HOEnZb"><font color="#888888">
</font></span></blockquote><span class="HOEnZb"><font color="#888888">
<br>
-- <br>
Brian G. Peterson<br>
<a href="http://braverock.com/brian/" target="_blank">http://braverock.com/brian/</a><br>
Ph: <a href="tel:773-459-4973" value="+17734594973" target="_blank">773-459-4973</a><br>
IM: bgpbraverock<br>
<br>
______________________________<u></u>_________________<br>
<a href="mailto:R-SIG-Finance@r-project.org" target="_blank">R-SIG-Finance@r-project.org</a> mailing list<br>
<a href="https://stat.ethz.ch/mailman/listinfo/r-sig-finance" target="_blank">https://stat.ethz.ch/mailman/<u></u>listinfo/r-sig-finance</a><br>
-- Subscriber-posting only. If you want to post, subscribe first.<br>
-- Also note that this is not the r-help list where general R questions should go.<br>
</font></span></blockquote></div><br></div>