Class SeriesCollectionBase<T>
- Namespace
- Balsam
- Assembly
- Balsam.Backtester.dll
An abstract class for collections of ISeries objects which supports access by key or index.
[ProtoContract(IgnoreListHandling = true)]
[ProtoInclude(3, typeof(TimeSeriesCollection))]
[ProtoInclude(4, typeof(BooleanSeriesCollection))]
public abstract class SeriesCollectionBase<T> : IEnumerable<T>, IEnumerable, ISeries, INotifyCollectionChanged where T : ISeries
Type Parameters
T
- An abstract class for collections of ISeries objects which supports access by key or index.
- Inheritance
-
SeriesCollectionBase<T>
- Implements
-
IEnumerable<T>
- Derived
- Inherited Members
- Extension Methods
Constructors
SeriesCollectionBase()
Initializes an empty series collection.
public SeriesCollectionBase()
SeriesCollectionBase(IEnumerable<T>)
Initializes a series collection and adds the specified series to the collection.
public SeriesCollectionBase(IEnumerable<T> series)
Parameters
series
IEnumerable<T>
SeriesCollectionBase(int)
Initializes an empty series collection with the specified capacity.
public SeriesCollectionBase(int capacity)
Parameters
capacity
int
Properties
AllowDuplicateSymbols
Allows multiple series with the same symbol to be added to the collection, otherwise an exception is thrown.
public bool AllowDuplicateSymbols { get; set; }
Property Value
Count
Gets the number of elements in the collection.
public int Count { get; }
Property Value
CurrentDate
The current date if concurrency is being maintained; otherwise DateTime.MinValue.
public DateTime CurrentDate { get; }
Property Value
FirstDate
The first date in the collection or DateTime.MinValue if the collection is empty.
public DateTime FirstDate { get; }
Property Value
HasDuplicateSymbols
Returns true if the collection has duplicate symbols. If AllowDuplicateSymbols is true, duplicate symbols will automatically be appended with a hypen and number.
public bool HasDuplicateSymbols { get; }
Property Value
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
IsReadOnly
Gets/sets whether the collection is read-only.
public bool IsReadOnly { get; protected set; }
Property Value
this[int]
Gets/sets an element by index.
public T this[int index] { get; set; }
Parameters
index
int
Property Value
- T
this[string]
Gets/sets an element by key.
public T this[string key] { get; set; }
Parameters
key
string
Property Value
- T
Key
Gets/sets the function used to determine the key for the collection. Defaults to symbol.
public Func<ISeries, string> Key { get; set; }
Property Value
LastDate
The last date in the collection or DateTime.MinValue if the collection is empty.
public DateTime LastDate { get; }
Property Value
Name
Gets/sets the name for this collection.
public string Name { get; set; }
Property Value
Symbol
Gets/sets a symbol for this collection.
public string Symbol { get; set; }
Property Value
Methods
Add(IEnumerable<T>)
Adds all the BarSeries in the specified enumerable to the collection.
public void Add(IEnumerable<T> series)
Parameters
series
IEnumerable<T>
Add(string, T)
Adds the specified BarSeries to the collection using the specifed key.
public void Add(string key, T series)
Parameters
key
stringseries
T
Add(T)
Adds the specified BarSeries to the collection using the symbol as the key.
public void Add(T series)
Parameters
series
T
Clear()
Clears the collection.
public void Clear()
Contains(T)
Determines whether the specified element is in the collection.
public bool Contains(T item)
Parameters
item
T
Returns
ContainsKey(string)
Returns true if the collection contains the specified key.
public bool ContainsKey(string key)
Parameters
key
string
Returns
GetActiveSymbols()
Returns an enumerable of symbols for which the CurrentDate is greater than or equal to FirstDate (i.e. concurrency is being maintained).
public IEnumerable<string> GetActiveSymbols()
Returns
GetEnumerator()
Returns an enumerator for iterating through the collection.
public IEnumerator<T> GetEnumerator()
Returns
- IEnumerator<T>
GetKeys()
Returns an enumerable of keys.
public IEnumerable<string> GetKeys()
Returns
OnCollectionChanged(NotifyCollectionChangedEventArgs)
Raises a NotifyCollectionChanged event.
protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
Parameters
OnGetItem(string)
Gets the item using the specified key.
protected virtual T OnGetItem(string key)
Parameters
key
string
Returns
- T
OnGetKey(T)
Returns the symbol to be used as a key. Can be overridden in derived classes to use something else.
protected virtual string OnGetKey(T series)
Parameters
series
T
Returns
OnLoad(string)
Deserialize previously saved .bin file back into a series collection.
protected static SeriesCollectionBase<T> OnLoad(string fileName)
Parameters
fileName
string
Returns
OnSave(string)
Serializes the collection to disk to allow for quick loading. File extension is .bin.
protected virtual void OnSave(string fileName)
Parameters
fileName
string
OnSetIndex(DateTime)
Sets the current bar to the specified date.
protected int OnSetIndex(DateTime date)
Parameters
date
DateTime
Returns
OnSetIndex(int)
Sets the current bar to the specified index. Currently only -1 is a valid index.
protected void OnSetIndex(int index)
Parameters
index
int
OnSync(IEnumerable<DateTime>, SyncOption)
Override this method to support syncing of collections.
protected virtual ISeries OnSync(IEnumerable<DateTime> dates, SyncOption syncOption)
Parameters
dates
IEnumerable<DateTime>syncOption
SyncOption
Returns
Remove(string)
Removes the BarSeries with the specified key from the collection.
public bool Remove(string key)
Parameters
key
string
Returns
Remove(T)
Removes the specified BarSeries from the collection.
public bool Remove(T series)
Parameters
series
T
Returns
Save(string)
Serializes the collection to disk in a .bin file for quick loading.
public void Save(string fileName)
Parameters
fileName
string
ToDictionary()
Converts the collection to a dictionary.
public Dictionary<string, T> ToDictionary()
Returns
- Dictionary<string, T>
ToString()
Returns a string representation of this collection.
public override string ToString()
Returns
Events
CollectionChanged
Raises an event when the collection is changed.
public event NotifyCollectionChangedEventHandler CollectionChanged