Table of Contents

Class SeriesBase<T>

Namespace
Balsam
Assembly
Balsam.Backtester.dll

An abstract base class that implements basic functionality common to all timeseries.

[ProtoContract(IgnoreListHandling = true)]
[ProtoInclude(10, typeof(TimeSeries))]
[ProtoInclude(11, typeof(BooleanSeries))]
[ProtoInclude(12, typeof(IntegerSeries))]
public abstract class SeriesBase<T> : ISeries, IEnumerable<T>, IEnumerable, ICloneable

Type Parameters

T
Inheritance
SeriesBase<T>
Implements
Derived
Inherited Members
Extension Methods

Constructors

SeriesBase()

Initializes a new empty series.

protected SeriesBase()

SeriesBase(IEnumerable<DateTime>)

Initializes a new series with the specified dat es.

protected SeriesBase(IEnumerable<DateTime> dates)

Parameters

dates IEnumerable<DateTime>

SeriesBase(IEnumerable<DateTime>, IEnumerable<T>)

Initializes a new series.

protected SeriesBase(IEnumerable<DateTime> dates, IEnumerable<T> values)

Parameters

dates IEnumerable<DateTime>
values IEnumerable<T>

SeriesBase(IEnumerable<DateTime>, T)

Initializes a new series with the specified dates and value.

protected SeriesBase(IEnumerable<DateTime> dates, T value)

Parameters

dates IEnumerable<DateTime>
value T

SeriesBase(int)

Initializes a new empty series with the specified capacity.

protected SeriesBase(int capacity)

Parameters

capacity int

Fields

WarnOnOperatorRelativeIndexing

Prints a warning to the Console if operator overloads are called when using relative indexing.

public static bool WarnOnOperatorRelativeIndexing

Field Value

bool

Properties

Count

Gets the number of observations in the series.

public int Count { get; }

Property Value

int

CurrentDate

Gets the current date if concurrency is being maintained, otherwise returns DateTime.MinValue.

public DateTime CurrentDate { get; }

Property Value

DateTime

Dates

Gets the dates for the series.

public DateSeries Dates { get; }

Property Value

DateSeries

FirstDate

Gets the first date on which valid data is available.

public DateTime FirstDate { get; }

Property Value

DateTime

Index

Gets the current index;

public int Index { get; }

Property Value

int

Indexing

Gets the indexing strategy being used.

public IndexKind Indexing { get; }

Property Value

IndexKind

IsActive

Returns true if concurrency is being maintained and the CurrentDate is greater than or equal to the FirstDate.

public bool IsActive { get; }

Property Value

bool

this[DateTime]

Gets/sets an observation based on the specified date. This ignores any Indexing setting and always accesses the absolute date.

public virtual T this[DateTime date] { get; set; }

Parameters

date DateTime

Property Value

T

this[int]

Gets/sets an observation based on the specified index.

public virtual T this[int index] { get; set; }

Parameters

index int

Property Value

T

this[TimeSpan]

Gets an observation based on a time span offset relative to the current bar.

public virtual T this[TimeSpan timeSpan] { get; }

Parameters

timeSpan TimeSpan

Property Value

T

Last

Gets the last available value based on the current indexing strategy.

public T Last { get; }

Property Value

T

LastDate

Gets the last available date of the series.

public DateTime LastDate { get; }

Property Value

DateTime

MaxBarsBack

Gets/sets the starting index where the data is first be considered valid. For example, given zero-based indexing, a 10 day moving average would have a MaxBarsBack of 9 (i.e. data from 0 to 9 need to calculate the first value.).

public int MaxBarsBack { get; set; }

Property Value

int

Name

Gets/sets the name.

public string Name { get; set; }

Property Value

string

Previous

Gets the previous value if current bar > 0 otherwise returns the penultimate value.

public T Previous { get; }

Property Value

T

Symbol

Gets/sets the symbol.

public string Symbol { get; set; }

Property Value

string

Tag

Gets/sets a convenience field for the user to store any arbitrary object or identifying information.

public object Tag { get; set; }

Property Value

object

Methods

Add(DateTime, T)

Adds a new paired date/value to the end of the collection.

public void Add(DateTime date, T value)

Parameters

date DateTime
value T

AdjustDates(Func<DateTime, DateTime>)

Applies a function to all dates in the series, transforming them in place.

public void AdjustDates(Func<DateTime, DateTime> func)

Parameters

func Func<DateTime, DateTime>

CheckIndexing(params SeriesBase<T>[])

Used for operator overloads to check that they are called with absolute indexing.

protected static void CheckIndexing(params SeriesBase<T>[] series)

Parameters

series SeriesBase<T>[]

Clear()

Clears all data from the series.

public void Clear()

CopyTo(int, T[], int, int)

Copies a range of elements from the internal list to the specified array.

public void CopyTo(int index, T[] array, int arrayIndex, int count)

Parameters

index int
array T[]
arrayIndex int
count int

CopyTo(T[])

Copies the internal list to the specified array.

public void CopyTo(T[] array)

Parameters

array T[]

CopyTo(T[], int)

Copies the internal list of the specified array starting at the specified index of the target array.

public void CopyTo(T[] array, int arrayIndex)

Parameters

array T[]
arrayIndex int

ExportToFileCore(StreamWriter, string, bool)

The core file export logic.

protected virtual void ExportToFileCore(StreamWriter sw, string delimiter = ",", bool includeHeader = false)

Parameters

sw StreamWriter
delimiter string
includeHeader bool

GetEnumerator()

Returns an enumerator to iterate through all the values in the series.

public IEnumerator<T> GetEnumerator()

Returns

IEnumerator<T>

Insert(DateTime, T)

Inserts the specified date and value.

public void Insert(DateTime date, T item)

Parameters

date DateTime
item T

Merge(SeriesBase<T>)

Merges the specified series into the existing one, ignoring any duplicates.

public void Merge(SeriesBase<T> series)

Parameters

series SeriesBase<T>

Merge(SeriesBase<T>, bool)

Merges the specified series into the existing one.

public void Merge(SeriesBase<T> series, bool overwrite)

Parameters

series SeriesBase<T>

The series to merge.

overwrite bool

When true, data is updated for duplicate dates; otherwise, duplicates are ignored.

MergeCore(SeriesBase<T>, bool)

Merges the specified series into the current one.

protected void MergeCore(SeriesBase<T> series, bool overwrite)

Parameters

series SeriesBase<T>
overwrite bool

OnAdd(DateTime, T)

Adds the specified values to the internal lists.

protected virtual void OnAdd(DateTime date, T value)

Parameters

date DateTime
value T

OnClear()

Clears the series back to initial empty state.

protected virtual void OnClear()

OnClone()

Returns a clone of this series.

protected virtual SeriesBase<T> OnClone()

Returns

SeriesBase<T>

OnDatesChanged()

Called when dates are modified or changed after having been added to the collection.

protected virtual void OnDatesChanged()

OnGetValue(int)

Returns the value of the specified index.

protected T OnGetValue(int index)

Parameters

index int

Returns

T

OnInsert(int, DateTime, T)

Inserts the specified date/item pair at the specified index.

protected virtual void OnInsert(int index, DateTime date, T item)

Parameters

index int
date DateTime
item T

OnRemove(int)

Removes an observation at the specified index.

protected virtual void OnRemove(int index)

Parameters

index int

OnSetIndex(DateTime)

Sets the current bar based on the specified date.

protected virtual int OnSetIndex(DateTime date)

Parameters

date DateTime

Returns

int

OnSetIndex(int)

Sets the index to the specified value.

protected virtual void OnSetIndex(int index)

Parameters

index int

OnSetValue(int, T)

Sets the index to the specified value.

protected virtual void OnSetValue(int index, T value)

Parameters

index int
value T

OnTrim()

Removes observations prior to MaxBarsBack.

protected virtual void OnTrim()

Remove(DateTime)

Removes a paired date/observation at the specified date.

public bool Remove(DateTime date)

Parameters

date DateTime

Returns

bool

Remove(int)

Removes a paired date/observation at the specified index.

public void Remove(int index)

Parameters

index int

RemoveNonTradingDays()

Removes any observations that fall on a weekend.

public void RemoveNonTradingDays()

Save(string)

Saves the series to a comma delimited file using the specified filename.

public void Save(string fileName)

Parameters

fileName string

SubsetCore(DateTime, DateTime)

Returns a subset of a series. MaxBarsBack of the returned series is adjusted as necessary.

protected SeriesBase<T> SubsetCore(DateTime startDate, DateTime endDate)

Parameters

startDate DateTime
endDate DateTime

Returns

SeriesBase<T>

SubsetCore(int, int)

Returns a subset of a series starting at the specified index and returning the specified number of observations. MaxBarsBack is adjusted as necessary.

protected SeriesBase<T> SubsetCore(int index, int count)

Parameters

index int
count int

Returns

SeriesBase<T>

Exceptions

ArgumentOutOfRangeException

SyncCore(IEnumerable<DateTime>, SyncOption)

Returns a new series synced to the specified dates.

protected virtual SeriesBase<T> SyncCore(IEnumerable<DateTime> dates, SyncOption option)

Parameters

dates IEnumerable<DateTime>
option SyncOption

Returns

SeriesBase<T>

ToDictionary()

Returns a dictionary of values with date as key, starting at MaxBarsBack.

public Dictionary<DateTime, T> ToDictionary()

Returns

Dictionary<DateTime, T>

ToString()

Returns a string representation of this series.

public override string ToString()

Returns

string

Trim()

Removes all observations prior to MaxBarsBack.

public void Trim()

Trim(T)

Replaces all values prior to MaxBarsBack with specified value and sets MaxBarsBack to zero.

public void Trim(T value)

Parameters

value T