Pyramiding and closing of positions in portfolio simulation
Author: Gamba
Creation Date: 3/10/2012 12:57 PM
profile picture

Gamba

#1
Hi,

I tried to make additional entries for a symbol during a portfolio simulation.
Am I right that I have to make a completely new entry? Since a simulation
calculates first with only 1 share I am not able to add additional share ... I guess ...

Additonal entries seems to work, so I tried to exit all additional positions
when the first position of a symbol generates an exit:

CODE:
Please log in to see this code.


But that changes the main position list and it generates errors, that the ordering
of this list is wrong ...

What is the best way to accomplish this?

Thx
Gamba
profile picture

Eugene

#2
Have you tried starting with the basics?

WealthScript Techniques | Pyramiding (Adding to position)
profile picture

Gamba

#3
Eugene, of course, but I want to use it in portfolio simulation, woth multiple symbols.
If I understand it right the code is only for one symbol, because using of
AllPositions will close all my portfolio positions.

Would you pleas answer my questions, that would be point me in the right direction.

Thx
Gamba
profile picture

Cone

#4
QUOTE:
But that changes the main position list and it generates errors
You can't use a foreach loop to exit (i.e. remove) a position from the ActivePositions list. Instead, use this design pattern:

CODE:
Please log in to see this code.
profile picture

Gamba

#5
In addition I have to ask in the main loop if there are further active positions.
After that it seems to work.

CODE:
Please log in to see this code.


So, let's get back to my iniial questions:

1.) I tried to make additional entries for a symbol during a portfolio simulation.
Am I right that I have to make a completely new entry and can not simply add some shares?

2.) The now working exit for all positions of one symboi in a portfolio simulation:
Is this a known technique are there any other best practices for a portfolio?
Or in worst case: Are there any known side effects ...

Thx
Gamba

profile picture

Eugene

#6
1) Yes, absolutely.
2) Maybe Position.AllPositions?
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).