- ago
Hi,
I tried running a daily live strategy on tradier at a specific time so I can watch everything. I gave it a dataset with the one symbol but the logs keep saying:

9/23/2024 16:28:00: Status = Processing
9/23/2024 16:28:00: Pass 1 - Requesting updates for 1 symbols...
9/23/2024 16:28:01: Pass 1 - UpdateHistories returned 0 symbols
9/23/2024 16:28:11: Pass 2 - Requesting updates for 1 symbols...
9/23/2024 16:28:11: Pass 2 - UpdateHistories returned 0 symbols
9/23/2024 16:28:21: Pass 3 - Requesting updates for 1 symbols...
9/23/2024 16:28:21: Pass 3 - UpdateHistories returned 0 symbols
...
9/23/2024 16:33:05: Pass 31 - UpdateHistories returned 0 symbols
9/23/2024 16:33:05: NextRun set to 9/24/2024 16:28
9/23/2024 16:33:05: Status = Incomplete
9/23/2024 16:33:05: No Updates for 1 Symbol: AOA

What causes this?
0
169
Solved
13 Replies

Reply

Bookmark

Sort
Glitch8
 ( 11.38% )
- ago
#1
You’re running it before the market close?
0
- ago
#2
yes. instead of the default time of 7pm im setting the time to something something close to "now" during market hours so i can see the orders its placing etc.

Hmm... by your question, i assume i'm going to learn something about daily market data? It only exists after market close for the day?
0
Cone8
 ( 6.74% )
- ago
#3
Correct. A Daily bar is available after the session closes. In general, you cannot run strategies on partial bars. If you need to run a Strategy more frequently, then you need to use smaller (intraday) intervals, and adapt the strategy to that.
0
- ago
#4
OK thanks. Im going to ask a few more questions but in separate threads. They are all towards the same goal but they are different questions.
0
- ago
#5
So... i'm trying to run a daily strategy with strategy monitor and stage the trades. Now, i'm running it after the close. I set the run time to be a few minutes from now. Like, if its 9:30pm ET, i set it to 9:31pm ET. It runs. But im still getting the "UpdateHistories returned 0 symbols" message and no trades are places.

What is the correct way to run a daily strategy using the strategy monitor, on the complete bar of the current day?

QUOTE:

9/25/2024 21:34:01: Status = Processing
9/25/2024 21:34:01: Pass 1 - Requesting updates for 2 symbols...
9/25/2024 21:34:01: Pass 1 - UpdateHistories returned 0 symbols
9/25/2024 21:34:02: Ran Strategy on BNDW,VT: 0 Signals, Run Time=570ms
9/25/2024 21:34:02: NextRun set to 9/26/2024 21:34
9/25/2024 21:34:02: Status = Completed
9/25/2024 21:34:02: Processed all Symbols
0
- ago
#6
QUOTE:
Like, if its 9:30pm ET, i set it to 9:31pm ET.

This is a really bad idea because the exchange will make updates and corrections throughout the night. I wouldn't run an update until early next morning maybe two hours before the market opens; otherwise, your strategy will be making decisions on data with errors.
0
Cone8
 ( 6.74% )
- ago
#7
Bad idea or not, it should still work if you have a Historical Provider checked that is capable of returning a Daily bar as soon as the session closes.

Which Historical Providers do you have checked?
This shows that It's not returning any data >> UpdateHistories returned 0 symbols
0
- ago
#8
OK, learned a few more things. Made a little more progress. Still not totally working yet though...

1. Yesterday, when I switched to using the alpaca broker, i didnt create a new dataset linked to alpaca. I have now done that, creating two alpaca datasets, one for each strategy im running.
2. I had not used the historical data providers screen before. I used it today. I moved alapca up to the top. I configured it with my prod API keys. I updated the historical data and scheduled data to update nightly at 12:05am.
3. I associated the strategys with their respective alpca datasets in the strategy monitor.

Now, when I run the strategys (by setting the next run time to be the next minute), they runs and something happens.

I have two strategies... both use the same code, with the exception of the assets and weights. One "works" and the other doesn't. Though in reality, they both might not be working.

My benchmark strategy gets 10% of the account value and allocates 100% of that to one asset. Here's the log. Things to note... it's now using alpaca, whereas before it was using Q-data. It says "UpdateHistories returned 0 symbols" but it did produce a buy signal (as it should have).

QUOTE:

9/26/2024 06:40:29: Status = LoadingData
9/26/2024 06:40:29: Start Polling Thread
9/26/2024 06:40:29: Populating Data
9/26/2024 06:40:29: Calling GetHistories Pass 1
9/26/2024 06:40:29: GetHistories returned with 1 symbols
9/26/2024 06:40:29: Calling GetHistories Pass 2
9/26/2024 06:40:29: GetHistories returned with 1 symbols
9/26/2024 06:40:29: AOA:500 bars to 20240925 0000|Alpaca
9/26/2024 06:40:29: NextRun set to 9/26/2024 06:41
9/26/2024 06:40:29: Status = Idle
9/26/2024 06:41:01: Status = Processing
9/26/2024 06:41:01: Pass 1 - Requesting updates for 1 symbols...
9/26/2024 06:41:01: Pass 1 - UpdateHistories returned 0 symbols
9/26/2024 06:41:02: Ran Strategy on AOA: 1 Signals, Run Time=623ms
9/26/2024 06:41:02: NextRun set to 9/27/2024 06:41
9/26/2024 06:41:02: Status = Completed
9/26/2024 06:41:02: Processed all Symbols


My replica strategy is the same code, and also gets 10% of the account equity. It allocates 79% to one asset and 20% to another. Here are the logs. It too now correctly uses alpaca for the data. It also says "UpdateHistories returned 0 symbols". It also correctly generated one buy signal. But it should have generated two buy signals.

QUOTE:

9/26/2024 06:40:51: Status = LoadingData
9/26/2024 06:40:51: Start Polling Thread
9/26/2024 06:40:51: Populating Data
9/26/2024 06:40:51: Calling GetHistories Pass 1
9/26/2024 06:40:51: GetHistories returned with 2 symbols
9/26/2024 06:40:51: Calling GetHistories Pass 2
9/26/2024 06:40:51: GetHistories returned with 2 symbols
9/26/2024 06:40:51: BNDW:500 bars to 20240925 0000|Alpaca
9/26/2024 06:40:51: VT:500 bars to 20240925 0000|Alpaca
9/26/2024 06:40:51: NextRun set to 9/26/2024 06:41
9/26/2024 06:40:51: Status = Idle
9/26/2024 06:41:01: Status = Processing
9/26/2024 06:41:01: Pass 1 - Requesting updates for 2 symbols...
9/26/2024 06:41:01: Pass 1 - UpdateHistories returned 0 symbols
9/26/2024 06:41:02: Ran Strategy on BNDW,VT: 1 Signals, Run Time=625ms
9/26/2024 06:41:02: NextRun set to 9/27/2024 06:41
9/26/2024 06:41:02: Status = Completed
9/26/2024 06:41:02: Processed all Symbols


My questions:
1. I was expecting to see UpdateHistories returned 1 symbols (or 2 for the replica strategy). Why are histories not being returned?
2. I was surprised to see any buy signals since no updated histories were returned. How is that possible?
3. I was surprised that the replica strategy only bought one asset... if the logic and data was working enough to buy one asset, it should have bought two. What's up with that?
4. The data manager says i have to keep the window open for scheduled downloads... can i keep it minimized or does it have to be actually open?
5. Debugging this is hard. How can i write output to the strategy monitor status log. I tried "WriteToStatusBar" but that didn't work.

Ive included the code for the replica strategy here. The code for the benchmark is the same except for the weight changes in BacktestBegin.

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; using System.Linq; namespace WealthScript4 {    public class MyGlobalEightyTwentyReplica : UserStrategyBase    {       static Dictionary<string, double> _weights = new();       public override void BacktestBegin()       {          //add allocations for each of your symbols. The DataSet must contain these symbols          _weights["VT"] = 79;          _weights["BNDW"] = 20;       }       //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 (!_weights.ContainsKey(bars.Symbol))             return;          if (ExecutionMode == StrategyExecutionMode.StrategyMonitor)          {             if (idx == bars.Count - 1 || bars.DateTimes[idx].IsLastTradingDayOfMonth(bars))             {                RebalanceLive(bars);             }          }          else          {             if (idx == 0 || bars.DateTimes[idx].IsLastTradingDayOfMonth(bars))             {                WriteToStatusBar($"Rebalancing {bars.Symbol} at {bars.DateTimes[idx].ToShortDateString()}");                Rebalance(bars, _weights[bars.Symbol]);             }          }       }       public Transaction RebalanceLive(BarHistory bars)       {          Transaction trade = null;          BrokerAccount brokerAccount = Backtester.LiveAccount;          if (brokerAccount == null)             return null;          // the amount set for % of equity          //double pctEquity = Backtester.Strategy.PositionSize.Amount / 100.0;          double pctEquity = 0.10;          double qtyNeeded = Math.Floor(_weights[bars.Symbol] / 100d * brokerAccount.AccountValue * pctEquity / bars.LastValue);          double qtyBroker = 0;          //find the shares if a position for bars.Symbol exists          foreach (BrokerPosition bp in brokerAccount.Positions)          {             if (bp.Symbol == bars.Symbol)             {                qtyBroker = bp.Quantity;                break;             }          }          if (qtyBroker > qtyNeeded)          {             //sell shares             trade = PlaceTrade(bars, TransactionType.Sell, OrderType.Market, 0, "RebalanceLive");             trade.Quantity = qtyBroker - qtyNeeded;          }          else if (qtyBroker < qtyNeeded)          {             // buy shares             trade = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, "RebalanceLive");             trade.Quantity = qtyNeeded - qtyBroker;          }          return trade;       }    } }
0
Cone8
 ( 6.74% )
- ago
#9
You need to pay attention to the schedule.
Next Run tells you when the next run is scheduled in your time zone.

1. What time zone are you in?
2. Is Live Positions enabled? (doesn't matter in this case)
3. Is your account holding any of the positions?
(If a position's quantity doesn't have to be changed, there will be no signals.)
0
- ago
#10
Heya.

1. Im in US eastern time. And im able to get it to run exactly when i want.
2. Yes "use live positions" is enabled.
3. Im using a fresh paper alpaca account with no positions and $100,000.
0
- ago
#11
OK, i found something... I removed the bit where I multiply by pctEquity. So now the calculation is:

CODE:
double qtyNeeded = Math.Floor(_weights[bars.Symbol] / 100d * brokerAccount.AccountValue / bars.LastValue);

When I run this, i now get signals for both positions. Sweet. It was a math problem.

But something else is going on... i think it's using the default "fixed" value of $5000 in brokerAccount.AccountValue. But I can't tell cause I can't print anything out!

I really wish there was a way for me to debug these values... how can i write logs from runs that happen in the strategy monitor?

Also, still seeing "Pass 1 - UpdateHistories returned 0 symbols" but im clearly getting data and generating signals. Maybe that's a red herring.
0
Cone8
 ( 6.74% )
- ago
#12
You have the full power of .NET to create logs any way that you want... but you can easily add a statement like this for a log in the Log Viewer (Ctrl+L) -

CODE:
WLHost.Instance.AddLogItem(Backtester.Strategy.Name, "Your message here", WLColor.Green);
1
Cone8
 ( 6.74% )
- ago
#13
QUOTE:
1. ... Why are histories not being returned?

Look at the log closely. It's getting histories and even telling you the last date and the source. (e.g., 9/26/2024 06:40:51: BNDW:500 bars to 20240925 0000|Alpaca). Then it schedules a run for 9/26/2024 06:41.

QUOTE:
2. I was surprised to see any buy signals since no updated histories were returned. How is that possible?
It didn't return (append) any new bars because it loaded all the data that was available. It ran the strategy because the data was up-to-date (the 9/26 market had not opened yet), therefore it can return signals.

QUOTE:
3. I was surprised ... working enough to buy one asset, it should have bought two.

One reason is because the shares were already the correct number. But clearly you've manipulated the code from what you posted, because the strategy shouldn't have called RebalanceLive() since it was not the end of the month yet. Monday 9/30 will be the last day, after the market closes.

QUOTE:
4. can i keep it minimized or does it have to be actually open?

Minimized is open too. However, you do not need to schedule updates at all, and especially not for Daily data. WealthLab will request the data whenever it needs it.

5...
Answered above
0
Best Answer

Reply

Bookmark

Sort