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
Fields
DC
Date Close format.
public static readonly DataField[] DC
Field Value
DCV
Date Close Volume format.
public static readonly DataField[] DCV
Field Value
DOHLC
Date Open High Low Close format.
public static readonly DataField[] DOHLC
Field Value
DOHLCV
Date Open High Low Close Volume format.
public static readonly DataField[] DOHLCV
Field Value
DOHLCVI
Date Open High Low Close Volume OpenInterest format.
public static readonly DataField[] DOHLCVI
Field Value
DOHLCVINU
Date Open High Low Close Volume OpenInterest DeliveryDate UnadjustedClose format. Used for CSI data.
public static readonly DataField[] DOHLCVINU
Field Value
DOHLCVIU
Date Open High Low Close Volume OpenInterest UnadjustedClose format.
public static readonly DataField[] DOHLCVIU
Field Value
_barFactory
Used to instantiate new bars of type T.
protected Func<DateTime, double[], T> _barFactory
Field Value
_fileLayout
Encapsulates the file layout.
protected AsciiBarServer<T>.FileLayout _fileLayout
Field Value
Properties
DateFormatString
Gets/sets a custom .NET framework date time format string.
public string DateFormatString { get; set; }
Property Value
Delimiter
Gets/sets the delimiter used to separate fields. Default is comma delimited.
public string Delimiter { get; set; }
Property Value
DigitsToRound
Gets/sets the number of digits to round.
public int DigitsToRound { get; set; }
Property Value
Directory
Gets the primary data directory.
public string Directory { get; }
Property Value
Extension
Gets/sets the file extension.
public string Extension { get; set; }
Property Value
Fields
Gets the field layout.
public IEnumerable<DataField> Fields { get; }
Property Value
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
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
IncludeMissingClose
Gets/sets whether records with a missing or NaN close are included.
public bool IncludeMissingClose { get; set; }
Property Value
Instruments
Gets/sets the instrument dictionary.
public InstrumentCollection Instruments { get; set; }
Property Value
IsConnected
Gets whether the server is connected; controls deferred initialization.
protected bool IsConnected { get; }
Property Value
RaiseNegativePrices
Gets/sets whether prices will be adjusted so that there are no negative values.
public bool RaiseNegativePrices { get; set; }
Property Value
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
SymbolTranslations
Get/sets a symbol translation collection.
public SymbolTranslationCollection SymbolTranslations { get; set; }
Property Value
Symbols
Gets the internal dictionary that maps a symbol to a particular ascii data file.
protected Dictionary<string, string> Symbols { get; }
Property Value
TimeFormatString
Gets/sets a custom .NET framework time format string. Common formats include hhmm and h\:mm
public string TimeFormatString { get; set; }
Property Value
UseMultipleThreads
Gets/sets whether LoadAll and LoadSymbols will load multiple symbols in parallel. True by default.
public bool UseMultipleThreads { get; set; }
Property Value
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
GetSymbols(string)
Returns symbols that contain the specified string.
public IEnumerable<string> GetSymbols(string contains)
Parameters
contains
string
Returns
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
OnGetSymbols()
Returns available symbols.
protected override IEnumerable<string> OnGetSymbols()
Returns
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
Returns
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
Returns
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
Returns
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
ToString()
Returns a string representation of this instance.
public override string ToString()