- ago
Does WL 7 have the equivalent of WL 6 dependent strategies capabilities (i.e., LoadStrategyFromDisk/runDonor methods)? If not, is there a way to get the equivalent functionality a different way?
0
727
Solved
14 Replies

Reply

Bookmark

Sort
- ago
#1
It wasn't part of WL6, rather a class from Community Components extension. Could you expand on why this functionality is required? For example, the main purpose it served (plotting and trading the equity curve) is now built in.
0
- ago
#2
Sure, Eugene. I hacked out the equity curve section of code as my purpose was instead to access by symbol every position generated during a backtest of symbols in a Dataset. This is so I would be able to calculate performance statistics required for %K (Kelly) calculations.

The parent program invokes the daughter strategy that runs the backtest loop. The parent strategy then accesses the cached info (using GetGlobal) to do calcuations by symbol and exports the data, by symbol, to a spreadsheet.

Below is a link to a WL 6 Forum post with the parent strategy (including final code) that you helped me with:

https://wl6.wealth-lab.com/Forum/Posts/Export-a-summary-of-performance-stats-by-symbol-programmatically-40013

Thanks,
Robert
0
- ago
#3
Robert, the new WL7 backtester works significantly different than in WL6. In particular, the methods PreExecute and PostExecute give you a chance to operate on the list of symbols that either are being processed or have been processed during this backtesting loop iteration. Please refer to "Strategy Execution" section of the QuickRef for more info:

https://www.wealth-lab.com/Support/ApiReference/UserStrategyBase
0
- ago
#4
Hi Eugene,
I read through much of the API material you referred to, and the help and QuickRef. In the V6 GetGlobal approach, I used the following code:
CODE:
            List<Position> MyClosedPositions = new List<Position>();             List<string> dupSymbols = new List<string>();             foreach (Position p in sr.Positions)             {                MyClosedPositions.Add(p);                dupSymbols.Add(p.Symbol);             }

I then deduped the symbols to have a unique list of symbols and looped for positions that matched each symbol.

1. In V7 it appears that the PostExecute / BarHistory class (at least conceptually) might perform functions of GetGlobal. I see from provided example how I can do something similar to what I did beforeby making a redundant list of all the bars symbols and deduping to a unique list. But is there a more direct way iin V7 to get a list of all the unique symbols in a backtest? Or can I bypass this step completely (see next).

2. I am not sure how to get positions, since BarHistory seems structured around daily info, not positions. There is a Position class which I assume are methods for a single position but I don't see a .Symbol method included. I also see a PositionList Positions function in the QuickRef but I can't find an example of the syntax.

3. I can't seem to find a search capability in Discussions that may help me find what I am looking for. Am I not seeing it?

What do you suggest as the best practice in V7 to extract all positions from a multisymbol backtest, and sort / filter positions by symbol so I can extract performance stats for each individual position?

Thanks,
Robert
0
- ago
#5
Perhaps you're looking for GetPositionsAllSymbols?
CODE:
using System.Linq; ... string sym = "AAPL"; var lstClosedPositionsPortfolio = GetPositionsAllSymbols().Select(p =>p.IsOpen == false && p.Symbol = sym).ToList();


P.S. The search capability is there, it's straight below "Ask a question". Probably it should be made more visible.
0
Best Answer
- ago
#6
Well, this seems very close to the mark. How could I have found this on my own, without knowing the actual name of the function? Is it listed in API section under some class?

Is there an example of this used somewhere in a program?

Does it need to be constructed within the PostExecute function? As in

CODE:
      public override void PostExecute(DateTime dt, List<BarHistory> participants)       {          string sym = "AAPL";          var lstClosedPositionsPortfolio = GetPositionsAllSymbols().Select(p => p.IsOpen == false && p.Symbol = sym).ToList();                 }


I am getting an error (when constructed as above)
QUOTE:

45: Operator '&&' cannot be applied to operands of type 'bool' and 'string'

Is this because there needs to be a declaration of variable "p" as type Position? Is there an example?
0
- ago
#7
QUOTE:
Is it listed in API section under some class?

Of course it is listed in the QuickRef (whose searchability has somewhat to be improved) and in the website section that duplicates it:
https://www.wealth-lab.com/Support/ApiReference

QUOTE:
I am getting an error (when constructed as above)

Sorry, was typing on-the-fly and missed an ampersand:

CODE:
//p.Symbol = sym p.Symbol == sym
0
Glitch8
 ( 8.38% )
- ago
#8
I still don’t see an ampersand 🤔
0
- ago
#9
Looked at the ampersand actually thinking about equality sign = 😂
0
Glitch8
 ( 8.38% )
- ago
#10
We’re all getting older 👴
0
- ago
#11
Eugene - thanks that fixed it.

With the code you provided I am not sure what is contained in the list "lstClosedPositionsPortfolio". Originally I though this might be a list of all closed position objects for string "AAPL". But now I see the list type is BOOL so I'm not sure what it contains.

I want to iterate through each position to get performance metrics, such as Profit for each AAPL position. What should I be looking at next?

Robert
0
- ago
#12
QUOTE:
With the code you provided I am not sure what is contained in the list "lstClosedPositionsPortfolio". Originally I though this might be a list of all closed position objects for string "AAPL". But now I see the list type is BOOL so I'm not sure what it contains.

I want to iterate through each position to get performance metrics, such as Profit for each AAPL position. What should I be looking at next?


Eugene,
I added the following to your code to try to see contents of list

CODE:
         string sym = "AAPL";          var lstClosedPositionsPortfolio = GetPositionsAllSymbols().Select(p => p.IsOpen == false && p.Symbol == sym).ToList();                    foreach (Position pos in lstClosedPositionsPortfolio)          {             WriteToDebugLog(pos.Profit);          }


But it throws error:
QUOTE:
32: Cannot convert type 'bool' to 'WealthLab.Backtest.Position'


I'm obviously missing something. What is an example syntax to manipulate this list to test for properties (like Position.Profit)
Robert
0
- ago
#13
My bad, give this a try:
CODE:
var lstClosedPositionsPortfolio = GetPositionsAllSymbols().Where(p => p.IsOpen == false && p.Symbol == sym).ToList();
0
- ago
#14
Much better ;)
0

Reply

Bookmark

Sort