Loop over DataSet and store results in global memory before running a Portfolio simulation?
Author: Carova
Creation Date: 12/31/2018 3:53 PM
profile picture

Carova

#1
Hi!

I am looking to loop over a DataSet (similar to a rotation strategy) and store the results in a Global series before running through a standard Portfolio simulation. Here is my code start:

CODE:
Please log in to see this code.


What do I need to do further? Is this correct?

Thanks!
Vince
profile picture

Eugene

#2
profile picture

Carova

#3
Hi Eugene!

That code does a portion of the job but does not store the series in Global for future access.

Here is the resultant code with that addition:

CODE:
Please log in to see this code.


Is this correct now?

Vince
profile picture

Eugene

#4
Hmm, the same Description assigned to two DataSeries looks suspicious.
profile picture

Carova

#5
Good catch Eugene! Thanks!

HNY!!

Vince
profile picture

Eugene

#6
Happy New Year to you too!
profile picture

Carova

#7
Hi Eugene!

There seems to be an issue with my code

CODE:
Please log in to see this code.


When I run it against 20 years of Daily bars of the Dow 30 I get the attached errors messages. Is there an issue with synchronization?

Vince
profile picture

Eugene

#8
Wouldn't using the "Above SMA" IndexDefinition be more straightforward than coding it?
profile picture

Carova

#9
Yes, if that was what I planned to do. The code is just an example. I have a more complex concept in mind.

profile picture

Eugene

#10
Anyway, ran your code once and it didn't throw an exception.
profile picture

Carova

#11
Found that with 20 years of data the errors do not occur consistently but with 30 years they do. AAPL, the first symbol, has complete data for the period, so the "first symbol" is not the issue.

Vince
profile picture

Carova

#12
Added some more data checking, but still generates errors when tested on 30 years of Daily data for the Dow 30

CODE:
Please log in to see this code.


Any ideas?

Vince
profile picture

Eugene

#13
Here's something for you to troubleshoot. For version from post #7 the global DataSeries will be zero for the first symbol if you run a multi-symbol backtest and then click on AAPL. With the one in post #12, for all symbols.
profile picture

Carova

#14
There is something more basic at play here. If I remove the "run once" code (below) that still results in the same errors. Your suggestions are really related to that aspect.

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

Eugene

#15
With added synchronization and some unncessary code removed, this doesn't produce errors for me when run on 20 years of Dow 30 (Yahoo! data):

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

Carova

#16
Thanks Eugene! The errors are gone, but a new issue has emerged. The code stops trading after about 10 years even though the conditions for trading are met (see attached).

profile picture

Eugene

#17
It's your (unknown) DataSet so troubleshooting is on you!

Make sure that your position size is sufficient to purchase at least one share of the instrument (like higher-priced indices). See trades not taken due to insufficient funds, review the PosSizer settings etc.
profile picture

Carova

#18
Hi Eugene!

I checked my dataset and it appears that it does work correctly for Daily Scale on the Dow 30 but the problem seems to be when it is run on a Weekly scale. See attached. These were run with 2% of Equity and as you can see there is always plenty of available Equity for purchase.

Vince
profile picture

Eugene

#19
Hi Vince,

Cannot reproduce. Check your position sizing settings and Wealth-Lab Preferences (trading related).
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).