PosSizer request: Vary active positions based on DataSeries value
Author: Eugene
Creation Date: 5/12/2010 7:02 AM
profile picture

Eugene

#1
Here's a PosSizer idea suggested by mikesblack (link to original thread):
QUOTE:
If it's not too much trouble was wondering if I could interest you in developing a new position sizer? I would like to be able to vary the number of active positions based on some dataseries value? Could this be a possibility? (...)

I'll explain what I am doing specifically to illustrate my idea.

I have created a .csv file from the content of an equity curve page from a strategy I created and imported it into Wealth Lab Data Manager. The data consists of only 2 columns, date and close( equity ).

Next, I plotted various indicators on that data( symbol) and have exported this to Excel for analysis, e.g. regression, histograms, etc.. Specifically, I have created a target variable that is the 6 day ROC lagged 6 days marked next to current indicators.

From the results of my analysis I have found some what appears to be meaningful relationships between certain indicated values on the equity curve and system 6 day returns looking 6 days forward.

With this new information I would like to vary exposure in the market accordingly. So, let's say for simplicity I am using an oscillator with discrete steps from 0-10. If there is some linear relationship ( BTW most of the relationships I have discovered are far from linear.) In this case I would want to vary/ limit the number of positions taken from say perhaps 1-10 symbols based around the oscillator values.


If this could be done with ease, perhaps then beside limit the number of positions entered or bought, but also to sell down positions to meet the level of the indicated value.(Not sure how to think about that one. If anyone would know if and how, it would be you.)

I am interested in limiting numbers of positions, but I wonder if we one could apply position size and position number to the mix? If not, Number over Size is my preference.
profile picture

Eugene

#2
Mike,

I don't see it as a universal PosSizer that can benefit all users. Too many indicators and oscillators with different readings will make it hard to avoid setting up a GUI dialog like this or that, and I'm not a fan of complex settings dialogs. There also are other reasons. So I'll give you some suggestions how to build this PosSizer on your own using Visual Studio Express (or SharpDevelop), PosSizer API manual and demo project source code.

My suggestion would be the following. Finding out the DataSeries value at the bar when a position is being sized. In my opinion, reading the DataSeries name from PosSizer GUI dialog (and subsequently looking it up in the current position's Bars.Cache), or importing DataSeries from a disk file are far from elegant. So the most straightforward way is to pass a value with the Position.Priority or Position.Tag properties.

In its simplest case, you don't even need a PosSizer GUI dialog to set up - though adding one should not be a big problem. First, I'll illustrate how you can size a position based on a DataSeries value (of type double) passed with the current position's .Tag property:

CODE:
Please log in to see this code.


Next, here's how to limit the number of entered positions (to answer your question: PosSizers can't sell positions, the only thing they do is size) based on a DataSeries value:

CODE:
Please log in to see this code.
profile picture

mikesblack

#3
Thank you Eugene. I will give the second version a try.

Perhaps a light will shine on my programing abilities and so won't have to rely on your generosity. I appreciate your attention and hope not to over do my requests.
profile picture

Eugene

#4
I'd suggest taking the open source project and inserting one of these code snippets. It's a drop-in replacement for "the heart of the PosSizer" aka the SizePosition method. Creating a PosSizer can seem a bit complicated, but should you have any questions, you can always find help here.
profile picture

avishn

#5
I'm using currentPos.Tag to size positions in my custom position sizer. That obviously works only if currentPos is not null, so it doesn't really work for alerts. Is there a recommended approach on how to make it work (i.e. to pass a double value from strategy to position sizer for alert sizing)?
profile picture

Cone

#6
Very good question. Besides resorting to global variables, it seems like we'll need to dig for a better answer.
profile picture

Eugene

#7
Not sure what you mean by global variables? PosSizers don't support WealthScript methods directly, but it's possible to assign any value to the Bars object using the Bars.Tag property when sizing for an Alert (i.e. if( bar == Bars.Count-1 ) ).

Another possibility that comes to mind when talking about globals is using file operations i.e. TextWriter in your Strategy and TextReader (or StreamReader) in the PosSizer.
profile picture

Cone

#8
Thanks Eugene, I'll put my shovel away now.