[R-SIG-Finance] Any R api's available to do modelling with MM algos or portfolio weights?

Pie T pietrader at gmail.com
Sat Sep 15 19:21:08 CEST 2012

Hi -
I would like to model following scenarios for my past trades and
wondering if there are any R APIs already available in blotter (or
another R package). If not can you please advise on how you as an
experienced Quant/R programmer would do it. If you can include a code
fragment (or a link to a sample) that is great but otherwise pointers
is also fine.

I have a list of transactions that I can read into R as an xts/df
object. The Quantity in input txn table is normalized to 1 share/1
contract.  The format of the transaction table is as follows:

"TxnID, Symbol, Quantity, Long/Short, Entry Date, Entry Price, Exit
Date, Exit Price, Txn PnL (%)"

Now I have an Account with initial capital as $X. Following are couple
of scenarios I would like to model and see how my portfolio
performance stats would looked like. I am wondering if there is any R
API to which I can just pass this input transaction table, initial
account value, weight(s) and type of MM algorithm to use and get in
return new transaction table. Once I have new transaction table, I
know how to get various performance metrics & charts in R using
blotter & PerformanceAnalytics packages.

(a) (Equal Weight algo) Use 20% of portfolio (i.e., weight = 0.25) for
each transaction and get a new transaction table with an extra column
at the end like "Account PnL". If all transactions are non-overlapping
then it is just matter of appending weight column and simple
multiplication. But many of the transactions overlap with 1 or more
other transactions. So the API needs to be intelligent about that
while determining how much cash available for the next transaction.

(b) (Volatility Weigting algo) Do same as above but weight it by
volatility (say ATR) of the symbol i.e., I specify to R package API
that 1 unit of volatility = 1% of portfolio and the api after
execution returns a new transaction table with an "Account PnL"

(c) (Fixed fractional algo) Same as above but API takes as input R
($risk per share) for each transaction and another input (i.e.,
guidance 1R = x% of portfolio) and returns a new transaction table
with an "Account PnL" column.

My apologies if this is not the right forum for this question. I look
forward to your suggestions.


More information about the R-SIG-Finance mailing list