Margin-Factor in Wealth-Script
Author: akr
Creation Date: 5/22/2010 6:12 AM
profile picture

akr

#1
Hello,

how can I access Marginfactor in Wealth-Script?
BR,
akr
profile picture

Eugene

#2
This is not a use case, and getting the value is pretty tricky but possible. It's a part of the "PositionSize=..." config string in WealthLabConfig.txt:
CODE:
Please log in to see this code.
profile picture

akr

#3
OK, with this code I can read the value of MarginFactor, but how can I change inside my Script.
MarginFactor = 1.5;
Does not really influence the MarginFactor.

Thank you and BR,
akr
profile picture

Eugene

#4
The code is getting the Margin Factor - as indicated above.

Setting it this way is even more unsupported than getting. I don't know if setting it through SettingsManager.Set in a strategy would work, but what I know is that attempting to change this value can potentially lead to unexpected results because it will get in the way of Wealth-Lab working with its configuration file.
profile picture

akr

#5
Is it possible (how) to set the PositionSize (Percent of Equity) in Wealth-Script?
profile picture

Eugene

#6
A fixed share amount can bet set through SetShareSize - but not Percent of Equity. Theoretically, you can keep track of portfolio equity in your Strategy (using a DataSetSymbols loop), and use SetShareSize to set a computed fixed share amount. Alas, it's easier said than done.

But why would you need that? Maybe we can suggest a better way.
profile picture

akr

#7
In my Strategy, I want reduce Risk if the Vola is as high as at Moment, or if the trend gets broken,.... Normally I use a Marginfactor of 2.
So I thought I try to reduce the Marginfactor if something with the uptrend goes wrong.
Maybe it is also possible with SetShareSize?
I always have 5 Positions open, that means if the Marginfactor is set to 2, the percent of equity is 40 (if Marginfactor is 1 -> percent of equity is 20).
Do you think, is this possible with DataSetSymbols loop?
Is there a small example available?
Thank you,
akr
profile picture

Eugene

#8
Can't suggest any example of using DataSetSymbols to create a portfolio equity series, sorry.

If you're not looking for dynamically increasing/reducing the current position size with volatility/risk, then I'd suggest coding a PosSizer that would vary the position size from a normal percentage (i.e. 40%) to reduced (20%), when the volatility gets high or {insert a condition here}.
profile picture

Eugene

#9
On a second thought, I think this PosSizer is already coded:

Position Sizing with the Trend

1. In your strategy code, define a condition when reduced position size (20%) will be used - a high volatility condition, trend gets broken etc. When it's time to enter a position, use the Position.EntrySignal property to mark the entry signal somehow e.g. "normal" and "reduced".

2. In the PosSizer's GUI, check "Or use these EntrySignals..." and enter your signal names.

Note: This is going to work as expected for a system that takes only long (or only short) positions; otherwise you need to code a PosSizer.
profile picture

akr

#10
Thank you for help Eugene.
I will try it tommorow.