Possible to access equity values directly? - seem to be different from those in EquityCurve
Author: sburgener
Creation Date: 11/6/2012 10:35 AM
profile picture

sburgener

#1
Hi,

I have seen in your wiki (http://www2.wealth-lab.com/WL5WIKI/OpenIssues.ashx?HL=equitycurve) that EquityCurve wasn't returning values in line with equity used in PosSizers. This is exactly what I am experiencing as EquityCurve doesn't return the values I would expect.

Is there a way to access the equity value directly? I can access it through SizePosition when using PosSizers but only for days on which we have Alerts, i.e. positions to be sized, but actually I would like to access equity for the other days as well.

Thanks!
Seb
profile picture

Eugene

#2
Hi,

No but this ain't a problem. The equity value is calculated on the fly when you call SizePosition(), but it's not required because you still can access EquityCurve, following this calling convention:

Why accessing an EquityCurve(CashCurve) value in multi-symbol portfolio simulations may produce unexpected results in PosSizers and Performance Visualizers?

Reason: because the different historical DataSets aren't synchronized when backtesting.

Solution: in a multi-symbol backtest, it's advised to use the ConvertDateToBar method of the EquityCurve or CashCurve DataSeries to get a correct bar. For example, here's how to determine the equity curve value at the beginning of a month using ConvertDateToBar:


CODE:
Please log in to see this code.



P.S. On a related topic. Make sure your PosSizer is not using the "Series" method when creating indicators based on EquityCurve/CashCurve for it will return an incorrect value. Instead, use the "Value" method which will return correct results. (More details in the PosSizer API guide).
profile picture

sburgener

#3
Thanks Eugene, but even after using Synchronize(EquityCurve) I still get a discrepancy.

The only thing I would like to do is to display the EquityCurve in the chart window (for a portfolio backtest), using the method with the Donor strategy as explained in Interacting Dynamically with Portfolio Level Equity. So my strategy doesn't actually use the EquityCurve, I just would like to display it, that's all.
When I then debug into my PosSizer (which sizes positions according to the total available equity, retrieved through the equity field), I get equity and cash values according to what I would expect. More specifically I looked at the evolution of cash values in the PosSizers on a given bar (on which I have several new positions being entered on the close) and I see the latter cash value decrease (on the same bar) when entering the various positions one after the other: this is in line with my own aside computation. Also, I replicated the equity values similarly to Portfolio Equity Tracker in order to double-check the behaviour of the PosSizer, and make sure that strategy results are exactly the same as with the PosSzier.

However, when plotting both the CashCurve as well as the EquityCurve, I don't get what I would expect. In particular, on the first day of investment (I invest on close), the sum of both these values doesn't sum up to my initial portfolio value (as of one day before investment date) and the difference is signficative: 1,001,050 instead of 1,000,000.

Thanks again for your time and help!
profile picture

Eugene

#4
You're looking in the wrong direction, so PosSizers and Synchronize alike are not going to help. Don't mix "Interacting with Equity" that you're using to plot Equity with the 'official' WealthScript methods.

"Interacting with Equity" is an unofficial solution. Although the discrepancy of 0.1% is not critical, it's still sad to hear that a glitch may still exist despite my efforts to make it 100% identical to the Wealth-Lab equity curve. Of course, unless you're using a customized commission plan i.e. you haven't reset the selected Commission plan's settings to default in Wealth-Lab's Preferences dialog.*


*Notes and Limitations

Have you? Otherwise I might need a reproducible test case for troubleshooting the discrepancy, and I'd appreciate your assistance with this.
profile picture

sburgener

#5
Thanks for your comments Eugene.

I had a further look into the differences and I might have an idea where they are coming from.

Currently my signals are created 5 days before I invest (e.g. on bar 206 for an investment on bar 211). The SizePosition method however becomes active only 1 day before we enter the position (i.e. on bar 210). When using EquityCurve, might this be a possible cause of the problem?
Another issue might come from the fact that for an investment on a day (e.g. bar 211), in my PosSizer I take the equity value (which is obviously as of bar 210) and add the intraday moves (those on day 211), in order to reinvest the full available equity on the close of the investment date (bar 211). This is different from what your equity-sizing PosSizers are doing, where for an investment on bar 211, we would take available equity on the close of bar 210.

Might one of the above be the cause of the discrepancy?

I am currently checking to put together a test case for you which I can send you over.
profile picture

Eugene

#6
QUOTE:
Might one of the above be the cause of the discrepancy?

Frankly, I don't know why again we're talking about PosSizers. As already noticed in my previous, the source of possible but insignificant discrepancy of 0.1% is my "equity interaction" hack.

Just to comment:
QUOTE:
Currently my signals are created 5 days before I invest (e.g. on bar 206 for an investment on bar 211). The SizePosition method however becomes active only 1 day before we enter the position (i.e. on bar 210).

Right, because PosSizers assume that Positions in a Strategy are executed at "bar + 1", and this is not subject for change.
QUOTE:
Another issue might come from the fact that for an investment on a day (e.g. bar 211), in my PosSizer I take the equity value (which is obviously as of bar 210)

It's not that obvious for the reason already mentioned above: FAQ > Why accessing an EquityCurve(CashCurve) value in multi-symbol portfolio simulations may produce unexpected results in PosSizers and Performance Visualizers?
profile picture

sburgener

#7
QUOTE:
Frankly, I don't know why again we're talking about PosSizers. As already noticed in my previous, the source of possible but insignificant discrepancy of 0.1% is my "equity interaction" hack.

I was mentioning PosSizers because the value equity in SizePosition is correct, but EquityCurve, to which I am comparing it to, is not.

QUOTE:
Have you? Otherwise I might need a reproducible test case for troubleshooting the discrepancy, and I'd appreciate your assistance with this.

I've prepared an example of code I could send you through, but I'd rather send it to you privately.
profile picture

Eugene

#8
QUOTE:
I was mentioning PosSizers because the value equity in SizePosition is correct, but EquityCurve, to which I am comparing it to, is not.

At the risk of repeating, you should not access the EquityCurve in PosSizers on a bar by bar basis in multi-symbol backtests. The value may and will be different due to a long-standing WontFix issue which has to be worked around by the user, for each PosSizer/Visualizer independently. (FAQ)
QUOTE:
I've prepared an example of code I could send you through, but I'd rather send it to you privately.

I'd appreciate if you could water down your example of "equity interaction" in a Strategy to a manageable something, and leave it here. Ideally, using a built-in/public Strategy as the "donor". Don't forget all the settings (including Wealth-Lab's Preferences: as I said, commission plan's settings have to be reset to their default values). tia.
profile picture

sburgener

#9
Eugene,

Please find below an example of code in which the sum of CashCurve and EquityCurve on the first investment date doesn't sum to the initial portfolio value and where EquityCurve is different to what we would expect.

Settings:
- Commissions and return on uninvested cash: both unticked (i.e. they are worth 0)
- DataSet: any (I tested the below on several ones, notably Dow 30 from Yahoo)
- Scale: Daily
- DataRange: 01/01/2000 - 30/10/2012
- Margin: 3 (needs to be bigger than 1 to have no omitted positions)
- PosSize: Starting Capital 1,000,000
- PosSizer: Position Options, UseTag set to % Equity (everything else left unchanged)
- Preferences -> Advanced options: 7 decimal places for Pricing and Indicator

With this example, when recomputing invested value based on the Trades tab, I get 976,188.0749 for 1st Feb 2000, whereas EquityCurve in the Chart window (for AA) amounts to 999,992.5 (and cash to -1,986,279).

CODE:
Please log in to see this code.


profile picture

Eugene

#10
Sebastian,

Unfortantely, this discussion has created the wrong impression of a discrepancy between the Wealth-Lab-generated EquityCurve and "equity" value in PosSizers. This is not the case.

The class I created to work around the absense of equity curve interaction in Version 5/6 essentially is a reverse engineering of what Wealth-Lab does internally. Discrepancies with the native EquityCurve may exist due to solution's hackish nature, so it's not really a support issue. The open source code is free, so you're welcome to troubleshoot and contribute to make it more robust.

P.S. Your example code has to be improved:

1. The dummy class should inherit from WealthScript rather than Test:
CODE:
Please log in to see this code.


2. In Wealth-Lab, trading orders should not be issued for the dates exceeding bar+1. Therefore I will not consider obsDate greater than 0 a use case.

3.1. An even margin factor may still not be enough: it's the odd part that makes the difference e.g. 1.05. Ideally, your test should be performed in Raw Profit mode.
3.2. Alternatively, you should have used "Use Worst Trades in Portfolio Simulation" or assigned a fixed Position.Priority value.

4. For the reason above, it's theoretically possible for LastPosition to error out so I'd use this instead:
CODE:
Please log in to see this code.


Otherwise, there may exist TWO sets of trades: one processed by Wealth-Lab natively (i.e. Test.Execute) and another one in Donor2.Execute. A discrepancy in EquityCurve in this case is guaranteed.


Using the revamped code below I get absolutely IDENTICAL ending value of the EquityCurve, given Raw Profit mode, no commissions, no slippage, "Use Worst Trades..." and NO other options enabled in Preferences:

CODE:
Please log in to see this code.


It doesn't mean that the equity interaction technique doesn't have something to be improved, though. I'll put a note on my todo list to give it another test in the future.
profile picture

sburgener

#11
You're great, thanks Eugene for your correction and interesting comments!

Regarding your comment,
QUOTE:
2. In Wealth-Lab, trading orders should not be issued for the dates exceeding bar+1. Therefore I will not consider obsDate greater than 0 a use case.
i am totally aware of the latter, but I was replicating an index which exists in the market place and uses this (in my opinion suboptimal) trading lag.

Thanks again!
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).