Access positions before PosSizer is running
Author: ewessely
Creation Date: 7/29/2012 8:09 AM
profile picture

ewessely

#1
Hi,
is there a way in a multi-symbol test to access the positions (and modify) BEFORE the position sizer will run?
Background: I want to eliminate (or set share size to 0) for some positions based by a criteria for which I need all possible positions from all symbols in the datase. I tried to do this in my own possizer, but there you can't get the list of all positions - you only get taken positions and canditates for a specific bar.
Greetings
Erich
profile picture

Eugene

#2
Hi Erich,

It's not clear. If the list of all open and closed positions for all symbols (the Positions collection) and the list of theoretical signals on each run of the PosSizer (Candidates) is not what you're after, then what else that these 2 collections don't encompass are you looking for?
profile picture

ewessely

#3
Hi Eugene,
the idea is to eliminate trades with a profit of eg more than 2*StdDev of all possible trades.
In the strategy after the trading loop I have all possible trades in the position collection, but only for one symbol.
In the possizer you only get the canditates for one bar and can't calculate the StdDev including all positions. And in the positions collection in the possizer you will only get the realtrades. (after you decided for one of the candidates).
So I did not find a way to access a collection containing all trades of all symbols before possizing is done.

Greetings
Erich
profile picture

Eugene

#4
Erich,

Thanks for the clarification, I have a clearer image now. A possible solution may be to keep snapshots of the Candidates lists in a collection (e.g. Dictionary).
profile picture

ewessely

#5
Eugene,
I also thought of this, but then I have a complete list of the candidates after the possizer has run and therefore no chance to choose of the candidates based on this result.
Is there no event between finishing the trading loop of all symbols and starting the possizing where I could hook into the process?
profile picture

Eugene

#6
Good point. I forgot to add that in order to work, it's necessary to declare that that collection as a class-level static variable.
profile picture

ewessely

#7
Cool idea, thank you!
But how can I then pass a value calculated based on this collection to the possizer?
Greetings
Erich
profile picture

Eugene

#8
The point is, that collection (e.g. List<Candidates>) lives inside the PosSizer as a static class-level variable.
profile picture

ewessely

#9
Eugene,
that's not really clear to me.
If I define the collection in the PosSizer, of course I can collect all candidates when CalcPositionSize is called. But then I have the complete list of ALL candidates after the sizing is done for the last bar. And then I have no chance to change the Possize based on a value calculated on ALL canditates.
On the other hand: when I collect all positions in a class level variable in the strategy, there is no way to pass it to the possizer (or only a value calculated on this)
profile picture

Eugene

#10
You're not following me. No need to pass anything from the Strategy as the PosSizer has everything. But as Wealth-Lab doesn't keep historic lists of Candidates, overwriting them each time SizePosition() is run, your job is to collect all possible trades (candidates) in a static class-level collection (or serialize them in an XML file if you prefer to keep the state like that).

1. In your PosSizer, define a static class-level variable e.g. Dictionary<int,List<Position>> where key = bar and value = Candidates for that particular bar (i.e. List<Position>)
2. On each sizing run, check if this collection already contains the Candidates list for that bar. Otherwise append it to the collection.
3. Query the resulting collection that contains all Candidates for all bars. (I suggest choosing .NET 3.5 platform version when targeting your assembly to be able to use LINQ for easier querying.)

Makes sense?
profile picture

ewessely

#11
Eugene,
does not really make sense and does not solve the problem.
When I collect all candidates in the PosSizer, you will agree that ALL candidates are available not before the SizePosition for the last bar is executed. I only get the candidates when SizePosition is called for a bar.
So the problem is still: How can I calculate the StdDev of ALL candidates BEFORE I do the sizing on the first bar? I don't have all candidates when the PosSizer executes the SizePosition the first time. All I want do is: Set PosSize to 0 for a cantidate in PosSizer if Profit greate 2* StdDev of all possible trades (=candidates). But the StdDev of all possible trades cannot be calculated before knowing them.
profile picture

Eugene

#12
QUOTE:
When I collect all candidates in the PosSizer, you will agree that ALL candidates are available not before the SizePosition for the last bar is executed. I only get the candidates when SizePosition is called for a bar.

You only get the Candidates for that particular bar, plus snapshots of all previous "Candidates" - if you followed my suggestion, of course. Won't that make the complete list of all possible candidates for each bar the SizePosition method had been executed on?
QUOTE:
How can I calculate the StdDev of ALL candidates BEFORE I do the sizing on the first bar?

Just like you would do it on ANY bar. The bar number makes no difference.
QUOTE:
I don't have all candidates when the PosSizer executes the SizePosition the first time.

Wrong. You do have all candidates for that bar when the PosSizer executes the SizePosition method.

P.S.
What really makes no sense is "2*StdDev of all possible trades". What did you mean by that, precisely? Standard deviation of what number, NetProfit? That doesn't apply to a candidate trade.
profile picture

ewessely

#13
QUOTE:
You only get the Candidates for that particular bar, plus snapshots of all previous "Candidates" - if you followed my suggestion, of course. Won't that make the complete list of all possible candidates for each bar the SizePosition method had been executed on?

Yes, but as outlined at the end and not at the beginning of Sizing

QUOTE:
Just like you would do it on ANY bar. The bar number makes no difference.

Mathematically there is a big difference between of the StdDev of the candidates on a singe bar and ALL possible trades.

QUOTE:
Wrong. You do have all candidates for that bar when the PosSizer executes the SizePosition method.

Right, bit only for THAT bar and not for ALL bars, therfore not useful.

QUOTE:
P.S.
What really makes no sense is "2*StdDev of all possible trades". What did you mean by that, precisely? Standard deviation of what number, NetProfit? That doesn't apply to a candidate trade.

StdDev of NetProfit. Sense: Filter out trades which are too optimistic (maybe because of spikes in 1 or 5 min data)

Conclusio: I will build the list in the strategy, write it to a file, read the file in PosSizer. Everything else than perfect , but maybe a working solution....
profile picture

Eugene

#14
Conclusion: we did not understand each other. Anyway, good luck to you with your venture.
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).