Want to buy and sell a portion of portfolio
Author: flroots
Creation Date: 6/25/2014 5:28 PM
profile picture

flroots

#1
At the start of each quarter I may wish to re-balance the portfolio. Initially I wish to purchase one stock and one bond ETF such that I have a 70% stock and 30% bond allocation with the total equal to $10K. First, how do I make the initial buy order for each ETF in the above ratio and second, how do I create the subsequent buy and sell orders for some fraction of the total account such as 10%? The strategy allows for the possibility of sequential buys or sells of ether ETF. BTW, I will be paper trading and I don't know if that changes anything. Thanks
profile picture

Eugene

#2
As I've just answered this same question, see reply #5 here:

Bar number must be 6 or greater
profile picture

flroots

#3
Thanks Eugene. I see that's a very similar situation. I also am working with multiple symbols (ie, 2) and wish to be able to hold multiple positions of each. The part I'm having problems with is specifying the correct symbol when selling. For example,I'm pretty sure this code segment is not finding the correct p corresponding to the bndsym symbol:

CODE:
Please log in to see this code.


Here is the entire loop I'm working with:
CODE:
Please log in to see this code.
profile picture

Eugene

#4
QUOTE:
For example,I'm pretty sure this code segment is not finding the correct p corresponding to the bndsym symbol:

This code fragment simply sells the last active position. SetContext is useless with regard to exiting positions, in general. What will have success is looping through the ActivePositions (just not from inside a foreach loop), querying the Position.Symbol property, and matching it with your "bndsym". See example in reply #4:

Pyramiding and closing of positions in portfolio simulation
profile picture

flroots

#5
Thanks. This seems to work. Can you tell me what the problem is with the 'foreach'?

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

Eugene

#6
It "seems" to work because your condition doesn't trigger. The "problem" is that in C# it's not possible to modify the collection you're looping through using foreach. If you give this broken code a (good) try, the compiler will halt it eventually.

Also, you forgot to remove the unnecessary SetContext call.

Finally, it's not a good idea to pass anything greater than "bar" or "bar+1" i.e. startbar+30 is incorrect. To issue a time-based exit order, follow this design pattern:

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

flroots

#7
Thanks Eugene. I've modified the code as shown below. My strategy requires me to select which symbol to sell and it may or may not be the last position. I don't see that happening with your code example above? The startbar+30 was just a debugging artifact. As you see, I've removed the SetContext since as you say it's no necessary.

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

Eugene

#8
Please use CODE tags for posting code snippets, not QUOTE. (I've edited your replies three times). "Code" is on the left from "Quote".

QUOTE:
I don't see that happening with your code example above?

My code above only illustrates a time-based exit order.

QUOTE:
I've modified the code as shown below.

It's up to you to stick to that foreach loop, ignoring my suggestions and explanations. Since you were presented with an example (see link in post #4), my work here is done.
profile picture

flroots

#9
Thanks again Eugene. I am happy to abandon the foreach loop, but I haven't figured out from your examples how to make it work in my situation where I need to sell a particular symbol which may or may not be the last position?

On a related subject, when I purchased two ETFs on 4/11/2007 I got the following results:
VTI 138 shares at 71.655 = $9888.39
BND 132 shares at 75.04 = $9905.28

What determines how many shares make up a given position? Can that be controlled? As a stopgap, I initially purchase 7 positions of VTI and 3 positions of BND to approximate the 70/30 stock/bond ratio. My logic can then change allocation to 80/20, 90/10, 100/0 or back to 70/30 depending on the triggers.
profile picture

Eugene

#10
QUOTE:
What determines how many shares make up a given position?

Position sizing.

QUOTE:
Can that be controlled?

Wealth-Lab User Guide > Reference > Data Panel > Position Size Control.

QUOTE:
As a stopgap, I initially purchase 7 positions of VTI and 3 positions of BND to approximate the 70/30 stock/bond ratio. My logic can then change allocation to 80/20, 90/10, 100/0 or back to 70/30 depending on the triggers.

This seems to be already known from your post #1 so please consider reviewing the link in my reply #2 for a thorough explanation.
profile picture

flroots

#11
Thanks again. I hope you forgive my relative ignorance. It's only my 2nd or 3rd day using Wealth-Lab. I have been reviewing SetShareSize. As near as I can tell, I can purchase the desired equity by calculating SetShareSize based upon dividing the desired equity by the share price to calculate shares. I'm still trying to figure out the implications of this quote:
QUOTE:
In Raw Profit modes, SetShareSize does not have effect. It applies to Portfolio Simulation mode only.
profile picture

Eugene

#12
QUOTE:
I'm still trying to figure out the implications of this quote:

Make sure you've selected the "WealthScript Override" option for SetShareSize to take effect.


QUOTE:
I am happy to abandon the foreach loop, but I haven't figured out from your examples how to make it work in my situation where I need to sell a particular symbol which may or may not be the last position?

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

flroots

#13
Wow, never in a million years would I have figured that out! It works great. Thanks
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).