a4f66628fd
* initial commit * run parametrized algorithm with command line parameters * skeleton: top level structure * OptimizationNodePacket scheme * pass parameters as HashSet * run Lean and read results * call method on optimization completion * refactor public interfaces - close ParameterSet collection; allow only get operations - explicit method to start LeanOptimizer * synchronize RunLean method; the result could come in before the backtest id is set in the collections * another portion of refactoring and interface changes * comments * comments & tests for Extremum, Minimization and Maximization classes * unify optimization paramater values (min, max, step) & mode GridSearch tests - swap min&max if necessary - iterate left => right (negate step value if necessary) & provide default step value if step == 0 - no StackOverflow Exception - parameterSet Id should be global for current generator and retain between steps - test signle point boundary (min == max) * BruteForceStrategy tests * more comments * Update Optimizer assembly information - Update Optimizer projects assembly information to match behavior of the other projects * Tweaks - Adding comments - Replace OnComplete for Ended event - Replace Abort for Dispose - ConsoleLeanOptimizer will keep track of running processes - Each backtest will store results in a separated directory, so they don't fight for the log.txt file. - Adding cmdline option for lean to close automatically - Adding concurrent execution backtest limit - Console optimizer will start Lean minimized - Escape spaces in Json path * remove parameter set generator abstraction layer we don't need this flexibility now. * refactor public methods; Step shouldn't be public * constraints: wip * define contract * comparison operators and tests * specify JsonProperty values * Move SafeMultiply100 to extensions * Throw exception on failed Optimizer.Start * constraints: wip * change finish & dispose process * minor fixes - handle force lean abort - notify consumer if target has been reached * target & constraints; adapt unit tests * Minor Tweaks and fixes - Some logging improvements - Remove Public since not required * Ignore empty ParameterValue * simplify condition * avoid reinitialization * reduce type; force immutable * unit tests for constraints and target value * parse & normalize percent values, i.e. 20% => 0.2 * fixup * Target & Constraint & OptimizationNodePacket unit tests * Add more json unit tests - Adding more json conversion unit tests. Fix bug for Extremum which wasn't using the converter. * LeanOptimizer tests * Estimation results * User thread safe counters * LeanOptimizer unit tests; push OptimizationResult on Ended event * more unit tests * Minor tweaks -Estimate ToString in a single line. -Typos and missing header file * Add base SendUpdate method - Add base SendUpdate method for LeanOptimizer * fix LeanOptimizer test; rely on internal Update rather than timer * Add OptimizationStatus - Add missing commments and OptimizationStatus * EulerSearch implementation: wip * OptimizationParameter custom converter * change the type * make step optional * change folder structure * enumerate optimization parameter using IEnumerable & IEnumerator * unit tests: parameters & objectives * unit tests: strategies * remove redundant TODO * change Euler search boundaries * more Euler tests * prevent race condition * Add account/read endpoint - Adding account/read endpoint. Adding unit test * Add status check before running lean * Minor self review - Adding missing comments, minor changes * remove array parameters * minor changes - tidy up config file, rename variable - accept min less or equal than max * move OptimizationParameter methods to strategies * Minor improvements for BaseResultHandler derivates * minor changes - strict requirements for Step and MinStep values - strategy specific settigs * Add TotalRuntime to estimate Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
202 lines
6.8 KiB
C#
202 lines
6.8 KiB
C#
/*
|
|
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
|
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*
|
|
*/
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Newtonsoft.Json;
|
|
using QuantConnect.Interfaces;
|
|
|
|
namespace QuantConnect.Packets
|
|
{
|
|
/// <summary>
|
|
/// Specifies values used to control algorithm limits
|
|
/// </summary>
|
|
public class Controls
|
|
{
|
|
/// <summary>
|
|
/// The maximum number of minute symbols
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "iMinuteLimit")]
|
|
public int MinuteLimit;
|
|
|
|
/// <summary>
|
|
/// The maximum number of second symbols
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "iSecondLimit")]
|
|
public int SecondLimit;
|
|
|
|
/// <summary>
|
|
/// The maximum number of tick symbol
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "iTickLimit")]
|
|
public int TickLimit;
|
|
|
|
/// <summary>
|
|
/// Ram allocation for this algorithm in MB
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "iMaxRamAllocation")]
|
|
public int RamAllocation;
|
|
|
|
/// <summary>
|
|
/// CPU allocation for this algorithm
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "dMaxCpuAllocation")]
|
|
public decimal CpuAllocation;
|
|
|
|
/// <summary>
|
|
/// The user backtesting log limit
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "iBacktestLogLimit")]
|
|
public int BacktestLogLimit;
|
|
|
|
/// <summary>
|
|
/// The daily log limit of a user
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "iDailyLogLimit")]
|
|
public int DailyLogLimit;
|
|
|
|
/// <summary>
|
|
/// The remaining log allowance for a user
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "iRemainingLogAllowance")]
|
|
public int RemainingLogAllowance;
|
|
|
|
/// <summary>
|
|
/// Maximimum number of insights we'll store and score in a single backtest
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "iBacktestingMaxInsights")]
|
|
public int BacktestingMaxInsights;
|
|
|
|
/// <summary>
|
|
/// Maximimum number of orders we'll allow in a backtest.
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "iBacktestingMaxOrders")]
|
|
public int BacktestingMaxOrders { get; set; }
|
|
|
|
/// <summary>
|
|
/// Limits the amount of data points per chart series. Applies only for backtesting
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "iMaximumDataPointsPerChartSeries")]
|
|
public int MaximumDataPointsPerChartSeries;
|
|
|
|
/// <summary>
|
|
/// The amount seconds used for timeout limits
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "iSecondTimeOut")]
|
|
public int SecondTimeOut;
|
|
|
|
/// <summary>
|
|
/// Sets parameters used for determining the behavior of the leaky bucket algorithm that
|
|
/// controls how much time is available for an algorithm to use the training feature.
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "oTrainingLimits")]
|
|
public LeakyBucketControlParameters TrainingLimits;
|
|
|
|
/// <summary>
|
|
/// Limits the total size of storage used by <see cref="IObjectStore"/>
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "storageLimitMB")]
|
|
public int StorageLimitMB;
|
|
|
|
/// <summary>
|
|
/// Limits the number of files to be held under the <see cref="IObjectStore"/>
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "storageFileCountMB")]
|
|
public int StorageFileCount;
|
|
|
|
/// <summary>
|
|
/// Holds the permissions for the object store
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "storagePermissions")]
|
|
public FileAccess StoragePermissions;
|
|
|
|
/// <summary>
|
|
/// The interval over which the <see cref="IObjectStore"/> will persistence the contents of
|
|
/// the object store
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "persistenceIntervalSeconds")]
|
|
public int PersistenceIntervalSeconds;
|
|
|
|
/// <summary>
|
|
/// Gets list of streaming data permissions
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "streamingDataPermissions")]
|
|
public HashSet<string> StreamingDataPermissions;
|
|
|
|
/// <summary>
|
|
/// Gets list of allowed data resolutions
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "dataResolutionPermissions")]
|
|
public HashSet<Resolution> DataResolutionPermissions;
|
|
|
|
/// <summary>
|
|
/// The cost associated with running this job
|
|
/// </summary>
|
|
[JsonProperty(PropertyName = "iCreditCost")]
|
|
public uint CreditCost;
|
|
|
|
/// <summary>
|
|
/// Initializes a new default instance of the <see cref="Controls"/> class
|
|
/// </summary>
|
|
public Controls()
|
|
{
|
|
MinuteLimit = 500;
|
|
SecondLimit = 100;
|
|
TickLimit = 30;
|
|
RamAllocation = 1024;
|
|
BacktestLogLimit = 10000;
|
|
BacktestingMaxOrders = int.MaxValue;
|
|
DailyLogLimit = 3000000;
|
|
RemainingLogAllowance = 10000;
|
|
BacktestingMaxInsights = 10000;
|
|
MaximumDataPointsPerChartSeries = 4000;
|
|
SecondTimeOut = 300;
|
|
StorageLimitMB = 5;
|
|
StorageFileCount = 100;
|
|
PersistenceIntervalSeconds = 5;
|
|
StoragePermissions = FileAccess.ReadWrite;
|
|
|
|
// initialize to default leaky bucket values in case they're not specified
|
|
TrainingLimits = new LeakyBucketControlParameters();
|
|
|
|
StreamingDataPermissions = new HashSet<string>();
|
|
DataResolutionPermissions = new HashSet<Resolution>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the maximum number of subscriptions for the specified resolution
|
|
/// </summary>
|
|
public int GetLimit(Resolution resolution)
|
|
{
|
|
switch (resolution)
|
|
{
|
|
case Resolution.Tick:
|
|
return TickLimit;
|
|
|
|
case Resolution.Second:
|
|
return SecondLimit;
|
|
|
|
case Resolution.Minute:
|
|
case Resolution.Hour:
|
|
case Resolution.Daily:
|
|
default:
|
|
return MinuteLimit;
|
|
}
|
|
}
|
|
}
|
|
}
|