Keeping Track of Positions Before First Trade Date
Author: Panache
Creation Date: 7/4/2017 2:35 PM
profile picture

Panache

#1
As always, I'm trying to do something differently from the way most people do it.

I want to give my Strategies time to "settle down" before the first trade, to get a better idea of how they would actually have performed during the relevant period. For example, my Strategy will hold 10 positions created by buying on a SMA cross-over and selling on a SMA cross-under. I want to keep track of the trades that would have been made during 2010 - 2012, buy the positions that would have been held on the last trading day of 2012 and then analyze the Strategy's performance by buying and selling during the period 2013 -2016. I can do that within the Strategy by creating a "shadow" list of positions and looping through the entire DataSet day by day, but that becomes computationally expensive in an Optimization.

My first thought was to create a custom Performance Visualizer which would allow me to select a custom Period, ie. 2013-2016. However, I don't believe that is going to help me in my Optimizations, because the Net Profit in the Optimizations is going to be based on the period 2010-2016, not just 2013-2016.

I could also create a custom Optimization Scorecard to solve that problem, but I think I would have to hard code the dates in, and those dates need to be able to be easily changed to allow for different Optimization periods.

Therefore, I'm thinking about trying to do it within a PosSizer. The problem I see with doing it in a PosSizer is that I believe the PosSizer is called for each candidate position. If so, I can't think of any way to create my "shadow" list of the positions that would have been created during 2010-2012, except by writing it to a file, which would be very slow.

One possible solution might be to write directly to the Position Object and give each candidate position a size of zero prior to 2013. Is that possible? If so, where can I find out what actually needs to be written to the Position Object? I assume many of the items shown in the QuickRef as being returned by the Position Object are calculated values and aren't actually stored in it.

Finally, if you have a better idea, I'd love to hear it.
profile picture

Eugene

#2
QUOTE:
except by writing it to a file, which would be very slow.

Probably as a slightly faster altenative to the file, might class-level variables do the job?

Access positions before PosSizer is running
profile picture

Panache

#3
Maybe. I can use a class level list to hold the "shadow" list of positions, but how do I turn that list into candidates on the last trading day of 2012? Specifically, is there a way for a PosSizer to create candidates that aren't passed to it?
profile picture

Eugene

#4
I don't think it's possible to influence the Candidates list directly but if you find a way, please let the forum know.
profile picture

Panache

#5
I can work around that problem by having my Strategy generate a Buy signal for every symbol on the last trading day of 2012 and using a tag to designated it as a fake signal. That gives my PosSizer all the candidates it needs.

However, I just realized that Sell signals don't get passed to the PosSizer, correct? Therefore, the PosSizer never knows when a Sell signal has been generated, so it has no way to know when symbols should be removed from my "shadow" list of positions.

I thought I could work around that problem by letting all the trades get written to Positions and then using Positions.RemoveAt[] to delete the trades prior to 2013, but I get an error message saying I can't use Positions.RemoveAt[]. Is it possible to override that?
profile picture

Eugene

#6
QUOTE:
However, I just realized that Sell signals don't get passed to the PosSizer, correct?

Correct. PosSizers are used only for sizing the new Positions.

QUOTE:
Is it possible to override that?

I don't think that there's a workaround enabling you to modify the Positions list.
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).