Table of Contents

Class DataStore

Namespace
Balsam.Data
Assembly
Balsam.Backtester.dll

Provides a fast in-memory datastore

[ProtoContract]
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class DataStore : DataStoreBase, IDataStore, ICloneable
Inheritance
DataStore
Implements
Inherited Members
Extension Methods

Properties

CanPersist

Returns true.

public override bool CanPersist { get; }

Property Value

bool

HasTrades

Returns true if the datastore has any trades.

public override bool HasTrades { get; }

Property Value

bool

Methods

Clear()

Clears the datastore.

public override void Clear()

Clone()

Returns a copy of this datastore. The internal data objects are shallow copies since they are typically read-only.

public DataStore Clone()

Returns

DataStore

GetGlobalVariables()

Returns global variables.

protected override VariableDictionary GetGlobalVariables()

Returns

VariableDictionary

GetInstruments()

Returns the instruments in the datastore.

protected override InstrumentCollection GetInstruments()

Returns

InstrumentCollection

GetNextTradeId()

Returns the next trade id.

protected override long GetNextTradeId()

Returns

long

GetPricing(long, string, DateTime)

Returns pricing for the specified position on the specified date.

protected override Bar GetPricing(long positionId, string symbol, DateTime date)

Parameters

positionId long
symbol string
date DateTime

Returns

Bar

GetRisk(long, DateTime)

Returns risk for the specified position on the specified date.

protected override double GetRisk(long positionId, DateTime date)

Parameters

positionId long
date DateTime

Returns

double

GetRoll(long, DateTime)

Returns a roll if any for the specified position on the specified date.

protected override Roll GetRoll(long positionId, DateTime date)

Parameters

positionId long
date DateTime

Returns

Roll

GetStartAndEndDates()

Returns the start and end dates of data within the datastore.

protected override DateRange GetStartAndEndDates()

Returns

DateRange

GetStrategyNames()

Returns the strategy names within the datastore.

protected override IEnumerable<string> GetStrategyNames()

Returns

IEnumerable<string>

GetStrategyVariables(string)

Returns strategy variables for the specified strategy.

protected override VariableDictionary GetStrategyVariables(string strategyName)

Parameters

strategyName string

Returns

VariableDictionary

GetSymbols()

Returns the symbols within the datastore.

protected override IEnumerable<string> GetSymbols()

Returns

IEnumerable<string>

GetTradeDates()

Returns an enumerable of dates on which there are trades.

protected override IEnumerable<DateTime> GetTradeDates()

Returns

IEnumerable<DateTime>

GetTrades()

Returns all trades within the datastore.

protected override IEnumerable<Trade> GetTrades()

Returns

IEnumerable<Trade>

GetTrades(DateTime)

Returns all the trades on a specified date. This does not include time of day.

protected override IEnumerable<Trade> GetTrades(DateTime date)

Parameters

date DateTime

Returns

IEnumerable<Trade>

Load(Stream)

Loads a datastore from the specified stream.

public static DataStore Load(Stream stream)

Parameters

stream Stream

Returns

DataStore

Load(string)

Loads the specified datastore file from disk.

public static DataStore Load(string fileName)

Parameters

fileName string

Returns

DataStore

Merge(IDataStore)

Merges the specified datastore into the existing one.

public override void Merge(IDataStore dataStore)

Parameters

dataStore IDataStore

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 datastore to disk using the specified file name.

public override void Save(string fileName)

Parameters

fileName string

Save(string, PersistenceFormat, bool)

Saves the datastore to disk using the specified parameters.

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

Parameters

fileName string
format PersistenceFormat
compress bool

Subset(IEnumerable<long>)

Returns a new datastore excluding the specified trade ids. This is typically used to created a new datastore without trades rejected by a previous money manager.

public DataStore Subset(IEnumerable<long> rejectedTrades)

Parameters

rejectedTrades IEnumerable<long>

Returns

DataStore

Subset(DateTime, DateTime)

Returns a subset of this datastore with information between the specified start and end dates inclusive.

public DataStore Subset(DateTime startDate, DateTime endDate)

Parameters

startDate DateTime
endDate DateTime

Returns

DataStore

Subset(string)

Returns a new datastore containing just trades for the specified strategy.

public DataStore Subset(string strategyName)

Parameters

strategyName string

Returns

DataStore

Exceptions

ArgumentNullException

WriteGlobalVariables(VariableDictionary)

Writes the specified global variables dictionary to the datastore.

protected override void WriteGlobalVariables(VariableDictionary variables)

Parameters

variables VariableDictionary

WritePricing(long, Bar)

Writes pricing for the specified position.

protected override void WritePricing(long positionId, Bar bar)

Parameters

positionId long
bar Bar

WriteRisk(long, DateTime, double)

Writes risk for the specified position.

protected override void WriteRisk(long positionId, DateTime date, double risk)

Parameters

positionId long
date DateTime
risk double

WriteRoll(long, Roll)

Writes the specified roll.

protected override void WriteRoll(long positionId, Roll roll)

Parameters

positionId long
roll Roll

WriteStrategyVariables(string, VariableDictionary)

Writes the specified strategy variables.

protected override void WriteStrategyVariables(string strategyName, VariableDictionary variables)

Parameters

strategyName string
variables VariableDictionary

WriteTrade(Trade)

Writes the specified trade.

protected override void WriteTrade(Trade trade)

Parameters

trade Trade