Backtest: Portfolio Profit or Loss exceeds an amount?
Author: falcon82
Creation Date: 8/3/2013 7:42 AM
profile picture

falcon82

#1
Hello,

is there a way to backtest in WL the following scenario?

The portfolio profit or loss in a backtest (over all holding positions) exceed a special/defined amount. In this case WL should close the current position with the biggest profit or loss (or another option: all winning/losing positions).

Regards
profile picture

Eugene

#2
In Wealth-Lab 6, accessing portfolio-level equity is only supported in PosSizers. Portfolio P/L is not supported in Strategies because they're pre-executed with 1 Share (RP mode) to obtain the list of all trades and then, real-world position sizing rules come into play. Still, PosSizers only size positions and closing out a trade isn't something they can help with.

But there is an advanced workaround in Community Components that makes possible to get a portfolio simulation's equity curve. It's been discussed on the forum before so you'll find some food for thought. Here's it:

WealthScript Techniques | Interacting Dynamically with Portfolio Level Equity
profile picture

falcon82

#3
Hello Eugene,

thanks for your answer - that helped a lot! Just one last question on the entry side of a trade:

Can I interact with the open positions from other symbols in the Wealth-Lab Script or is it just possible with a PosSizer as well?
Example 1: If I already have a open position in AAPL then don't open a position in GOOG.
Example 2: If a possible position in one symbol is highly correlated with the existing open positions in other symbols then refuse the trade.
If the examples are not possible within the WL script - can I check these constraints with a PosSizer?

Thanks for your help!
profile picture

Eugene

#4
Hi Andreas,

QUOTE:
Example 1: If I already have a open position in AAPL then don't open a position in GOOG.


There's ActivePositions collection that contains all open positions. Each Position, active or not, has a Symbol property (plus an alternative: Position.Bars.Symbol) that returns the symbol for a given position. Looping through ActivePositions, determine if there's an open position in AAPL and act accordingly. Example:

CODE:
Please log in to see this code.


QUOTE:
Example 2: If a possible position in one symbol is highly correlated with the existing open positions in other symbols then refuse the trade.
If the examples are not possible within the WL script - can I check these constraints with a PosSizer?


If by saying "position in one symbol is highly correlated" you actually meant correlation between prices of underlying symbols, then you might find this strategy helpful:

Correlation Matrix
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).