Method to calculate the peak/current portfolio equity?
Author: sedelstein
Creation Date: 2/8/2011 5:03 AM
profile picture

sedelstein

#1
I'm now ready to try a strategy I've backtested in a simulated paper trading account and set it loose, say, on the S&P100

Before I do, I was wondering if there is a method to calculate the peak equity that a portfolio obtains and the current total equity of the portfolio.

I'd like to be able to in the case of some disaster, exit all open positions when there is a portfolio drawdown of some given magnitude.

Is there a function similar to MAEAsOfBarPercent that can be applied to the portfolio as a whole rather than an individual position?

thanks for the help.
profile picture

Eugene

#2
Short answer: no.

Long answer: with some custom coding and not 100% reliable, but at least you can try this approach to derive the portfolio's equity curve and calculate your own "MAEAsOfBarPercent" based on the data series:

WealthScript Techniques | Interacting Dynamically with Portfolio Level Equity
profile picture

sedelstein

#3
Looks rather complicated (at this stage for me). It also doesn't appear to be realtime, but backtest. Is that correct??
I suppose, I'll just have to use MAE stops on the individuals positions (and pray)
profile picture

Eugene

#4
Yes, that's for backtests.
profile picture

sedelstein

#5
CORRECTED FOR TYPOS

One more question. Not sure if this should go in a different post or not so apologies in advance.

I called support at Fidelity to learn how to take my strategy from a backtest and to test it on a realtime basis in a paper account.

I went through the process of adding it to a strategy monitor and auto-placing the trades but I was somewhat confused about some aspects of my strategy and whether they would be handled correctly.

My strategy places a bar on the next day

if (entry_condition) BuyAtLimit(bar + 1, Close[bar], "");



however, it exits at the close of the the current bar

if (exit_condition) SellAtClose(bar, p, "");



When activating the strategy in the strategy monitor, I chose daily data and the support representative told me that the trade wouldn't execute at the end of the day because the data needed would NOT be available as that day's bar had not completed.

Is there a way to wake the strategy up just before the close, calculate exit_condition as of the current info for that day and place and execute the Sell at Close if the condition is met?

I would have thought this possible.

Thanks
profile picture

Eugene

#6
QUOTE:
Is there a way to wake the strategy up just before the close, calculate exit_condition as of the current info for that day and place and execute the Sell at Close if the condition is met?

See this Wiki FAQ: Is there a workaround for Market on Close orders?
profile picture

sedelstein

#7
Ok

I read the code in the programming guide. Since the strategy get signals from daily data, Do I need to access data on two scales?
Daily and minute bars and then use the minute bar to generate the signal? I still don't see how to do it.

Suppose I need today's daily rsi as of the last minute in order to trade. e.g. Sell if RSI(9 daily) > 80

At 3:59, I'm not clear on how I use the minute data to give me an estimate of today's closing 9-day RSI.
profile picture

Eugene

#8
We've deviated too much from one pretty specific to another highly different question. Nevertheless, to answer your question: no, you don't need to access minute data, the example code is purely for Daily data (Yahoo! doesn't provide intraday backfill data anyway).

The example code is illustrative and presents a plugin replacement for your:
CODE:
Please log in to see this code.
With:
CODE:
Please log in to see this code.
Hope that helps.
profile picture

sedelstein

#9
Sort of

the problem is the exit_condition. I'm using Fidelity data. If the frequency is daily, then at 3:59, the bar is not finished, then the condition can't be calculated , that is, how can I estimate this bar's RSI(9) if it isn't closed? I don't see how the code above does that.

Sorry if I'm being thick.

This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).