Trade new set of stocks every month
Author: GolfPlayer
Creation Date: 2/12/2019 8:32 PM
profile picture

GolfPlayer

#1
Hi!
I want to backtest my strategy on a portfolio of, let’s say, 50 stocks. But , a quantity of tradable stocks and their names depends upon a month.

For example, in the January of 2015 I want to make trades on Apple, Google and Ford.
In the February of 2015 – Tesla, Microsoft and Intel.
In March of 2015 Apple, Ford, Intel. And etc.

So there is a special set of stocks for every month. How can I realize such trading conditions in WLD?
profile picture

Eugene

#2
Hi,
There has to be special logic in your code to handle it. Something like this:

1. Set up a .NET collection to hold your Month, List<symbols> pairs.

2. On every bar prior to make a trade, there's a simple boolean condition to evaluate:

a. Take Bars.Date[bar].Month and query your collection: is there a list of symbols for current month?
b. If it's not empty, compare current Bars.Symbol against your list of symbols. If the symbol is found it's traded, otherwise skipped.
profile picture

GolfPlayer

#3
Thanks!
Is there any axample of creating such NET collection?
profile picture

Cone

#4
If you tell me how you come up with your lists, I can probably whip up something that would be more useful for your application.

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

GolfPlayer

#5
Hi!
Cone!
Thanks for an example. It helps.
My orginal idea was to trade first 10 stocks with largest month volume from 50 stocks set. 50 stockes are unchanged. New 10 stocks set for every month.
I wanted to prepare such array in Excel, then create collection as Eugene advised.
Is it difficult to chose first ten stocks by volume for every month in a strategy code?
profile picture

Eugene

#6
Looks like the idea you've expressed now shapes up as a symbol rotation system. So the plan is to roll into Top-10 stocks with the highest monthly volume in a fixed DataSet that contains 50 stocks. Rebalance monthly on the 1st. Is my understanding correct?

P.S. Forget Excel. Wealth-Lab can do so much more.
profile picture

GolfPlayer

#7
Eugene!
Yes, you are right about rotation system.

I hope some day I’ll be able to do all I want in WLD. But I’m not so good in C# as I wish to be.

profile picture

Eugene

#8
Sergey,

Here's a sample Strategy that rebalances every month. You can easily change the criteria from monthly volume to monthly turnover.

Prerequisites:
1. Community Components v2018.12 or greater must be installed
2. In the Editor, click "References" button, check System.Core, click OK.

Check it out on Daily data and let me know if there's any issue (I tested on Dow 30, 500 bars of EOD data):

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

GolfPlayer

#9
Eugene, Thank you!
profile picture

Eugene

#10
Always a pleasure.
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).