Table of Contents

Class ObservationSeries

Namespace
Balsam
Assembly
Balsam.Backtester.dll

Encapsulates a collection of observations. Note this does not support concurrency for backtesting via the ISeries interface like TimeSeries does.

[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class ObservationSeries : IEnumerable<Observation>, IEnumerable
Inheritance
ObservationSeries
Implements
Inherited Members
Extension Methods

Constructors

ObservationSeries()

Instantiates a new empty ObservationSeries.

public ObservationSeries()

ObservationSeries(IEnumerable<Observation>)

Instatiates a new ObservationSeries using the specified observations.

public ObservationSeries(IEnumerable<Observation> observations)

Parameters

observations IEnumerable<Observation>

Exceptions

ArgumentNullException

Properties

Count

Gets the number of items in the collection.

public int Count { get; }

Property Value

int

FirstDate

Gets the first available date.

public DateTime FirstDate { get; }

Property Value

DateTime

this[int]

Gets the observation at the specified index.

public Observation this[int index] { get; }

Parameters

index int

Property Value

Observation

LastDate

Gets the last available date.

public DateTime LastDate { get; }

Property Value

DateTime

Symbol

Gets/sets the symbol.

public string Symbol { get; set; }

Property Value

string

Methods

Add(Observation)

Adds the specified observation to the collection.

public void Add(Observation item)

Parameters

item Observation

GetEnumerator()

Returns an enumerator for iterating through the collection.

public IEnumerator<Observation> GetEnumerator()

Returns

IEnumerator<Observation>

GetFields()

Returns an enumerable of fields if a header was specified.

public IEnumerable<string> GetFields()

Returns

IEnumerable<string>

Insert(Observation)

Inserts an observation into the series.

public void Insert(Observation item)

Parameters

item Observation

Exceptions

ArgumentNullException

Load(Stream)

Loads the specified stream.

public static ObservationSeries Load(Stream stream)

Parameters

stream Stream

Returns

ObservationSeries

Exceptions

InvalidDataException
NotSupportedException

Load(string)

Loads the specified csv or json file.

public static ObservationSeries Load(string fileName)

Parameters

fileName string

Returns

ObservationSeries

Save(Stream, PersistenceFormat)

Saves this datastore to a stream using the specified persistence format.

public void Save(Stream stream, PersistenceFormat format)

Parameters

stream Stream
format PersistenceFormat

Save(string)

Saves the series to a csv file.

public void Save(string fileName)

Parameters

fileName string

Save(string, PersistenceFormat, bool)

Saves the specified file using the specified format and optionally compressing the output using gzip.

public void Save(string fileName, PersistenceFormat format, bool compress = false)

Parameters

fileName string
format PersistenceFormat
compress bool

Exceptions

ArgumentNullException

SetFields(IEnumerable<string>)

Sets field names using the specified array.

public void SetFields(IEnumerable<string> fields)

Parameters

fields IEnumerable<string>

Subset(DateTime, DateTime)

Returns a subset of the series using the specified start and end dates.

public ObservationSeries Subset(DateTime startDate, DateTime endDate)

Parameters

startDate DateTime
endDate DateTime

Returns

ObservationSeries

ToString()

Returns a string representation of this object.

public override string ToString()

Returns

string

ToTimeSeries(bool)

Returns a timeseries using the first available field.

public TimeSeries ToTimeSeries(bool useTimestamp = false)

Parameters

useTimestamp bool

Returns

TimeSeries

ToTimeSeries(int, bool)

Returns a timeseries of the specified index.

public TimeSeries ToTimeSeries(int index, bool useTimestamp = false)

Parameters

index int
useTimestamp bool

Use the timestamp instead of observation date as the timeseries date.

Returns

TimeSeries

ToTimeSeries(string, bool)

Returns a timeseries of the specified field.

public TimeSeries ToTimeSeries(string field, bool useTimestamp = false)

Parameters

field string
useTimestamp bool

Use the timestamp instead of observation date as the timeseries date.

Returns

TimeSeries