[R-SIG-Finance] how to use all the cumulative equities in the account to buy
Gambulator Gambulator
gambulator at gmail.com
Wed Aug 5 07:34:12 CEST 2015
I did this and it seems to work fine.
osMaxEquity <- function(timestamp, orderqty, portfolio, symbol, ruletype,
...)
{
updatePortf(portfolio, symbol,
Dates=paste('::',as.Date(timestamp),sep=''))
Posn = getPosQty(portfolio, symbol, timestamp)
if (Posn!=0){
orderqty=0
return (orderqty)
}
cumPL <- sum(getPortfolio(portfolio)$symbols[[symbol]]$posPL$
Net.Trading.PL)
totalEquity=initEq+cumPL
closePrice <- as.numeric(Cl(mktdata[timestamp,]))
orderqty=totalEquity/closePrice
print(orderqty)
return(orderqty)
}
I don't know why print does not print anything out though
On Tue, Aug 4, 2015 at 6:26 PM, Gambulator Gambulator <gambulator at gmail.com>
wrote:
> Say I am trading SPY and started with 100k. I would like to have my first
> trade to buy whatever number of shares SPY I can buy. Then let's say I made
> money and my account now has 200k, I want my next trade to use 200k and buy
> whatever SPY I can buy and if I lose money then I would use whatever the
> leftover is to do the next trade.
>
> I see people talking about using the rebalance function to do that and
> then I see people mentioning percentRisk function but I can't quite figure
> out how to call these functions properly. Perhaps they are for portfolio
> with more than 1 stock and requires asset allocation type of rebalancing.
>
> Is there an out of the box function that would buy using my current equity
> ? If not, anyone has a custom one that I can use ? After doing some
> googling, some people suggest that we can just add the P&L to the initial
> capital and figure out the current equity. Is that the way to go ?
>
[[alternative HTML version deleted]]
More information about the R-SIG-Finance
mailing list