Show / Hide Table of Contents

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.

Inheritance
object
SimulatorCore
Algorithm
Implements
IAlgorithm
Inherited Members
SimulatorCore._calcNetAssetValue()
SimulatorCore.Name
SimulatorCore.StartTime
SimulatorCore.WarmupStartTime
SimulatorCore.EndTime
SimulatorCore.TradingDays
SimulatorCore.SimTimes
SimulatorCore.SimTime
SimulatorCore.NextSimTime
SimulatorCore.IsLastBar
SimulatorCore.AddDataSource(string)
SimulatorCore.AddDataSource(Algorithm)
SimulatorCore.AddDataSource(DataSource)
SimulatorCore.AddDataSource(object)
SimulatorCore.AddDataSources(IEnumerable<string>)
SimulatorCore.Instruments
SimulatorCore.HasInstrument(string)
SimulatorCore.HasInstrument(DataSource)
SimulatorCore.HasInstruments(IEnumerable<string>)
SimulatorCore.HasInstruments(IEnumerable<DataSource>)
SimulatorCore.FindInstrument(string)
SimulatorCore.OptionChain(string)
SimulatorCore.OptionChain(DataSource)
SimulatorCore.QueueOrder(Order)
SimulatorCore.PendingOrders
SimulatorCore.Positions
SimulatorCore.Log
SimulatorCore.Deposit(double)
SimulatorCore.Withdraw(double)
SimulatorCore.Cash
SimulatorCore.NetAssetValue
SimulatorCore.NetAssetValueHighestHigh
SimulatorCore.NetAssetValueMaxDrawdown
SimulatorCore.CommissionPerShare
SimulatorCore.FillModel(Order, Bar, double)
SimulatorCore.IsValidSimTime(DateTime)
SimulatorCore.CalcNextSimTime(DateTime)
SimulatorCore.IsValidBar(Bar)
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: TuringTrader.Simulator
Assembly: TuringTrader.Simulator.dll
Syntax
public abstract class Algorithm : SimulatorCore, IAlgorithm

Constructors

| Edit this page View Source

Algorithm()

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

| Edit this page View Source

SubclassedParam

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

| Edit this page View Source

CanRunAsChild

True, if this algorithm can be run as a child algorithm.

Declaration
public virtual bool CanRunAsChild { get; }
Property Value
Type Description
bool
| Edit this page View Source

FitnessReturn

Algorithm fitness: return

Declaration
public double FitnessReturn { get; }
Property Value
Type Description
double
| Edit this page View Source

FitnessRisk

Algorithm fitness: risk

Declaration
public double FitnessRisk { get; }
Property Value
Type Description
double
| Edit this page View Source

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
| Edit this page View Source

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
| Edit this page View Source

IsOptimizerParamsValid

Check if current optimizer params are valid.

Declaration
public bool IsOptimizerParamsValid { get; }
Property Value
Type Description
bool
| Edit this page View Source

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
| Edit this page View Source

IsRunningInsideV2

Field indicating if this algorithm instance is running inside a V2 engine host. This information is required to tweak some of the memory cleanup at the end of the simulation.

Declaration
public bool IsRunningInsideV2 { get; set; }
Property Value
Type Description
bool
| Edit this page View Source

OptimizerParams

Container holding all optimizable parameters, along with their settings.

Declaration
public Dictionary<string, OptimizerParam> OptimizerParams { get; set; }
Property Value
Type Description
Dictionary<string, OptimizerParam>
| Edit this page View Source

OptimizerParamsAsString

String representation of the current settings of all optimizable parameters.

Declaration
public string OptimizerParamsAsString { get; }
Property Value
Type Description
string
| Edit this page View Source

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

| Edit this page View Source

CheckParametersValid()

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

| Edit this page View Source

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

| Edit this page View Source

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()
| Edit this page View Source

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()
| Edit this page View Source

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
DateTime? startTime

simulation start time

DateTime? endTime

simulation end time

Returns
Type Description
IEnumerable<Bar>

enumerable of bars, representing the algorithm result

Implements

IAlgorithm

Extension Methods

GlobalSettings.GetRegistryValue(SimulatorCore, string, object)
GlobalSettings.SetRegistryValue(SimulatorCore, string, object)
  • Edit this page
  • View Source
In this article
Back to top Copyright © 2011-2023, Bertram Enterprises LLC dba TuringTrader.com