Class Algorithm
Abstract base class for trading algorithms. All Turing Trader algorithms must be derived from this class, and override the Run() and Report() methods.
Implements
Inherited Members
Namespace: TuringTrader.Simulator
Assembly: TuringTrader.Simulator.dll
Syntax
public abstract class Algorithm : SimulatorCore, IAlgorithm
Constructors
| Improve this Doc View SourceAlgorithm()
Initialize trading algorithm. Most trading algorithms will only do very little here; the majority of the initialization should be performed in Run(), to allow multiple runs of the same instance.
Declaration
protected Algorithm()
Fields
| Improve this Doc View SourceSubclassedParam
Field w/ optional additional parameters for subclassed parameters. This field is populated from the data source's nickname used to instantiate the algorithm.
Declaration
public string SubclassedParam
Field Value
Type | Description |
---|---|
string |
Properties
| Improve this Doc View SourceCanRunAsChild
True, if this algorithm can be run as a child algorithm.
Declaration
public virtual bool CanRunAsChild { get; }
Property Value
Type | Description |
---|---|
bool |
FitnessReturn
Algorithm fitness: return
Declaration
public double FitnessReturn { get; }
Property Value
Type | Description |
---|---|
double |
FitnessRisk
Algorithm fitness: risk
Declaration
public double FitnessRisk { get; }
Property Value
Type | Description |
---|---|
double |
FitnessValue
Custom fitness value. Algorithms should use this, to report the fitness of the current algorithm settings to the optimizer. Outside of optimization, this field has no relevance.
Declaration
public double FitnessValue { get; set; }
Property Value
Type | Description |
---|---|
double |
IsDataSource
Field indicating if this algorithm instance is used as a datasource. This information can be used to turn-off CPU or memory intensive operations, e.g., the generation of plots and logs.
Declaration
public bool IsDataSource { get; set; }
Property Value
Type | Description |
---|---|
bool |
IsOptimizerParamsValid
Check if current optimizer params are valid.
Declaration
public bool IsOptimizerParamsValid { get; }
Property Value
Type | Description |
---|---|
bool |
IsOptimizing
Field indicating if this algorithm instance is being optimized. Algorithms should use this to reduce unnecessary calculations and output, to speed up optimization and conserve memory.
Declaration
public bool IsOptimizing { get; set; }
Property Value
Type | Description |
---|---|
bool |
OptimizerParams
Container holding all optimizable parameters, along with their settings.
Declaration
public Dictionary<string, OptimizerParam> OptimizerParams { get; set; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.Dictionary<TKey, TValue><string, OptimizerParam> |
OptimizerParamsAsString
String representation of the current settings of all optimizable parameters.
Declaration
public string OptimizerParamsAsString { get; }
Property Value
Type | Description |
---|---|
string |
Progress
Progress indicator, ranging from 0 to 100. This progress indicator is based on the time stamp of the current bar being processed, which may or may not be a good indicator of CPU time.
Declaration
public double Progress { get; }
Property Value
Type | Description |
---|---|
double |
Methods
| Improve this Doc View SourceCheckParametersValid()
Check, if current parameter set is valid. This is used to weed out illegal parameter combinations during grid optimization.
Declaration
public virtual bool CheckParametersValid()
Returns
Type | Description |
---|---|
bool | true, if parameter set valid |
Clone()
Clone algorithm, including all optimizer parameters. The application uses this method to clone the 'master' instance, and create new algorithm instances before running them.
Declaration
public IAlgorithm Clone()
Returns
Type | Description |
---|---|
IAlgorithm | new algorithm instance |
Report()
Create report. This method can be called after calling Run(), to create and display a custom report. Typically, trading algorithms override this method with their own implementation. Algorithms are not required to call the base class implementation of this method.
Declaration
public virtual void Report()
Run()
Entry point for trading algorithm, simple interface. All algorithms override either this method, or the subclassable version of it with their own implementation. Algorithms are not required to call the base class implementation of this method. This method is called only once per instance. Nonetheless, care should be taken that the implementation of this method initializes/ resets all parameters, to allow multiple runs.
Declaration
public virtual void Run()
Run(DateTime?, DateTime?)
Entry point for trading algorithm, subclassable interface. All algorithms override either this method, or the subclassable version of it with their own implementation. Algorithms are not required to call the base class implementation of this method. This method is called only once per instance. Nonetheless, care should be taken that the implementation of this method initializes/ resets all parameters, to allow multiple runs.
Declaration
public virtual IEnumerable<Bar> Run(DateTime? startTime, DateTime? endTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime? | startTime | simulation start time |
System.DateTime? | endTime | simulation end time |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><Bar> | enumerable of bars, representing the algorithm result |