I was testing some strategy and got very bizarre results (too good). I quickly found, that the problem is in addTxn() method and it is related to the commission parameter. In the description of the method, you can find that the fees will be subtracted.
TxnFees: fees associated with the transaction, e.g. commissions. Fees are indicated as negative values and will be subtracted from the transaction value. Optionally, ‘TxnFees’ can also provide a function of two argument quantity and price which permits user-defined transaction costs, possibly as function of transaction volume and price. Here is an example, where the sock is sold and Avg.Cost is actually higher than Price and opposite when the stock is bought. Txn.Qty Txn.Price Txn.Fees Txn.Value Txn.Avg.Cost Pos.Qty 2010-03-17 -148 117.10 17.33080 -17348.13 117.2171 -148 2010-03-18 148 117.04 17.32192 17304.60 116.9230 0 >From my point of view, then the stock is sold, I should get less -17313.47, not more -17348.13. Is it the bug? -- View this message in context: http://n4.nabble.com/Blotter-addTxn-method-tp1773855p1773855.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.