- ago
The QR for the new Rebalance() function states:

QUOTE:
Issues a buy or sell, as appropriate, to cause the symbol specified in bars to allocate a percentage of the current backtest equity specified in percentOfEquity.


If Preferences > Trading > Portfolio Sync > "Use Broker-reported Account Value for % of Equity Position Size" box is checked, will Rebalance() use the Broker-reported equity instead of the backtest equity to calculate position sizes for signals including automated trading?
0
307
6 Replies

Reply

Bookmark

Sort
Cone8
 ( 25.44% )
- ago
#1
No, it will not. Just as you highlighted in the quote from the QuickRef, it works with backtest equity only.

If you want to use a strategy for this this purpose, you could save a Rebalance strategy with the live account equity and run it from that date - it should be stay in sync as long as the strategy mimics your actions in the live account.
0
- ago
#2
How would I get access to live account equity to do that programmatically? Or are you suggesting a manual process to fetch that data?
0
Cone8
 ( 25.44% )
- ago
#3
You'd start by voting for this feature request in the topic starter -
https://www.wealth-lab.com/Discussion/Access-Accounts-data-from-broker-programmatically-7914

But yes, I'm suggesting that you just look at your account today, create a strategy that enters the Positions you have, and enter the starting equity. Everything should line up with the signals after that.

Here's the strategy.
1. Enter the symbols and shares in the arrays at the bottom.
2. Enter the starting date for _startBar in Initialize.
3. Enter the equity of your account on that date.
4. Run this the script on 1 symbol only from at least a day before your starting date.

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript123 { public class Rebalancer : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          StartIndex = 1;          _startBar = bars.DateTimes.IndexOf(new DateTime(2022, 9, 27)); } //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 (idx == _startBar - 1)          {             for (int n = 0; n < _symbols.Length; n++)             {                // buy the shares at the close                      BarHistory xbars = GetHistory(bars, _symbols[n]);                Transaction t = PlaceTrade(xbars, TransactionType.Buy, OrderType.MarketClose);                t.Quantity = _shares[n];                            }          }          else if (idx > _startBar)          {             if (bars.DateTimes[idx].Month != bars.DateTimes[idx - 1].Month)             {                //rebalance every month                for (int n = 0; n < _symbols.Length; n++)                {                   BarHistory xbars = GetHistory(bars, _symbols[n]);                   Rebalance(xbars, 100.0 / _symbols.Length );                }             }          } }       int _startBar;       string[] _symbols = { "AAPL", "MSFT", "PG" };       int[] _shares = { 100, 90, 120 }; } }


0
- ago
#4
QUOTE:
You'd start by voting for this feature request in the topic starter

Haha. I can only vote once. I'm the one who started the Feature Request.

Thanks for the strategy code! If the feature request is completed, does the code you provided become unnecessary or should it be modified?
0
- ago
#5
QUOTE:
If the feature request is completed, does the code you provided become unnecessary or should it be modified?

It's too early to tell, the feature (let alone its implementation) is not decided yet. 🤷‍♂️
1
- ago
#6
Makes sense. Thanks.
0

Reply

Bookmark

Sort