BaseOptimizer
The base optimizer of strategies.
Inherits: BaseLogReceiver
Constructors
protected BaseOptimizer(ISecurityProvider securityProvider, IPortfolioProvider portfolioProvider, IExchangeInfoProvider exchangeInfoProvider, IStorageRegistry storageRegistry, StorageFormats storageFormat, IMarketDataDrive drive)
baseOptimizer = BaseOptimizer(securityProvider, portfolioProvider, exchangeInfoProvider, storageRegistry, storageFormat, drive)
Initializes a new instance of the BaseOptimizer.
- securityProvider
- The provider of information about instruments.
- portfolioProvider
- The portfolio to be used to register orders. If value is not given, the portfolio with default name Simulator will be created.
- exchangeInfoProvider
- Exchanges and trading boards provider.
- storageRegistry
- Market data storage.
- storageFormat
- The format of market data. Binary is used by default.
- drive
- The storage which is used by default. By default, DefaultDrive is used.
Properties
public MarketDataStorageCache AdapterCache { get; set; }
value = baseOptimizer.AdapterCache
baseOptimizer.AdapterCache = value
AdapterCache.
public OptimizerSettings EmulationSettings { get; }
value = baseOptimizer.EmulationSettings
Emulation settings.
public IExchangeInfoProvider ExchangeInfoProvider { get; }
value = baseOptimizer.ExchangeInfoProvider
IExchangeInfoProvider
public bool IsPaused { get; }
value = baseOptimizer.IsPaused
Whether optimization is currently paused.
public IPortfolioProvider PortfolioProvider { get; }
value = baseOptimizer.PortfolioProvider
IPortfolioProvider
public ISecurityProvider SecurityProvider { get; }
value = baseOptimizer.SecurityProvider
ISecurityProvider
public bool StopOnSubscriptionError { get; set; }
value = baseOptimizer.StopOnSubscriptionError
baseOptimizer.StopOnSubscriptionError = value
StopOnSubscriptionError
public MarketDataStorageCache StorageCache { get; set; }
value = baseOptimizer.StorageCache
baseOptimizer.StorageCache = value
StorageCache.
public StorageCoreSettings StorageSettings { get; }
value = baseOptimizer.StorageSettings
Storage settings.
Methods
protected internal MarketDataStorageCache AllocateAdapterCache()
result = baseOptimizer.AllocateAdapterCache()
Allocate AdapterCache.
Returns: AdapterCache
protected internal MarketDataStorageCache AllocateStorageCache()
result = baseOptimizer.AllocateStorageCache()
Allocate StorageCache.
Returns: StorageCache
protected void CompleteChannel()
baseOptimizer.CompleteChannel()
Complete the channel so RunAsync enumeration ends.
protected override void DisposeManaged()
baseOptimizer.DisposeManaged()
Disposes the managed resources. Override this method to add custom clean up of managed resources.
protected internal void FreeAdapterCache(MarketDataStorageCache cache)
baseOptimizer.FreeAdapterCache(cache)
Free AdapterCache.
- cache
- AdapterCache
protected internal void FreeStorageCache(MarketDataStorageCache cache)
baseOptimizer.FreeStorageCache(cache)
Free StorageCache.
- cache
- StorageCache
protected void InitializeRunAsync(int totalIterations, CancellationToken cancellationToken)
baseOptimizer.InitializeRunAsync(totalIterations, cancellationToken)
Initialize channel, batch manager, and linked CTS for RunAsync.
- totalIterations
- Total number of iterations (or int.MaxValue if unknown).
- cancellationToken
- External cancellation token.
public Task Pause()
result = baseOptimizer.Pause()
Pause optimization. New iterations won't start until Resume is called, and the backtests that are already running are suspended so progress halts promptly.
Returns: Task
protected IAsyncEnumerable<ValueTuple<Strategy, IStrategyParam[]>> ReadResultsAsync(CancellationToken cancellationToken)
result = baseOptimizer.ReadResultsAsync(cancellationToken)
Yield results from channel reader.
public Task Resume()
result = baseOptimizer.Resume()
Resume paused optimization.
Returns: Task
protected internal ValueTask<bool> TryNextRunAsync(DateTime startTime, DateTime stopTime, Func<IPortfolioProvider, ValueTuple<Strategy, IStrategyParam[]>?> tryGetNext, MarketDataStorageCache adapterCache, MarketDataStorageCache storageCache, CancellationToken cancellationToken)
result = baseOptimizer.TryNextRunAsync(startTime, stopTime, tryGetNext, adapterCache, storageCache, cancellationToken)
Try start next iteration. Returns if iteration was started and completed, if no more iterations available.
- startTime
- Date in history for starting the paper trading.
- stopTime
- Date in history to stop the paper trading (date is included).
- tryGetNext
- Handler to try to get next strategy object.
- adapterCache
- AdapterCache
- storageCache
- StorageCache
- cancellationToken
- Cancellation token.
Events
public event Action<Connector> ConnectorInitialized
baseOptimizer.ConnectorInitialized += handler
Init Connector. Called before Connect.
public event Action<Strategy, IStrategyParam[], int> SingleProgressChanged
baseOptimizer.SingleProgressChanged += handler
The event of single progress change.
public event Action<Strategy, IStrategyParam[]> StrategyInitialized
baseOptimizer.StrategyInitialized += handler
Strategy initialized event.