Using the equity curve to collectively weed out bad stock performers
Author: superticker
Creation Date: 11/29/2019 5:36 PM
profile picture

superticker

#1
I would like to weed out poor stock performers within a dataset based on their individual equity curve performance. One possible approach would be to select out stocks lacking a somewhat consistent positive slope in their equity curve, but I'm open to other approaches. Perhaps a new performance visualizer could be crafted for this purpose.
profile picture

Eugene

#2
WealthScript isn't specifically designed for accessing the equity curve. Two different approaches exist to work around it so you can give them a try if you wish:

1. Using single symbol equity curve in a multi symbol backtest
2. Limit Monthly Drawdown / Portfolio Equity Tracker (portfolio only, individual symbol's equity have to be implemented as DIY)

If you manage to extract the individual equity curve of a symbol using #1 then you could leverage the built-in By Symbol visualizer's ability to automatically display the final value of each DataSeries created by the strategy (more in the WL User Guide > Preferences > Performance Visualizers > By Symbol).

Plotting the individual equity curves certainly is a visualizer's job. Such visualizer doesn't exist yet. It could resemble this graph, for example: Trade Graphs | Trade Life. However, the chart would look messy for DataSets bigger than a few dozen symbols and identifying what curve belongs to which symbol might become less straightforward.

Thinking about it some more, in the end you may ascertain that weeding out stocks with the least consistent equity slope may even incur a performance hit if they are negatively correlated i.e. supporting portfolio growth during a drawdown. Not necessarily the rule but one has to be careful about this aspect.
profile picture

superticker

#3
Trying to pull the equity curve into a strategy Execute() block seems overly complicated to me. Let's not go there.

In another thread, you said the ScoreCard metrics are equity curve aware. If these metrics already have access to the equity curve, then let's let them evaluate the equity curve and reveal their merit value for it "by symbol". I think the Ulcer Performance Index ScoreCard metric reveals the positivity of the equity curve pretty well. The question remains, "How can I list the Ulcer Performance Index in the By Symbol tab?" Can a special Performance Visualizer be written to reveal ScoreCard metrics by symbol for a dataset (no optimization involved)?

The Ulcer Performance Index metric is already listed "by symbol" in the Performance > Results tab immediately following an optimization. But in my case, the optimization has already taken place (on a different day) and the Preferred Values (PVs) have already been established, so there's no Performance > Results tab available. I just want to dump the Ulcer Performance Index "by symbol" employing established PVs for all the stocks in a dataset. How can I do that? This shouldn't be a big deal unless there's a scoping problem with the relevant data collections involved. Is there?

I'm willing to hack the Ulcer Performance Index code and have it dump it's metric and symbol value to disk (or Windows clipboard) if I have to. But that's an ugly hack. There should be a more elegant way. Can't this output just be dumped to a Performance Visualizer tab or is there a scoping problem preventing this? Are ScoreCard metrics only available to an optimizer and not a performance visualizer?
profile picture

Eugene

#4
QUOTE:
In another thread, you said the ScoreCard metrics are equity curve aware. If these metrics already have access to the equity curve, then let's let them evaluate the equity curve and reveal their merit value for it "by symbol".

They are. WL returns the portfolio's results which includes its equity/cash curves. But it's scorecard/visualizer developer's job to build the equity curve on a per symbol basis as this is not provided by WL.

Let's start with how exactly (one way) would you prefer to weed out the bad stock performers. By looking over a performance visualizer output on the Ulcer Performance Index on a per symbol basis as your post #3 suggests? Or straight in Strategy code of a Multi-Symbol backtest? In Optimization? That might clarify the direction we're going.
profile picture

KGo

#5
If you have a simulation or a strategy trade list that has trades for all symbols using the PVs, here is how I get all the WL optimizer metrics by symbol. It's not fully automated but is quite fast and easy to set up with minimal coding.

Optimize Historical Trades downloadable strategy using a trade list containing all trades for all symbols. Then each optimization will be for a different symbol in that file.

Do this by adding a parameter to Historical Trades to use the optimizer. Each system number will be one symbol's trades.
CODE:
Please log in to see this code.


Replace the execute method with something like this
CODE:
Please log in to see this code.


Copy/paste the trade list to a spreadsheet. Put *AAPL* in the "Entry Name" Apple stock with the formula =CONCATENATE("*",B2,"*") (in Excel where B2 is the symbol) and copy down to all the trades. Save for example as "Portfolio Trades 01.csv" as used above.

~NoInclude as shown will take all trades and should match the source strategy results using shares position sizing to duplicate all trades to verify it's working as expected.

Remove the No and just use ~Include to allow only one symbol for each optimization run. Use shares or percent equity position sizing or the Position Options PosSizer with percent equity - whichever makes sense.

Paste the optimizer results to a spreadsheet Col B next to the symbol list in Col A for easy symbol reference.

profile picture

superticker

#6
QUOTE:
WL returns the portfolio's results,... But it's [the] scorecard/visualizer developer's job to build the equity curve on a per symbol basis ...
That's reasonable. And that code has already been developed for the Equity Curve tab, so we just reuse that code (without the plotting GUI).

QUOTE:
... how exactly ... would you prefer to weed out the bad stock performers? [Option 1] By looking over a performance visualizer output on the Ulcer Performance Index on a per symbol basis as your post #3 suggests?
Yes, I think that's the most intuitive interface for the casual user. Just produce a two column table of Symbol and the Ulcer Performance Index (and perhaps a third column for one other ScoreCard metric) that can be sorted by column and captured into the clipboard. Keep it simple. You can call the performance visualizer tab "Equity Curve Evaluations" (or even "Equity Curve+" if it's going to have many sub-tabs, which I think is an overkill).

QUOTE:
[Option 3] In Optimization?
Well, the assumption here is that one would be doing the weeding out immediately following PV optimization. I agree, it would be best to re-optimize the PV parameters just prior to passing judgement on whether or not a dataset of stocks can successfully work with a given strategy. But I'm concerned the user may have to jump through too many hoops to finally reach the weed out process at the end of the rainbow. If we are talking about writing a "dummy optimizer" to perform one iteration on each stock using existing PV values and displaying ScoreCard results in the Performance > Results tab by symbol, that would work fine for me. But is this approach intuitive for the average end user? I think the casual user would tend to look for a performance visualizer instead, but he would need to have recently performed a PV optimization first. And that should be noted on the visualizer's tab screen.

What are your thoughts?

The suggestion in Post# 5 is an interesting hack, but I wouldn't use that approach "by design". By design, we want something more streamlined and intuitive.
profile picture

Eugene

#7
We're not ready to talk about the casual user's experience of your request. In an ideal world, it's the built-in By Symbol visualizer which should be extended with a capability to display user-selected performance metrics like the UPI. Unfortunately, this feature extension is not considered by Fidelity as far as I know. Essentially, dumping the Ulcer Performance Index "by symbol" for all the stocks in a DataSet to a two column table would duplicate the By Symbol visualizer. So it becomes a single-user solution. If you wish to create that new visualizer as a DIY project, these resources might be a good start (make sure you've logged in to the Wiki to see the protected content):

Wealth-Lab Version 6 (.NET) Development Guide
Download Project Source Code

Of course you're welcome to ask me here if you need assistance with this.

Don't forget there's a script-based alternative in post #2. Despite that solution may seem complicated, building the individual symbol's equity curve and applying the performance metric like UPI to it as a DataSeries so its final value appears on the By Symbol tab looks like the most straightforward option so far.

P.S. A side note. Plotting the individual symbol's equity curves on a separate tab of the Equity+ visualizer (except the performance metrics which would probably be extraneous to this visualizer) might be an interesting enhancement. But I'm concerned about the crowded look as on the Trade Life chart that would take place for DataSets bigger than say Dow 30. This reduces its appeal.
profile picture

superticker

#8
QUOTE:
... it's the built-in By Symbol visualizer which should be extended with a capability to display user-selected performance metrics like the UPI.
That works for me if By Symbol has the scoping capability to see the ScoreCard metrics without escaping the C# language (i.e. without reflection). Right now it only displays DataSeries metrics from the execute block.

I'm from the embedded systems world, so I haven't dealt with a Windows GUI before. This project will have to wait until summer, 2020. Would there be any problems making the entire By Symbol tab Windows Presentation Foundation based instead of using obsolete Windows.Forms?

I agree, the Trade Life chart looks too busy. It would be nice if one could mouse over an individual plot and see which symbol it belongs to.
profile picture

Eugene

#9
QUOTE:
That works for me if By Symbol has the scoping capability to see the ScoreCard metrics without escaping the C# language (i.e. reflection). Right now it only displays DataSeries metrics from the execute block.

Reflection is the idea behind the proposed workaround #1 (Using single symbol equity curve in a multi symbol backtest):

Interacting Dynamically with Portfolio Level Equity

But it's encapsulated so no worries :) What it does in post #8 is execute your Strategy on each symbol individually to get the equity curve (i.e. not a multi-symbol portfolio backtest). You can have an array of the equity curves to apply a performance metric like Ulcer Performance Index (log in to the Wiki to see its source code).

The other workaround #2 (Limit Monthly Drawdown / Portfolio Equity Tracker) may be simpler to grasp and doesn't rely on Reflection. But you have to build that individual symbol's equity DataSeries - it's not in the script.
profile picture

superticker

#10
QUOTE:
Reflection is the idea behind the proposed workaround #1 [Option 1] ... But it's encapsulated so no worries.
So there is a scoping problem with getting "direct access" to all the relevant data collections. I agree, if the reflection code is encapsulated, then it's not my problem. (I would prefer not to code the "escaping the C# language" part.)

QUOTE:
What it does in post #8 is execute your Strategy on each symbol individually to get the equity curve
So that's why the By Symbol column makes WL slow down significantly when it's included. Interesting. And that also explains why including Bars.Cache.Clear(); in a strategy to purge all extraneous DataSeries really speeds up the strategy when the By Symbol column is included.

QUOTE:
The other workaround #2 (Limit Monthly Drawdown / Portfolio Equity Tracker) ... doesn't rely on reflection. But you have to build that individual symbol's equity DataSeries.
I'll take another look at that. What I don't want to do is make strategy execution slower than it already is, and I thought about removing the By Symbol column for production strategy runs just for that reason.

Thanks for providing me with the bigger picture.
profile picture

Eugene

#11
Should you have any further questions re: implementing solution #1, please let me know.
profile picture

KGo

#12
QUOTE:
The question remains, "How can I list the Ulcer Performance Index in the By Symbol tab?" Can a special Performance Visualizer be written to reveal ScoreCard metrics by symbol for a dataset (no optimization involved)?


This will give access to all the Scorecard metrics including Ulcer Performance Index for by symbol evaluation of most any strategy. This does not meet the the built in visualizer objective here but will provide easy by symbol results for casual users.
https://www.wealth-lab.com/Forum/Posts/New-By-Symbol-Analysis-Available-40088/
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).