Hi,
I need a way to limit Position Sizes in Future Mode. The main setup should be let's say 'Starting Capital = 10000' and 'MaxPercentRisk = 10%'.
Now in real world trading (mini...) it's not realistic to trade 1000000000 contracts so that I would like to limit each trade to max 10000 contracts.
I tried 'Position Options' from the PositionSizer Library: 'Max Invested $' doesn't seem to work in Future Mode (= no trades at all), 'Adjust size to XX$' seems to be ignored in Future Mode.
Another approach I tried was to write an own PositionSizer based on the demo. This one seems to work but while a 'standard' strategy execution takes 0.8 seconds to execute my demo based PosSizer takes 10 seconds and more which is (in my case) useless for backtesting.
Is there something I might have missed...?
Size:
Color:
Hi Michael,
QUOTE:
Another approach I tried was to write an own PositionSizer based on the demo. This one seems to work but while a 'standard' strategy execution takes 0.8 seconds to execute my demo based PosSizer takes 10 seconds and more which is (in my case) useless for backtesting.
You overlooked a bottleneck in the custom PosSizer code. PosSizers don't come with a speed penalty.
QUOTE:
I tried 'Position Options' from the PositionSizer Library: 'Max Invested $' doesn't seem to work in Future Mode (= no trades at all), 'Adjust size to XX$' seems to be ignored in Future Mode.
That's right: basis price is not honored. I can fix it in next build of MS123 PosSizers, if you could help me by reviewing and correcting the proposed changes to the formulas (in bold):
1. 'Max Invested $'To work with Futures symbols, the existing (position size x Basis Price) value should be
multiplied by the Point Value, right?
Also, should the current position size be
multiplied by the Point Value?
2. 'Adjust size to XX$' If (Current Size x Basis Price
x Point Value) < Minimum Required Order Size
then adjust the size as follows:
Minimum Allowed Order Size / Basis Price
x Point Value--
I appreciate if this can be verified.
Size:
Color:
Hi Eugene,
Sorry, I dont get it I think...:
QUOTE:
You overlooked a bottleneck in the custom PosSizer code. PosSizers don't come with a speed penalty.
Is there something I can do myself or is this by design?
I really would appreciate to help you but my Testing-Symbol's FutureMode Setup is
-
Margin: 2
Point Value 0.01
Tick 1
Decimals: 0
-
so that (Basis Price independent) the Cash/Equity is only be divided by the Margin to get the Position Size. In 'my' PositionSizer the limit is simply limited by
CODE:
Please log in to see this code.
Size:
Color:
Size:
Color:
I must admit before WealthLab I didnt know anything about C# or coding at all. Eugene, I'm sure it is something else, I also tried to figure it out by comparing a 'standard WL Position Sizer (10% Risk)' to the one I took from the 'Create a PosSizer.pdf'. It's obvious that there is something wrong since it consumes 10x more workload. But to understand the profiler output I seem to either need more knowledge about .Net or WealthLab under the hood.
I only could drill down processing to find a bottleneck at 'ApplyPositionSize -> BuildEquityCurve -> ?'.
http://img72.imageshack.us/img72/4403/profiler.jpgCODE:
Please log in to see this code.
Size:
Color:
1. Make sure you're running the release build (as opposed to debug build).
2. Also, running under debugger may slow down an assembly's performance.
Size:
Color:
The 1sec / 10sec difference unfortunately appears in the release version...
I tried to find out more with different profiler tools but they all pointed to WealthLab.Position.get_entryBar() and a possible thread synchronization bottleneck:
http://img818.imageshack.us/img818/5161/pofile2.jpg
Size:
Color:
Please disregard my advice on experementing with the profiler, I haven't seen your code at that point which on the surface appears OK (haven't compiled it though). Try downloading the sample project's source code from the
Home - MS123.PosSizers page (attachment): it's a watered down version of the library that works.
It may take time to find out what's wrong with your setup, because it's not becoming evident from the information already available. If there's a "synchronization bottleneck", then it certainly can't be caused by applying a PosSizer. Either you're comparing the built-in PosSizer running on 500 bars (or 1 symbol) with custom PosSizer running on 10,000 bars (or 1000 symbols), or there's something else to it in your workflow not apparent from your posts.
So I'd appreciate if you could take a look at questions in my reply dated 11/7/2012 1:20 PM. Fixing the working solution may be a shortcut. Thanks.
Size:
Color:
I think I forgot to mention that I've already tried to fix this with the OpenSource MS123.PosSizer. Just to proof it for this reply
a) I did a clean WealthLab install
b) I downloaded the PosSizer source code and changed the necesarry values 'TargetFramework 2.0 -> 4.0' and the Folder 'WL v5 -> WL v6', compiled a release version.
c) Run a simple 'SMA in/out' strategy with the build-in '10% Max Risk' PosSizer, then with the 'Random non-basic' PosSizer.
I always get the same result: Build-In PosSizer takes something between 750 and 1250 ms, the 'external one' 9000 - 11000ms. My intention was to use the included MS123.PosSizer to check if it's up to my code...
Size:
Color:
It's not the code, it's something specific to your system and/or the way the DLLs are compiled.
1. Does MS123 PosSizers work equally fast (on par with the built-in PosSizers)?
2. Which version of Visual Studio are you using to compile your DLLs?
3. How are you starting Wealth-Lab, by clicking on its shortcut or from Visual Studio?
4. Does the Wealth-Lab's main folder contain any other custom DLLs (i.e. developed by you or 3rd party and not downloaded from the Extensions section of our site)?
Size:
Color:
1) That's what I tried, the build-in PosSizers run a strategy in 850ms, a MS123PosSizer (any of them already included) take 9-11 seconds.
2) VisualStudio 2012 without any extensions
3) I'm starting WealthLab with it's shortcut
4) There are some DLL's installed by the following extensions:
- ASCII Files Static (which I dont need but without I couldnt get DatabaseProvider to work)
- Database Provider
- Yahoo
Size:
Color:
Did I understand correctly: you have ran a backtest with "Percent of Equity", and then applied a MS123 PosSizer or your own PosSizer, and this step takes 11 seconds?
For the record, what kind of data are these 850ms coming from? Data provider, data loading range, whatever else you feel is applicable.
Size:
Color:
Another DLL which I compiled and normally use with the same setup is the Community.Commissions without any problems. At the moment this DLL is abandoned to maintain a clean installation...
Size:
Color:
My WealthLab Testing Setup:
BarScale: 1minute
DataRange: about 6 months
Bars: 107660
DataProvider: Static SQL DB
Position Sizers with their Execution TimesPortfolio Sim Mode
Starting Capital: 10000
-
Fixed Dollar: 1000€ -> 839ms
Shares/Contracts: 1000 -> 740ms
Percent of Equity: 10 -> 844ms
Max Percent Risk: 10 -> 836ms
-
Double Down /w MaxRisk 10%: -> 12308ms
Double Down /w PercentEquity 10%: -> 18014ms
Double Down /w Shares/Contracts 1000: -> 13728ms
-
Random PosSizer /w MaxRisk 10%: -> 13395ms
Random PosSizer /w PercentEquity 10%: -> 18461ms
Random PosSizer /w Shares/Contracts 1000: -> 15814ms
- the Symbol is running in Future Mode
- no Commission are applied (as described above)
- Performance Visualizer activated are 'Performance' and 'Trades'
- If I run the 'Double Down' PosSizer without 'my' DLL in the WL Folder the results are as bad as above.
- Strategy Code:
CODE:
Please log in to see this code.
Size:
Color:
Well, usually I do not run tests on hundreds of thousands bars. Indeed, here applying a PosSizer is slower than any of the built-in options (e.g. 2 vs 4 seconds or 7 vs 9 seconds). I think that having an overhead is expected.
Size:
Color:
Even if I take half of these bars the difference is still 0.5seconds vs. 5.5 seconds. But if there's nothing wrong about this behaviour or the code or at least nothing I can improve then I'll take it as given.
Thank You Eugene.
Size:
Color:
Maybe something could be done by using parallel programming in custom PosSizers (i.e. Parallel.For and/or PLINQ). Of course, when there's room for that -- alas, not in your MaxPositionSize class.
Size:
Color:
Matthias,
A couple more observations:
1. I noticed that 64-bit version appears faster on processing PosSizers than 32-bit version e.g. by 20% on Double Down.
2. 6.3 vs. 6.4 i.e. .NET 2.0/3.5 vs. .NET 4.0 - doesn't make difference wrt Double Down performance.
Size:
Color: