- ago
One way would be to construct one minute bars from 10-second bars in the 10-second strategy.
I need one day's worth of 1 minute data or 390 x 6 = 2400 10-second bars.
My current data depth is 800.
I could increase it to 2400.
But this will increase processing time.
If there is no other way can you please jot down code for generating 1-minute bars from 10-second bars? This was possible in WL6.
(by the way I have been off WL6 for quite a while, WL8 1-minute strategy generating identical results)
Thanks!
0
95
2 Replies

Reply

Bookmark

Sort
- ago
#1
Below is a small test strategy that shows how to convert 10-second bars to 1-minute bars. Note, that for testing, I have to simulate 10-second bars because I don't have any 10-second scale data.
In the code below, see method named GetOneMinuteBarsFrom10SecondBars. That is how you do it.
I have no idea what would happen in streaming mode. So, you'll want to thoroughly test.
Also, make sure your 10-second bars have their Scale property value set to 10-seconds. For example, my10SecondBars.Scale = new HistoryScale(Frequency.Second, 10);
CODE:
using System; using WealthLab.Backtest; using WealthLab.Core; namespace WealthLabStrategies.Analysis { public class ScaleSecondBars : UserStrategyBase { public override void Initialize(BarHistory bars) { // Simulate 10-second bars from the one-minute bars // You would just use your 10-second bars directly if available and not simulate them var tenSecondBars = Simulate10SecondData(bars); var synchedBars = GetOneMinuteBarsFrom10SecondBars(bars, tenSecondBars); PlotBarHistory(synchedBars, "Scaled10SecondBars"); PlotTimeSeries(synchedBars.Open, "Open", "Open", WLColor.Green); PlotTimeSeries(synchedBars.High, "High", "High", WLColor.Red); PlotTimeSeries(synchedBars.Low, "Low", "Low", WLColor.Orange); PlotTimeSeries(synchedBars.Close, "Close", "Close", WLColor.Blue); PlotTimeSeries(synchedBars.Volume, "Volume", "SynchedVolume", WLColor.Green, PlotStyle.Histogram); } /// <summary> /// Compresses 10-second bars into one-minute bars and synchronizes the result with the one-minute bars. /// This ensures the compressed bars align with the timestamps of the one-minute bars data. /// </summary> private static BarHistory GetOneMinuteBarsFrom10SecondBars(BarHistory oneMinuteBarsToSynchWith, BarHistory tenSecondBars) { // compress the 10-second bars to one-minute bars var compressedBars = BarHistoryCompressor.ToMinute(tenSecondBars, 1); // Synchronize the compressed bars with the original bars var synchedBars = BarHistorySynchronizer.Synchronize(compressedBars, oneMinuteBarsToSynchWith); return synchedBars; } public override void Execute(BarHistory bars, int idx) { } /// <summary> /// Given a BarHistory of one-minute bars, this method simulates 10-second bars. /// </summary> private BarHistory Simulate10SecondData(BarHistory oneMinuteBars) { // Create a new BarHistory for the simulated 10-second data var tenSecondBars = new BarHistory(oneMinuteBars.Symbol, new HistoryScale(Frequency.Second, 10)); const int intervalsPerMinute = 6; // Number of 10-second intervals in a minute const double intervalFraction = 1.0 / intervalsPerMinute; // Fraction for interpolation for (var barIndex = 0; barIndex < oneMinuteBars.Count; barIndex++) { var open = oneMinuteBars.Open[barIndex]; var close = oneMinuteBars.Close[barIndex]; var high = oneMinuteBars.High[barIndex]; var low = oneMinuteBars.Low[barIndex]; var volume = oneMinuteBars.Volume[barIndex]; var startTime = oneMinuteBars.DateTimes[barIndex]; var priorClose = open; // Generate 6 10-second bars for each one-minute bar for (var i = 0; i < intervalsPerMinute; i++) { var currentTime = startTime.AddSeconds(i * 10 - 50); // Interpolate open and close values var interpolatedClose = open + (close - open) * ((i + 1) * intervalFraction); var interpolatedOpen = priorClose; // Calculate high and low for the interval var interpolatedHigh = Math.Min(Math.Max(interpolatedOpen, interpolatedClose), high); var interpolatedLow = Math.Max(Math.Min(interpolatedOpen, interpolatedClose), low); // Distribute volume evenly across intervals var interpolatedVolume = volume * intervalFraction; if (currentTime.Second == 50) { interpolatedOpen = open; interpolatedClose = close; interpolatedHigh = high; interpolatedLow = low; } // Add the 10-second bar to the new BarHistory tenSecondBars.Add(currentTime, interpolatedOpen, interpolatedHigh, interpolatedLow, interpolatedClose, interpolatedVolume); priorClose = interpolatedClose; } } return tenSecondBars; } } }
0
- ago
#2
Wow! Thank you a bunch!
0

Reply

Bookmark

Sort