Synchronize
public static TimeSeries Synchronize( TimeSeries source, TimeSeriesBase master, double? prefillNans = null, MarketDetails market = null, bool performScaleUpShift = false)Synchronizes the source TimeSeries with the DateTimes of master and returns a new TimeSeries.
The returned TimeSeries has the same DateTimes and Count as master.
For each master DateTime, WealthLab uses the most recent source value that is available as of that point in time.
If either source or master is null or contains no values, an empty TimeSeries is returned.
prefillNans
If the master begins before the first available source value, the synchronized TimeSeries initially contains Double.NaN values.
If prefillNans is supplied, those initial Double.NaN values are replaced with the specified value.
For example:
TimeSeries synced = TimeSeriesSynchronizer.Synchronize(
source,
bars,
0.0);
This fills any leading values before the first available source value with zero. market The optional market parameter supplies MarketDetails used when synchronizing data across scales, particularly daily-or-higher data to intraday data. If master is a BarHistory and market is null, WealthLab automatically uses the BarHistory's Market. If no MarketDetails are available when synchronizing daily-or-higher data to intraday data, WealthLab attempts to determine the market close time from the master series itself. Market information is particularly important for markets whose trading sessions cross midnight. performScaleUpShift Set performScaleUpShift to true when synchronizing from a less granular non-intraday scale to a more granular non-intraday scale and the source value should not become available until the following master period. Examples include:
- Monthly to Daily
- Quarterly to Daily
- Yearly to Monthly When enabled, WealthLab shifts the synchronized values by one master bar where necessary to prevent a completed higher-scale value from becoming available before that period has actually completed. The default value is false. TimeSeriesSynchronizer accounts for differences between the source and master scales. When synchronizing daily-or-higher data to intraday data, WealthLab aligns the source DateTimes with the appropriate market session before performing the synchronization. It also examines the final master bar to determine whether the current source period has actually completed. If the period is still incomplete, the previous completed source value is retained rather than exposing the current incomplete-period value. The returned TimeSeries retains the Description of the source TimeSeries.
using WealthLab.Backtest;
using WealthLab.Core;
using WealthLab.Indicators;
namespace WealthLab
{
public class MyStrategy : UserStrategyBase
{
private TimeSeries _weeklyRSI;
public override void Initialize(BarHistory bars)
{
//compress closing prices to weekly scale
TimeSeries weeklyClose =
TimeSeriesCompressor.ToWeekly(bars.Close);
//calculate RSI using weekly data
RSI rsiWeekly = RSI.Series(weeklyClose, 4);
//synchronize the weekly indicator back to the chart scale
_weeklyRSI =
TimeSeriesSynchronizer.Synchronize(rsiWeekly, bars);
PlotTimeSeries(
_weeklyRSI,
"RSI(4-week)",
"RSI",
WLColor.Blue);
}
public override void Execute(BarHistory bars, int idx)
{
}
}
}