Where put code to run exactly once for every trade (after position sizing)?
Author: skalman99
Creation Date: 3/12/2012 7:42 AM
profile picture

skalman99

#1
I need to export information about trades to csv-files. My current idea is to export the trades by looping over the results.Positions list in the following method:

public PerformanceEngine(SystemPerformance perf, SystemResults results)


But, this seems to be called 3 times... (I'm geussing that's once for Long, once for Short, and then once for all trades.)

Where is the correct place to place code to be executed exactly once for every trade?

Regards Jon Brewer
profile picture

Eugene

#2
Actually, it's called four times: once for all trades, one run for Long and one fot Short, and finally goes Buy & Hold.

You need to make sure you're working with SystemPerformance.Results (1st run):
CODE:
Please log in to see this code.

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

skalman99

#3
The method public PerformanceEngine(SystemPerformance perf, SystemResults results) is called 4 times. So if I log all the trades in perf.Results.Positions each trade is written 4 times to the log. Where should my "Utilities.LogTradeToFile(loginfo, pos);" call go? So that it won't be called 4 times?


Inside the "public PerformanceEngine(SystemPerformance perf, SystemResults results)" method does not seem to be the right place?


Below is code which causes each trade to be logged 4 times:

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

Eugene

#4
Perhaps I did not express myself well. By design, the code will be called 4 times. You can not do anything about it. Your job is to adjust the LogTradeToFile method accordingly. As I already suggested, do your logging during the first run, and just skip the other mandatory three runs. A simple counter might work.
profile picture

sedelstein

#5
I am curious about this too.

In the article http://www2.wealth-lab.com/WL5WIKI/kbInteractingWithPortfolioEquity.ashx
There is some code that refers to the first run. Is this what you are getting at?
Where would the test go to see if you were no longer in the first part of the run? (or in the example code above)

It seems like it's obvious to you but not to me or skalman99.
Can you provide a little more help? Muito obrigado.



profile picture

Eugene

#6
skalman99 and you are talking talking about different things. The concept being discussed in this thread - the visualizer execution cycle - happens after the Strategy has already finished executing and position sizing has been applied. Consequently, this article is of no help in this context.
profile picture

Eugene

#7
QUOTE:
It seems like it's obvious to you but not to me or skalman99.

What exactly is not obvious about this part?
QUOTE:
As I already suggested, do your logging during the first run, and just skip the other mandatory three runs. A simple counter might work.
profile picture

skalman99

#8
Hi Eugene,

I put a counter in the Position.Tag property to prevent a trade from being logged to file more than once. This works fine for running over one chart, or running over a dataset, but does not seem to work at all during an exhaustive optimisation.

During an exhaustive optimisation, nothing is logged at all. The same script with the same settings in the Data Panel will write trades to file when running over a dataset, but not while doing an optimisation. Why is this?

I use the File.AppendAllText method to write to the file.

Regards Jon
profile picture

Eugene

#9
Hi Jon,

Probably you've missed my point. The idea of a counter is to put it inside your visualizer, to enable your logging for the 1st run (Results) and to switch off during the next three runs (ResultsBuyHold, ResultsLong, and ResultsShort).

My tip didn't have anything to do with optimizers (as you never mentioned them), as well as I didn't suggest modifying the Strategy code. Furthermore, as optimization suddenly came on stage: logging in during an optimization run only makes sense from an Optimizer class, and is useless in a script (no position sizing).
profile picture

skalman99

#10
Eugene,

I'm being unclear. The counter is inside my visualizer and so is the code to log the trades to file. But this code is never called during an optimization run. So, as you suggest, I need to create a custom optimizer that includes the code for logging?

And I can find documentation for creating Optimizer class on WIKI?


Regards Jon
profile picture

skalman99

#11
Eugene,

Found this

http://personal.fidelity.com/products/trading/Trading_Platforms_Tools/pdf/Creating-Optimizers-in-Wealth-Lab-Pro.pdf
profile picture

skalman99

#12
Eugene,

Is the Exhaustive optimizer open source? This is the one I need to modify.

Regards Jon Brewer
profile picture

Eugene

#13
QUOTE:
I'm being unclear. The counter is inside my visualizer and so is the code to log the trades to file. But this code is never called during an optimization run.

That's right. Visualizers are not processed during optimization runs. As well as certain methods of the WealthScript namespace which fall into the "cosmetic" category.
QUOTE:
So, as you suggest, I need to create a custom optimizer that includes the code for logging?

Yes, I did.
QUOTE:
Is the Exhaustive optimizer open source? This is the one I need to modify.

No, it's not. But have a look at the first post in this thread:

Creating custom optimizer
profile picture

Eugene

#14
Important note to the users of the PerformanceEngine class (internal, unsupported part of the MS123 Visualizers library):

The information regarding PerformanceEngine calling conventions provided across the forum before is actual as of the library version 2012.05.1 and earlier. In future versions, the syntax will most likely undergo a breaking change due to a complete rewrite of the PerformanceEngine class.
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).