Position management for portfolio strategies

Posted By: MegaTanker

Position management for portfolio strategies - 08/27/21 12:34

Hello,
I have calculated weights for a number of assets in a portfolio strategy, but I can't find any good instructions in the manual how to properly "execute" those weights.

I have used other platforms that had a function that lets you set a weight for an asset and the platform will then execute trades (long or short) until this weight is reached (based on account balance).

I haven't found such thing for Zorro. Alternatively I could calculate the new amount of lots myself (I have found the assign and distribute functions) and compare it with the current lots to find out if I need to buy or sell or do nothing. But how do I see how many open positions the account has for an asset? Only thing I found in the manual is a for(open_trade) loop where I would have to check every loop if the current trade corresponds to the asset I want to check with TradeAsset. That seems suboptimal.

Is there a better way to automatically reach weights or is there a better way to check the current open position (if any) for an asset? Currently for testing I simply close all positions when it's time to reassign and then just create the new ones in full but that creates unnecessary commission/spread when lots stay the same or nearly the same.
Posted By: Lapsa

Re: Position management for portfolio strategies - 08/27/21 14:27

Quote

But how do I see how many open positions the account has for an asset?


NumOpenLong
NumOpenShort
NumOpenTotal

I do remember something written along the lines of managing portfolio strategies on the manual.

One topic was Markowitz optimization. Might be what you need or perhaps - lead to something else that's useful.
Posted By: MegaTanker

Re: Position management for portfolio strategies - 08/27/21 18:00

Thank you for the quick reply. Those variables look like they should solve the problem but I have noticed that they do not store the number of open lots, only the number of open trades. So if I buy 25 shares of one asset, NumOpenLong is now 1 instead of 25. After another buy of 25, NumOpenLong is 2. So it only returns the number of actual trades and doesn't account for the size of the trades.

Now that I know that it keeps track of open positions in Trades, I have found something that seems to work: for(current_trades) loops over the open trades of the current asset and I can sum up the TradeLots of each trade.
Posted By: Spirit

Re: Position management for portfolio strategies - 08/28/21 11:01

Open lots and all other variables are on this page: https://manual.zorro-project.com/winloss.htm . Look for "LotsPool".
Posted By: MegaTanker

Re: Position management for portfolio strategies - 08/28/21 17:40

Thanks, don't know how I missed that when I was looking at NumOpenLong.
Posted By: qin

Re: Position management for portfolio strategies - 01/27/23 02:25

I run the demo Workshop4, and print out LotsPool at every bar, it is always zero. Why? It seems it's not open positions we are holding.
what I want is a way to check the current open position (if any) for an asset.
Posted By: qin

Re: Position management for portfolio strategies - 01/31/23 07:24

My fault, LotsPool is correct. previously I print with %f, it should be %d
© 2024 lite-C Forums