Tracking Portfolio Equity bar by bar and position sizing
Author: chinook
Creation Date: 6/17/2012 2:22 PM
profile picture

chinook

#1
Hi All,

I have a portfolio of, let's say, 5 different futures symbols. I would like to keep track of the portfolio equity bar by bar for the purpose of position sizing each market using SetShareSize. Is it possible to do this from our code without using any Position sizer?

Any pointers will be helpful.

Thanks
profile picture

Eugene

#2
Hi,

It is possible but you really should start looking towards a PosSizer. This has been discussed many times before, so I'll give a couple of pointers:

* WealthScript Techniques | Interacting Dynamically with Portfolio Level Equity
* content search for the keyword "PerformanceEngine"
* Limit Monthly Drawdown / Portfolio Equity Tracker
profile picture

chinook

#3
Eugene, thank you very much for the pointers.
profile picture

chinook

#4
Hi,

I'm trying to run the code here (I already installed Community.Components):

http://www2.wealth-lab.com/WL5WIKI/kbInteractingWithPortfolioEquity.ashx

When I run the code in "Run a Strategy on-the-fly and display the portfolio equity curve" for a portfolio of 5 stocks, it compiles and runs but doesn't generate any trades. I'm using Portfolio simulation mode with fixed shares=1. If I keep everything the same, and remove the portfolio equity calculation part below

CODE:
Please log in to see this code.


then it generates trades. Any help will be appreciated.

Thanks.

profile picture

Eugene

#5
QUOTE:
I'm trying to run the code here (I already installed Community.Components):

You (a free trial user) or maybe it was tradertabb who is a customer? (Yes, I notice virtually everything - both were trying to download the same extension from the same IP address at nearly the same time).
QUOTE:
Any help will be appreciated.

Sorry, this method is not supported. You're on your own with this. Good luck.
profile picture

chinook

#6
Eugene, yes indeed, I'm doing coding for the tradertabb account.

Are there any supported methods for accessing Portfolio level equity? The main goal is to be able do position sizing each market using SetShareSize using our own code without using any Position sizer.

Thanks.
profile picture

Eugene

#7
In Wealth-Lab 6, accessing portfolio-level equity is only supported in PosSizers. Everything else is hackish to some extent. The most able and advanced hack is "Interacting Dynamically with Portfolio Level Equity" because it calls an interal method that Wealth-Lab is making a call to.

Nonetheless, it should work without any extra effort. Try the following:

1. Disable on demand update.
2. Restart Wealth-Lab or simply re-run with ClearGlobals(); inserted before other methods to clear global memory from any execution artifacts.
3.1. Run the code on only one symbol (multi-symbol backtest is done behind the scene),
3.2. and step on the first symbol of a DataSet to be sure.
profile picture

Eugene

#8
P.S. I wonder why the fuss with SetShareSize at all? Why do you think you need the portfolio equity?
profile picture

chinook

#9
Eugene, thank you very much. I followed your steps and still I'm not getting any trades in the Trades tab and the performance tab is not showing any change in equity.
Although I see that Portfolio Equity chart is fluctuating, the one created by the OnTheFly class.

For position sizing, I'm using:

Portfolio Simulation Mode
Starting Capital = 100,000
Shares = 1

If I can get this working, can I set SetShareSize in the donor strategy based on previous bar's Portfolio Equity?

Thanks.
profile picture

chinook

#10
>>P.S. I wonder why the fuss with SetShareSize at all? Why do you think you need the >>portfolio equity?

Eugene, I'd like to be able to set the position sizes with respect to :

1) changing volatility in the individual market
2) changing volatility in the portfolio equity (kind of similar to DVar)

Thus, I need to be able to access the portfolio and individual market equity series bar by bar and then look back a certain number of bars to do the calculations. For instance, for the current bar, I'll need to access the equity curves starting from the previous bar.

Thanks.
profile picture

Eugene

#11
QUOTE:
I followed your steps and still I'm not getting any trades in the Trades tab and the performance tab is not showing any change in equity.

With this method you will not get any trades in the Trades tab, there's not going to be any change in equity on the Equity tab, and no alerts are going to show up on the Alerts tab. This is by design.

The sole purpose is to get the equity curve by the portfolio simulation executing in the background (so to speak). What you should be seeing is a ChartPane replicating the portfolio equity of the strategy, and that's all. (However, unless it's a Futures contract, with Shares = 1 there's not much of an equity movement.)
profile picture

chinook

#12
QUOTE:

With this method you will not get any trades in the Trades tab, there's not going to be any change in equity on the Equity tab, and no alerts are going to show up on the Alerts tab. This is by design.

The sole purpose is to get the equity curve by the portfolio simulation executing in the background (so to speak). What you should be seeing is a ChartPane replicating the portfolio equity of the strategy, and that's all. (However, unless it's a Futures contract, with Shares = 1 there's not much of an equity movement.)



OK, Eugene I got it now. I thought something was wrong since there was no activity in the mentioned tabs!
profile picture

Eugene

#13
QUOTE:
1) changing volatility in the individual market

Volatility of the individual instrument's equity curve? Or simply the market's volatility, like in the % Volatility PosSizer? Whatever your answer will be, PosSizer still seems the natural way to go.

The market's volatility is pretty trivial, while building the individual market equity series in a PosSizer will present certain coding challenge. Still, it's natural to achieve the goal in PosSizer.
profile picture

chinook

#14
QUOTE:
Volatility of the individual instrument's equity curve? Or simply the market's volatility, like in the % Volatility PosSizer? Whatever your answer will be, PosSizer still seems the natural way to go.

The market's volatility is pretty trivial, while building the individual market equity series in a PosSizer will present certain coding challenge. Still, it's natural to achieve the goal in PosSizer.


Indeed, I meant the volatility of the individual instrument's equity curve. As you wrote market's (price) volatility is pretty easy to deal with.

Are you suggesting that there might be updates to the PosSizer?

OK, I ran the the sample code with 1 share for each market fixed. I added ClearGlobals() to the code as you suggested. The PL was +7500 from the Portfolio Equity chart. Then I removed the 'OnTheFly class' and ran the strategy as Multi Symbol Backtest. This time time the PL was -12,000. The position size was again set to 1 share. I think there's something going on here? Any suggestions?

Thank you.
profile picture

Eugene

#15
QUOTE:
Are you suggesting that there might be updates to the PosSizer?

It serves its task well, so this kind of update is not planned (too specific).
QUOTE:
Any suggestions?

Remove ClearGlobals(), it's only for debugging while I was under wrong impression (and you thought it was not working), then carefully re-read the entire Wiki article for suggestions. There's hardly anything else I'd like to add to this.
QUOTE:
Indeed, I meant the volatility of the individual instrument's equity curve.

It will be a challenge in the Strategy code as well. Keep in mind that even running the equity interaction hack using the overloaded call for singe-symbol backtest mode (SSB) is NOT equal to the individual instrument's equity within a portfolio backtest:
CODE:
Please log in to see this code.

Don't waste your time with hacks, go for PosSizer.
profile picture

chinook

#16
Thanks Eugene!

QUOTE:
It will be a challenge in the Strategy code as well. Keep in mind that even running the equity interaction hack using the overloaded call for singe-symbol backtest mode (SSB) is NOT equal to the individual instrument's equity within a portfolio backtest:


But if the position sizing is set to fixed 1 share in both cases (commissions set to zero), then the individual instrument's equity within a portfolio backtest should be equal to the one for single-symbol backtest, right?

QUOTE:
Don't waste your time with hacks, go for PosSizer.


PosSizer is very good but doesn't have the flexibility we need. I think I might need to create an outside application that processes trades of individual markets (set to 1 share) and step through it one day at a time keeping track of portfolio and individual markets equities.

Thanks again.




profile picture

Eugene

#17
QUOTE:
But if the position sizing is set to fixed 1 share in both cases (commissions set to zero), then the individual instrument's equity within a portfolio backtest should be equal to the one for single-symbol backtest, right?

True, when your portfolio has sufficient funds to execute all concurrent signals from all its constituents.

Consider that you have a DataSet with BRK.A and GOOG as of today and $125,000 to buy them on 2 simultaneously fired alerts. With 1 share, you couldn't.
profile picture

chinook

#18
CODE:
Please log in to see this code.


Yes, indeed good point there, although little bit extreme :)

My mock portfolio has 5 stocks with share prices < $200 and with $100,000 available. So they should be OK for this test.

Thanks Eugene. I think I need to write my own application here.

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