- ago
I’d like to use a metastrategy to buy and hold a set of symbols with a quarterly rebalance.

I have a buy & hold building block strategy (just the buy at market block without the sell) and I was thinking I could put an iteration of this building block strategy into the Meta, having one for each symbol. However, when I run the metastrategy there is always a large amount of cash not being invested.

The building block strategy invests 100% of equity, but the metastrategy does not.

Any idea on what I’m doing wrong?

Thanks!
0
372
Solved
2 Replies

Reply

Bookmark

Sort
Glitch8
 ( 11.87% )
- ago
#1
The MetaStrategy rebalance only reallocates the strategy buying powers, it doesn't issue any buys or sells to rebalance a strategy itself.

Here's a C# Strategy that is a buy & hold that will rebalance every quarter. Just assign a Percent of Equity Position Size that's appropriate for the number of symbols in the DataSet. For example, for 3 symbol 33.333% and for 10 symbols 10%.

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript4 { public class MyStrategy : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) { }       //execute the strategy rules here, this is executed once for each bar in the backtest history       public override void Execute(BarHistory bars, int idx)       {          if (!HasOpenPosition(bars, PositionType.Long))             PlaceTrade(bars, TransactionType.Buy, OrderType.Market);          else          {             //rebalance on first day of quarter             DateTime dt = bars.DateTimes[idx];             DateTime tomorrow = dt.AddDays(1);             if (dt.Month != tomorrow.Month)             {                int mn = tomorrow.Month;                if (mn == 1 || mn == 4 || mn == 7 || mn == 10)                {                   PlaceTrade(bars, TransactionType.Sell, OrderType.Market);                   PlaceTrade(bars, TransactionType.Buy, OrderType.Market);                }             }          }       } } }
0
Best Answer
- ago
#2
Thank you glitch. I appreciate the help!
0

Reply

Bookmark

Sort