I can't figure out how to properly use percent equity in portfolio testing

Hi, I’m trying to do some portfolio testing using different asset allocations. For example, I’d like to do a portfolio test that purchases 20% TLT, 60% MDY, and 20% GLD on January 1,2000 and hold it until September 1, 2017. This is what I have so far, which obviously doesn’t work. I’m not sure how to best incorporate the setpositionsize statement. Should I use a regular if statement? If so, how?

Thanks for any help!

//3 fund allocations

SetPositionSize(IIf(Name() =="GLD",20,0),spsPercentOfEquity);
SetPositionSize(IIf(Name() =="TLT",20,0),spsPercentOfEquity);


Disregard, I figured it out!

@TonyR I’m glad you figured it out, but you may need to consider that GLD was not listed until Nov 2004. So you can’t back test it from Jan 2000 (and TLT sometime in July 2002 I believe).

Also I assume you read up on your mistaken date numbers,

And lastly, are you not re-balancing at all over the whole period (~12 years from GLD listing)?

Yes, that was ONE of the issues, I did eventually get it to work. I like your username, I have a feeling I’m going to be asking you for a lot of help as I begin to develop asset allocation strategies. I’m working on doing quarterly/monthly rebalances as well, however what metric to use for the position score is the million dollar question, isn’t it.
Thanks for the reply and the useful hints! Appreciate it!

1 Like

First if you “figured it out” it would be nice for others to present your solution since some other person may have similar trouble.

Secondly, avoid calling same functions multiple times (this is general advice). So call, Name() and SetPositionSize() just once:

n = Name();
ps = 20; // default pos size
if( n == "MDY" ) ps = 60;
SetPositionSize( ps, spsPercentOfEquity );

if you had more different sizes you could use multiple if’s

n = Name();
if( n == "MDY" ) ps = 55;
if( n == "GLD" ) ps = 25;
ps = 20;

SetPositionSize( ps, spsPercentOfEquity );

or you could use switch statement

switch( Name() )
   case "MDY": ps = 55;
   case "GLD": ps = 25;
   default:    ps = 20;

SetPositionSize( ps, spsPercentOfEquity );


Thank you Tomasz, I ended up using nested iif statements with each of my instruments I needed, but yours was far more eloquent as I expected. Thank you very much for the solution! Truly a great program with great support!
Kindest Regards,