Clarification of Portfolio Trading Order Management  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
QGroup

Clarification of Portfolio Trading Order Management

Postby QGroup » 04 Dec 2014

I appreciate the implementation of the portfolio trader, but having difficulties finding answers to my questions due to the lack of documentation.

My main problem is how to flatten an order via the portfolio trader. Consider your programming example "Portfolio_Rank_MM", where we i.e have 20 assets and want to be long the top 5 ranks and short the bottom 5 ranks. Without using profit targets or stoploss, it will result in more than 5 long and 5 short positions since positions are only reversed and never flattened. I need to use the buytocover and sell order types in the MM somehow, but I have no control over them from the MM if I send them over from the strategy hence the positions will always be flat. I can use the method "ForceClosePosition" but this closes the position with a market order - how can I use limit orders to flatten or partially close positions via the MM strategy?

Furthermore, I believe the this.StrategiesInShort and this.StrategiesInLong method is supposed to access which assets that currently holds short and long positions? The referenced list that is returned is always either filled with only short or longs - it doesn't reflect the open position at all (ie when I have 3 long and 3 short positions, the "inShortStrategies" contains all 6 positions while "inLongStrategies" are empty). This is by using the example code you've provided. Have I misunderstood this method? The documentation has no information at all regarding this.

I'm using the latest version of MC.Net 9.0 (updated today).

Is there any additional documentation for the programming part of the Portfolio Trader other than the help class and the pdf file for MC9.0?

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Clarification of Portfolio Trading Order Management

Postby Henry MultiСharts » 08 Dec 2014

Hello QGroup,

Money Management signals do not generate/send any orders themselves. They just control what individual signals are doing.
Portfolio_Rank strategy is a rotational strategy. You need to modify it's source code and the code of the Portfolio_Rank_MM to make it function the way you need it.

We are currently analyzing the behavior you have with the this.StrategiesInShort and this.StrategiesInLong methods. I will keep you updated.

QGroup

Re: Clarification of Portfolio Trading Order Management

Postby QGroup » 08 Dec 2014

Thank you Henry,

"Money Management signals do not generate/send any orders themselves."
I know that - the orders are generated in the main strategy, and then either let through or inactivated in the MM. This isn't the issue though as I explain in the message, the problem is how to close a position with a limit order:

Consider the Rank strategy, where the decision whether an asset shall be boughht or sold is made in the MM part. The main strategy always sends a buy and sellshort order, which the MM then allows/inactivated based on the rank in relation to all other assets. If the strategy idea is to always be long 3 assets, short 3 assets and we have a total of 10 assets, that means 4 assets will be flat at any time. Since the decision is made in the MM, and let's say we're currently long one asset, we can't just send a sell order through since the MM might wan't the order to be reversed rather than just closed. This is the dilemma, that the MM doesn't seem to have a feature to distinguish between sellshort and sell orders.

Due to the lack of documentation I can only make conclusions based on the example code available for this.

The work-around I have for now is to trade large orders (ie 10000), and then have the MM set the trade size to a single share when the position should be flat which means the backtesting result will be similar to a flat position. This way I can use the buy/sellshort orders only in the development phase, but this is obviously not suitable for real trading...

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Clarification of Portfolio Trading Order Management

Postby Henry MultiСharts » 09 Dec 2014

MM doesn't need to distinguish between sellshort and sell orders. It distinguishes between entries and exits.
You need to modify the source code of the Portfolio_Rank strategy strategy. It should be able to manage entries and exits to achieve what you need, instead of doing reverse which is the default example.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Clarification of Portfolio Trading Order Management

Postby Henry MultiСharts » 09 Dec 2014

Furthermore, I believe the this.StrategiesInShort and this.StrategiesInLong method is supposed to access which assets that currently holds short and long positions? The referenced list that is returned is always either filled with only short or longs - it doesn't reflect the open position at all (ie when I have 3 long and 3 short positions, the "inShortStrategies" contains all 6 positions while "inLongStrategies" are empty).
This issue has been confirmed. The fix is targeted to MultiCharts .NET 9.0 Release 5

QGroup

Re: Clarification of Portfolio Trading Order Management

Postby QGroup » 11 Dec 2014

MM doesn't need to distinguish between sellshort and sell orders. It distinguishes between entries and exits.
This is the problem, it DOES need to distinguish and be available from the MM. Since we only have access to allow/decline Long entries and Short entries in the MM from the PortfolioStrategies[ID].AllowEntriesLong/Short we can't control partial exits of an order.

In the case of an Rotation or Ranking strategy we can't decide in the signal whether a position shall be closed or not, since the decision is dependent on the ranking in the MM. Therefore we can't send a sell/buytocover order to close a position unless we can allow/decline it in the MM.

I've tried different work around but can't get past the limitation:
- If we always send a sell/buytocover order to the MM together with buy/sellshort orders, the position is always flat. I was hoping that the sell/buytocover order would be overridden by the buy/sellshort orders, such as if we were long it would close the position and if we were long and should stay long the net position of closing the old trade an open a new of the same size would mean the trading engine in MC didn't have to change the position, hence no order would be sent. This didn't work.
- I've tried to override the position size and set it to 0, with the intention of closing the open position but fail to open an opposite due to he zero position size, but this reverts back to the default size in the settings instead.

The only solution I've got that works reasonably well is to make the decision of a flat position in the MM, use the PortfolioData method to send the information to the signal and then check from the signal whether an exit order shall be sent. The downside is that in the backtests the order won't be registered until one bar later, which means I then need to run a much lower timeframe in the backtests while still making the decision on a higher timeframe to decrease the time delay.

Is there a better solution to this? If not, it's really important to implement access to exit orders in the MM to not impose unnecessary limitations to the portfolio trader.

How could the Portfolio Trader be used to scale out of a position? Your release notes says "Portfolio strategies can enter, scale-in, scale-out, or exit positions based on the overall portfolio performance" but I'm yet to find any documentation or solution to how to do this.

A few years ago I worked with QuantFactory or RightEdge (don't remember exactly which one of them it was), who utilized a simple but very effective method. For a portfolio trader you ran a Master signal, which in turn looped through the asset and signal combination programmatically. This way I could run calculations on each bar prior to calling the signals, and then also after calling the signals, before the orders was sent to the broker...

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Clarification of Portfolio Trading Order Management

Postby Henry MultiСharts » 12 Dec 2014

IPortfolioStrategy also has a method for closing a specific position - ForceClosePosition.

Attached is a sample code with scale-in and scale-out of position logic. It does two long entries 10 contracts each, then scales-out with 1 contract. Make sure you enable "Allow up to NNN entry orders in the same direction" in the Strategy properties->Properties tab.
Attachments
Test_Scale_In_Out.pln
(1.99 KiB) Downloaded 585 times

QGroup

Re: Clarification of Portfolio Trading Order Management

Postby QGroup » 12 Dec 2014

The ForceClosePosition as I wrote earlier only flattens the position on a market price, when the issue is how to use limit orders to flatten a position or to close a position partially from the MM. The script you attached is just for a standard strategy and not for the case of an MM and won't work in the situation I've described - the decision to close an order can not be done in the strategy part since it's the MM that has the information (ranking) to make this decision.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Clarification of Portfolio Trading Order Management

Postby Henry MultiСharts » 16 Dec 2014

QGroup,

As I have already specified - Money Management signals do not generate/send any orders themselves. If the decision is done in the Money Management signal then you need to send this decision from the MM signal to the individual signal that will place the required order.

QGroup

Re: Clarification of Portfolio Trading Order Management  [SOLVED]

Postby QGroup » 18 Dec 2014

.. and as I've already specified, that is not what I’m trying to do and I’m fully aware of it.

I don’t know how I can explain this better, but I’ll give it a last try. The objective is to use a proper portfolio module in the “Portfolio MM” strategy, by accepting/declining signals from individual strategies and to scale these according to risk once a trade is open. If we can get the example code “Rank MM” to work the way I would expect, then the real problem can be solved easily.

Problem: Use limit orders to flatten a position, or both buy/sell or sellshort/buytocover orders to scale out of a position, when the trading decision is taken in the Portfolio MM strategy.

Background: In order to make a trading decision in the Portfolio MM strategy, the orders must be generated in each individual signal strategy which can later only be accepted or declined in the Portfolio MM strategy. The limitation is that there only exist methods in the Portfolio MM to accept/decline new buy and sellshort orders, not sell and buytocover orders. Since the trading decision is made in the Portfolio MM strategy we can’t anticipate what kind of order shall be sent from the individual signal strategies, hence we need same features as for new orders (allow/disallow, set lot size) to be available for scaling out/flattening a position.

Example: Consider the example code Rank MM, where the strategy buys the top X and sells short the bottom Y assets in the ranking. Assets are only closed with a profit target or a stoploss. Now consider the case where we have more than X+Y assets (i.e 10 assets and X=3 and Y=3) and always want to hold the best/worst 3 assets meaning the 4 assets in the middle ranks will be flat. This can be achieved by the “ForceFlatPosition” method, but if we want to close the position with limit orders I don’t see any options for this. We can’t just send a sell order from the signal strategy, since the signal strategy doesn’t know the rank of the other assets hence can’t make the decision if the order shall be closed or not. If we send a sell order just because it has a position open, then we can’t decline the order if the Rank MM decides the asset is still supposed to be open. Do you see the dilemma?
A similar problem arise if we consider a constant volatility model, where each asset shall have an allocation that equals a constant variance of the portfolio variance at any time. The signal strategy doesn’t know the total variance of assets in the portfolio, hence we can’t decide in the signal strategy whether to buy, sell or do nothing to our position in that assets. We therefore need to be able to send both a buy and a sell order and control them (allow/disallow and position size) in the Portfolio MM strategy.

Question: Since the Portfolio MM strategy can’t control sell/buytocover orders, is there a workaround to achieve the desired solution?

I hope this clarifies the question for you.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Clarification of Portfolio Trading Order Management

Postby Henry MultiСharts » 18 Dec 2014

QGroup, we are going to add ability to allow/disallow exit orders in MM signal in MultiCharts .NET 9.1.

Yves BENOIT
Posts: 30
Joined: 17 Jul 2009
Has thanked: 5 times
Been thanked: 10 times

Re: Clarification of Portfolio Trading Order Management

Postby Yves BENOIT » 21 Dec 2014

Hello Henry,
This discussion was productive, since MC plans to implement these useful features (get/set position size for exit orders ).
By the way I am also waiting for Version 9.1 and its new engine.
Approximatively when do your team plan to publish the first Beta?

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Clarification of Portfolio Trading Order Management

Postby Henry MultiСharts » 22 Dec 2014

Approximatively when do your team plan to publish the first Beta?
Hello Yves,

There is no ETA for MultiCharts 9.1 beta 1 at the moment.


Return to “MultiCharts .NET”