Table of Contents

Class AsciiBarServer<T>

Namespace
Balsam.DataServers
Assembly
Balsam.Backtester.dll

A bar server for reading ASCII data.

public class AsciiBarServer<T> : BarServer, IBarServer where T : Bar

Type Parameters

T
A bar server for reading ASCII data.
Inheritance
AsciiBarServer<T>
Implements
Derived
Inherited Members
Extension Methods

Constructors

AsciiBarServer(string)

Initializes a new AsciiBarServer using the specified directory. File format will be inferred from field count.

public AsciiBarServer(string directory)

Parameters

directory string

AsciiBarServer(string, params DataField[])

Initializes a new AsciiBarServer with the specified directory and field format.

public AsciiBarServer(string directory, params DataField[] fields)

Parameters

directory string
fields DataField[]

Fields

DC

Date Close format.

public static readonly DataField[] DC

Field Value

DataField[]

DCV

Date Close Volume format.

public static readonly DataField[] DCV

Field Value

DataField[]

DOHLC

Date Open High Low Close format.

public static readonly DataField[] DOHLC

Field Value

DataField[]

DOHLCV

Date Open High Low Close Volume format.

public static readonly DataField[] DOHLCV

Field Value

DataField[]

DOHLCVI

Date Open High Low Close Volume OpenInterest format.

public static readonly DataField[] DOHLCVI

Field Value

DataField[]

DOHLCVINU

Date Open High Low Close Volume OpenInterest DeliveryDate UnadjustedClose format. Used for CSI data.

public static readonly DataField[] DOHLCVINU

Field Value

DataField[]

DOHLCVIU

Date Open High Low Close Volume OpenInterest UnadjustedClose format.

public static readonly DataField[] DOHLCVIU

Field Value

DataField[]

_barFactory

Used to instantiate new bars of type T.

protected Func<DateTime, double[], T> _barFactory

Field Value

Func<DateTime, double[], T>

_fileLayout

Encapsulates the file layout.

protected AsciiBarServer<T>.FileLayout _fileLayout

Field Value

AsciiBarServer<T>.FileLayout

Properties

DateFormatString

Gets/sets a custom .NET framework date time format string.

public string DateFormatString { get; set; }

Property Value

string

Delimiter

Gets/sets the delimiter used to separate fields. Default is comma delimited.

public string Delimiter { get; set; }

Property Value

string

DigitsToRound

Gets/sets the number of digits to round.

public int DigitsToRound { get; set; }

Property Value

int

Directory

Gets the primary data directory.

public string Directory { get; }

Property Value

string

Extension

Gets/sets the file extension.

public string Extension { get; set; }

Property Value

string

Fields

Gets the field layout.

public IEnumerable<DataField> Fields { get; }

Property Value

IEnumerable<DataField>

FillMissingValues

Gets/sets how missing or NaN values are handled. When true attempts to fill a logical value based on available data for that record. (e.g. if the high is missing, it will take the maximum of the open and close). Does not work when IncludeMissingClose is set to true.

public bool FillMissingValues { get; set; }

Property Value

bool

IncludeExtraFields

Gets/sets whether extra fields are included in the bar. When true, the field layout must have been explictly set in the constructor.

public bool IncludeExtraFields { get; set; }

Property Value

bool

IncludeMissingClose

Gets/sets whether records with a missing or NaN close are included.

public bool IncludeMissingClose { get; set; }

Property Value

bool

Instruments

Gets/sets the instrument dictionary.

public InstrumentCollection Instruments { get; set; }

Property Value

InstrumentCollection

IsConnected

Gets whether the server is connected; controls deferred initialization.

protected bool IsConnected { get; }

Property Value

bool

RaiseNegativePrices

Gets/sets whether prices will be adjusted so that there are no negative values.

public bool RaiseNegativePrices { get; set; }

Property Value

bool

RequireInstrument

Gets/sets whether an instrument is required to be in the instrument dictionary. When true, an exception will be thrown if a symbol is not found in the internal instrument dictionary. If false, a Message event will be raised instead and the default instrument will be returned. Designed to prevent backtests or P&L calculations from being unwittingly performed with the wrong point values or currency.

public bool RequireInstrument { get; set; }

Property Value

bool

SymbolTranslations

Get/sets a symbol translation collection.

public SymbolTranslationCollection SymbolTranslations { get; set; }

Property Value

SymbolTranslationCollection

Symbols

Gets the internal dictionary that maps a symbol to a particular ascii data file.

protected Dictionary<string, string> Symbols { get; }

Property Value

Dictionary<string, string>

TimeFormatString

Gets/sets a custom .NET framework time format string. Common formats include hhmm and h\:mm

public string TimeFormatString { get; set; }

Property Value

string

UseMultipleThreads

Gets/sets whether LoadAll and LoadSymbols will load multiple symbols in parallel. True by default.

public bool UseMultipleThreads { get; set; }

Property Value

bool

Methods

AddDirectory(string)

Adds a directory to allow data to be loaded across multiple directories.

public void AddDirectory(string directory)

Parameters

directory string

Connect()

Initializes the dataserver.

protected void Connect()

ContainsSymbol(string)

Returns true if the server can return data for the specified symbol.

public bool ContainsSymbol(string symbol)

Parameters

symbol string

Returns

bool

GetSymbols(string)

Returns symbols that contain the specified string.

public IEnumerable<string> GetSymbols(string contains)

Parameters

contains string

Returns

IEnumerable<string>

OnGetInstrument(string)

Returns the instrument for the specified symbol or Instrument.DefaultInstrument if not found.

protected virtual Instrument OnGetInstrument(string symbol)

Parameters

symbol string

Returns

Instrument

OnGetSymbols()

Returns available symbols.

protected override IEnumerable<string> OnGetSymbols()

Returns

IEnumerable<string>

OnInstrumentsLoaded(InstrumentCollection)

Called after an instrument dictionary is loaded, either by calling Connect() or setting the Instruments property. Populates ConversionFactors dictionary using instrument symbol.

protected void OnInstrumentsLoaded(InstrumentCollection instruments)

Parameters

instruments InstrumentCollection

OnLoadSymbol(string, DateTime, DateTime, int)

Core logic to resolve file name, load data, load instrument, apply conversion factor and return a BarSeries.

protected override BarSeries OnLoadSymbol(string symbol, DateTime startDate, DateTime endDate, int barsToLoad = 2147483647)

Parameters

symbol string
startDate DateTime
endDate DateTime
barsToLoad int

Returns

BarSeries

OnLoadSymbols(DateTime, DateTime, params string[])

Overrides base implementation to load symbols in parallel. Set UseMultipleThreads to false to disable this behavior.

protected override BarSeriesCollection OnLoadSymbols(DateTime startDate, DateTime endDate, params string[] symbols)

Parameters

startDate DateTime
endDate DateTime
symbols string[]

Returns

BarSeriesCollection

OnProcessFile(string, string, DateTime, DateTime, int)

Core file processing. Returns a list of bars.

protected virtual List<Bar> OnProcessFile(string symbol, string fileName, DateTime startDate, DateTime endDate, int barsToLoad)

Parameters

symbol string
fileName string
startDate DateTime
endDate DateTime
barsToLoad int

Returns

List<Bar>

OnResolveFileName(string)

Returns the filename associated with the specified symbol or null if the symbol isn't found.

protected virtual string OnResolveFileName(string symbol)

Parameters

symbol string

Returns

string

ToString()

Returns a string representation of this instance.

public override string ToString()

Returns

string