Don't sell if priority would result in an immediate repurchase
Author: Panache
Creation Date: 12/7/2010 7:53 AM
profile picture

Panache

#1
I wrote a simple strategy to rebalance my mutual fund portfolio on the 15th day of every month (or the next trading day). Instead of selling everything at the end of the month and buying back many of the same funds the next day, is there a way to allow the Portfolio Simulation Mode to not sell funds that would be repurchased the next day?

The reason it makes a difference is that many funds have restrictions against short term trading. Therefore, when the strategy exits a position (and does not immediately repurchase it), it should wait two more months before it buys that fund again. I tried working around the problem by adding "|| bar - exitBar < 2". However, with that line of code, the Portfolio Simulation appears to completely ignore the line of code above it which prevents excessive trading.

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

Eugene

#2
If you know that you're going to purchase some funds tomorrow, there's a boolean condition. Why not check it right before exiting? This design seems logical to me.
profile picture

Panache

#3
Perhaps I'm missing something, but I'm not basing the decision to hold (repurchase) a symbol based on some condition which can be determined from the data for a single symbol. I am giving priority to the symbols in my watch list with the greatest percentage change. Therefore, it isn't possible to know which has the greatest percentage change until all the symbols in the watch list have been evaluated. I assume this is essentially what Wealth Lab does when it performs a Portfolio Simulation.

My problem is that I don't know how to back test a strategy like this. I thought about using GetExternalSymbol to go through each of the other symbols in my watch list, but I suspect I would quickly run out of memory. My best idea for a work around is to have another script to write the percentage change data to a file and then access the file in this script. If you have any better ideas, they would be very much appreciated.
profile picture

Eugene

#4
Your code doesn't look readable/working to me and seems like re-inventing the wheel already known as symbol rotation. Have you checked the RSI Rotation strategy that comes with WLP6?

I guess it would be optimal to:

1. Take the RSI rotation as the basis for your strategy
2. Adjust it for the 5-day ROC series by following this FAQ: I need other rotation rule other than the built-in RSI.
3. Add your exit condition(s)

As long as your stock(s) has the highest ROC, the position will stay open.
profile picture

Cone

#5
You just have to reverse the entry condition and condition the exit logic with it. Well, here's a shot with some cleanup.
CODE:
Please log in to see this code.
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).