I try to add some common functionality to a trading strategy. As an example let me compose a daily soup:
(This is OneNight with daily soup)
Because I want to use the very same mechanism in several strategies I move it to a common base class called UserStrartegyWithSoup like so:
I think this is technically correct but it does not even compile in WL8. I get this exception:
How can I compose my daily soup?
CODE:
using System; using System.Collections.Generic; using WealthLab.Backtest; using WealthLab.Core; namespace WealthScript4 { public class MyStrategy : UserStrategyBase { public override void PreExecute(DateTime dt, List<BarHistory> participants) { dailySoup = 0.0; // Init Daily Soup } public override void Execute(BarHistory bars, int idx) { double percentage = 2.0; foreach (var pos in OpenPositions) ClosePosition(pos, OrderType.Market); double limit = bars.Close[idx] * (1.0 - percentage / 100.0); Transaction tr = PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, limit); dailySoup += limit; // Collect Daily Soup } public override void PostExecute(DateTime dt, List<BarHistory> participants) { // Finish Daily Soup WLHost.Instance.AddLogItem(StrategyName, "Daily soup: " + dailySoup.ToString("f2"), WLColor.Blue); } private double dailySoup; } }
(This is OneNight with daily soup)
Because I want to use the very same mechanism in several strategies I move it to a common base class called UserStrartegyWithSoup like so:
CODE:
using System; using System.Collections.Generic; using WealthLab.Backtest; using WealthLab.Core; namespace WealthScript3 { // intermeddiate base class with soup public abstract class UserStrategyWithSoup : UserStrategyBase { public override void PreExecute(DateTime dt, List<BarHistory> participants) { dailySoup = 0.0; // Init Daily Soup } public override abstract void Execute(BarHistory bars, int idx); public override void PostExecute(DateTime dt, List<BarHistory> participants) { // Finish Daily Soup WLHost.Instance.AddLogItem(StrategyName, "Daily soup: " + dailySoup.ToString("f2"), WLColor.Blue); } protected double dailySoup; } public class MyStrategy : UserStrategyWithSoup { public override void Execute(BarHistory bars, int idx) { double percentage = 2.0; foreach (var pos in OpenPositions) ClosePosition(pos, OrderType.Market); double limit = bars.Close[idx] * (1.0 - percentage / 100.0); Transaction tr = PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, limit); dailySoup += limit; // Collect Daily Soup } } }
I think this is technically correct but it does not even compile in WL8. I get this exception:
CODE:
System.NullReferenceException: Object reference not set to an instance of an object. at System.Object.GetType() at WealthLab8.designerCode.Compile() at WealthLab8.designerCode.RevertDescriptor(Object ident, RoutedEventArgs vis) ...
How can I compose my daily soup?
Rename
The daily soup is just a silly example of course, but it illustrates the road block.
The real thing would be a ranking mechanism for the Bensdorp strategies.
The real thing would be a ranking mechanism for the Bensdorp strategies.
WL8 doesn't support inheritance in this way, you could create a utility class library that you could call from various strategies to achieve something similar.
...like the good old WL.Community:
https://github.com/Mkey85/WeathLab.Community
https://github.com/Mkey85/WeathLab.Community
QUOTE:
WL8 doesn't support inheritance in this way
This is a pity!
I can't see how I can hide away the PreExecute()/PostExecute() boilerplate code with a helper class....
Just code up a method in your utility class that you can call from Pre/PostExecute.
Your Response
Post
Edit Post
Login is required