Portfolio Trading

Posted By: Zheka

Portfolio Trading - 12/27/17 12:45

Hi, JCL,

Merry Christmas and a Happy and prosperous coming New Year!

Would greatly appreciate your advice/clarification on the following:

1. What design pattern would you recommend for trading a portfolio of systems different mostly in parameters used?
e.g. 5x Sys1 x asset1 + 3x Sys1 x asset2 + 1x Sys1 x asset3 + 4x Sys2 x asset1 + 2x Sys3x Asset3...etc

Looping through Assets and Algo as described in the manual does not seem to fit elegantly with the problem -as one would have to name Algos differently for each parameter permutation ...

2. Do I understand correctly that algo names can be generated dynamically in the script (e.g. asset+algo+TimeFrame+Nr)?

3. There is mention of the "Component" variable in the manual. How is it enumerated and would typically be used?

4. At what point does Zorro calculate "Net"/Pool trade quantities per asset (when using Hedge) and actually sends orders to the Broker? Is it at the end of a run() function?

5. Can one have 2 or 3 asset/algo loops within run()?

6. If multiple Zorro instances are used with same algo names - will all saved Vars and files used be instance-specific and SaveStatus/LoadStatus be managed by Zorro correctly?

7. Would it be possible to enlarge the internal array of ResultsLong/Short from 20 to 50 last trades, and add one for ResultsTotal?

Thank you!
Posted By: jcl

Re: Portfolio Trading - 12/28/17 12:10

Thanks, a good new year to your too. I did not understand the design pattern question, but as to the rest, algo names can be generated dynamically, but need not contain the asset since that's already in the Asset name. "Component" is used for the model number in a machine learning algo. Pool trades are sent at the end of the run function and when a position changes intrabar. You can have many asset/algo loops, but only 2 nested, and the number of assets and algos must not change between loops. Multiple instances of the same script will not be managed correctly, so rename the script for running it in several instances. You can store any number of trade results in a non-shifted series.
Posted By: Zheka

Re: Portfolio Trading - 12/28/17 13:12

Thank you, JCL.

As for "design pattern" q: if a Portfolio consists of
- 5 parameter variations of Algo1 on Asset1, +
- 3 param var of Algo 1 on Asset 2, +
- 2 x (p v) of Algo 2 on Asset 3, +
-.....etc

then the suggested Asset/Algo nested loop will most probably not be an elegant/efficient solution - as one would have to create 5+3+2+...differently named algos, each one only applicable to a small subset in a big loop..

Another way would be to just loop through algos from 1..n and read params (incl. Asset and TF) from a file corresponding to the algo number. (Or do this per Zorro instance trading one asset).

How would you do this?

Thank you.
E.
Posted By: MatPed

Re: Portfolio Trading - 12/28/17 14:35

Hi Zheka,
variations of the same algo on different assets are different algos and you are trading 5+3+2+... different strategies. It is as it is.

There are several coding options to handle specifics differences between assets (market hours, with a CASE ... as an example), but a strategy trading from 9 to 5 is not the same that the same algo trading 24h. Differentiate with different algo- names or not is up to you.

Ciao
Posted By: Zheka

Re: Portfolio Trading - 01/12/18 12:47

JCL,
To size positions in a portfolio of algos (which implement equity curve trading), I first wanted to poll all algos for their On/Off status and then re-allocate capital/size accordingly.

With this I hit several problems:
1)
Quote:
You can have many asset/algo loops, but only 2 nested, and the number of assets and algos must not change between loops.

I found that 2 Algo (only) loops do not work: the program just doesnt get into the second one (printf from the second loop does not print anything)

2) Alternatively, I tried to have one algo loop working in phantom mode to generate trades, and then change TradeLots of just opened trades in a for(open_trades) loop. Did not work because TradeLots appears to be read-only.

How can I achieve what I need?

Thanks a lot in advance for your advice.
Posted By: jcl

Re: Portfolio Trading - 01/12/18 13:28

Put your algo names in a string array:

string Algos[10];
int N=0;
while(algo(loop("name1","Name2",...))) {
Algos[N++] = Algo;
...
}

Then you can later go through all your algos with a simple for loop:

for(i=0; i<N; i++) {
algo(Algos[i]);
...
}

You can not edit the lot number of an open trade. When you buy an asset, you must already know how many lots you want to buy.
Posted By: Zheka

Re: Portfolio Trading - 01/12/18 17:03

Yes, thank you, I just got it working dynamically generating algo names in a for loop.

Moving to Equity Curve Trading:

- do I understand right that Balance- and EquityLong/Short is updated every bar/frame and so taking a moving average of it is not accurate - because a MA will be catching up with Equity during flat periods?
Posted By: Zheka

Re: Portfolio Trading - 01/17/18 13:10

bump
Posted By: jcl

Re: Portfolio Trading - 01/17/18 13:53

Yes, when you trade, your equity and balance can change at any bar, and when you do not trade, they are flat. So will be their MA (I hope). How different MA types work is described on many websites.
Posted By: Zheka

Re: Portfolio Trading - 01/17/18 15:25

Quote:
when you do not trade, they are flat.So will be their MA (I hope)
An MA will continue changing,irrespective of the MA type. And after MA-length bars with no trades will be equal to Balance.

The correct mechanism requires creating/maintaining a separate array of equity@trade, not equity@bar.
And I thought this might be an enhancement to implement in one of the future versions.
Posted By: jcl

Re: Portfolio Trading - 01/17/18 15:41

For a per-trade SMA, sum up the last 20 results from the Results array, and divide by 20.
Posted By: Zheka

Re: Portfolio Trading - 01/17/18 15:50

Results array is unfortunately available only as ResultsLong/Short separately.

Or is there another way to access it for all trades of asset/algo component?
Posted By: jcl

Re: Portfolio Trading - 01/17/18 15:57

Sum up ResultLong/Short and divide by 40?
Posted By: Zheka

Re: Portfolio Trading - 01/17/18 16:03

The sequence of trades must be known to sum the correct e.g. 30 trades from ResultsLong/Short.
Posted By: jcl

Re: Portfolio Trading - 01/17/18 16:31

Then store the result of any trade in a series.
Posted By: Brax

Re: Portfolio Trading - 01/18/18 16:34

Hi Zheka.

I'd like to suggest you to try out rolling expectancy ratio rather than averages for equity curve trading:

https://www.financemagnates.com/forex/bloggers/equity-curve-trading-part-2-rolling-expectancy-ratio/

Another thing i am currently using is setting a maximum percent drawdown instead of averages. I just run a test and determine maximum possible drawdown according to Montecarlo analysis to set this.

For example, if i don't want any strategy to lose more than 10%, i set this cap and adjust lot sizes so Montecarlo drawdowns kind of adjust to this limit.

This way i get a disaster proof mechanism without interfering too much in the dynamics of the strategy, because sometimes when we go phantom trading is just when the comeback starts and we lose that opportunity to recover.

Just my two cents.
Posted By: Zheka

Re: Portfolio Trading - 01/18/18 16:51

Thanks, brax!

I am actually using both the expectancy and eq.curve trading, and take care of drawdowns through position sizing and diversification.
© 2024 lite-C Forums