public KtbOrderProcessData( String targetCode, TradingDirection longShort, long unsignedInitTargetCount, double initTargetPrice, IMarketDataBoard board, Account account, ISweeper sweeper) { this.Orders = new List<POrder>(); this.Code = targetCode; this.LongShort = longShort; this.InitUnsignedTargetCount = unsignedInitTargetCount; this.InitTargetPrice = initTargetPrice; this.Board = board; this.Account = account; this.Sweeper = sweeper; this.CurUnsignedTargetCount = unsignedInitTargetCount; this.Aging = 0; this.MuteSec = 2; this.IsReadyForResume = false; }
public SmacSweeper(MLContext context, Arguments args) { _context = context; _args = args; _sweepParameters = args.SweptParameters; _randomSweeper = new UniformRandomSweeper(new SweeperBase.ArgumentsBase(), _sweepParameters); }
public SweepUnit_FO( long signedGoalCountFO, String code, double initEnterPrice, POrder initOrder, Account accountFO, ISweeper parent, int muteSec) { this.ID = SweepUnitIDManager.NextID++; this.InitEnterPrice = initEnterPrice; this.InitSignedGoalCount = this.CurSignedTargetCount = signedGoalCountFO; this.Code = code; this._initOrder = initOrder; this.AccountFO = accountFO; this._parent = parent; this._muteSec = muteSec; this.InitLongShort = InitSignedGoalCount > 0 ? TradingDirection.Long : TradingDirection.Short; this._mute = new Timer(muteSec, ""); this._bResumed = false; this._bCompleteQuickly = false; this.RealOrders = new List<POrder>(); RequestInitOrder(); }
public SweepUnitContext_Bond_Short( TradingDirection ls, BondPair pair, Account bondAccount, ISweeper sweeper) { this.ID = SweepUnitIDManager.NextID++; this.LongShort = ls; Trace.Assert(this.LongShort == TradingDirection.Short); // -15 this.CurSignedTargetCount = pair.Count * (-1); this.EnterCode = pair.EnterCodeWithMarketType; this.PairCode = pair.PairCodeWithMarketType; this._initSweepPrice = pair.PairPrice; this.BondAccount = bondAccount; this._enterMarketType = BondUtil.GetMarketType(pair.EnterCodeWithMarketType); this._pairMarketType = BondUtil.GetMarketType(pair.PairCodeWithMarketType); this._sweeper = sweeper; this.RealOrdersShort = new List<POrder>(); }
public SweepUnitContext_Bond_Long( TradingDirection ls, BondPair pair, Account bondAccount, ISweeper sweeper) { this.ID = SweepUnitIDManager.NextID++; this.LongShort = ls; Trace.Assert(this.LongShort == TradingDirection.Long); this.InitSignedGoalCount = pair.Count; this.CurSignedTargetCount = pair.Count; this.EnterCode = pair.EnterCodeWithMarketType; this._initEnterPrice = pair.EnterPrice; this.BondAccount = bondAccount; this._enterMarketType = BondUtil.GetMarketType(pair.EnterCodeWithMarketType); this._sweeper = sweeper; CreateInitOrders(pair); this.RealOrdersLong = new List<POrder>(); ReadyBidAskCountDataForAllocate(pair); }
public DeterministicSweeperAsync(IHostEnvironment env, Options options) { _host = env.Register("DeterministicSweeperAsync", options.RandomSeed); _host.CheckValue(options.Sweeper, nameof(options.Sweeper), "Please specify a sweeper"); _host.CheckUserArg(options.BatchSize > 0, nameof(options.BatchSize), "Batch size must be positive"); _host.CheckUserArg(options.Relaxation >= 0, nameof(options.Relaxation), "Synchronization relaxation must be non-negative"); _host.CheckUserArg(options.Relaxation <= options.BatchSize, nameof(options.Relaxation), "Synchronization relaxation cannot be larger than batch size"); _batchSize = options.BatchSize; _baseSweeper = options.Sweeper.CreateComponent(_host); _host.CheckUserArg(!(_baseSweeper is NelderMeadSweeper) || options.Relaxation == 0, nameof(options.Relaxation), "Nelder-Mead requires full synchronization (relaxation = 0)"); _cts = new CancellationTokenSource(); _relaxation = options.Relaxation; _lock = new object(); _results = new List <IRunResult>(); _nullRuns = new HashSet <int>(); _paramChannel = Channel.CreateUnbounded <ParameterSetWithId>( new UnboundedChannelOptions { SingleWriter = true }); PrepareNextBatch(null); }
// ReSharper disable UseObjectOrCollectionInitializer // ReSharper disable FunctionNeverReturns protected static void InitializeSweeper() { IWebConfiguration webConfig = IocContainer.Instance.Resolve <IWebConfiguration>(); if (!webConfig.RunSweeper) { return; } ILog sweeperLogger = LogManager.GetLogger(typeof(ISweeper)); ISweeper sweeper = IocContainer.Instance.Resolve <ISweeper>(); TimeSpan timeout = webConfig.SweeperTimeout; Thread sweeperThread = new Thread(() => { while (true) { Thread.Sleep(timeout); try { sweeper.CleanUp(); } catch (Exception ex) { sweeperLogger.Error(ex); } } }); sweeperThread.IsBackground = true; sweeperThread.Start(); }
public SweepUnit_OE( POrder goalOrder, Account accountFO, Account accountSpot, OptionTribe ot, ISweeper parent, Boolean bConservativeOptionPolicyOn, int muteSec) { ID = SweepUnitIDManager.NextID++; _parent = parent; GoalOrder = goalOrder; RealOrders = new List<POrder>(); _ot = ot; _mute = new Timer(muteSec, ""); // 2ì´ˆ _candidateCodes = ElwOptionUtil.GetSameCandidateCodes(goalOrder.Code); _accountSpot = accountSpot; _accountFO = accountFO; _bConservativeOptionPolicyOn = bConservativeOptionPolicyOn; if (!RequestInitOrder()) { GoalOrder.Free(); } _State = State._1_MuteFewSecs; ShowState(); }
public SweepMember(ISweeper parent, SweepMember_Input input, IReqOrderInput orderGenInput, IReqOrderPolicy reqOrderPolicy, IResumePolicy resumePolicy, IBalancePolicy balancePolicy) { this.Parent = parent; this.Input = input; this.Share = new SweepMember_Share(orderGenInput, reqOrderPolicy, resumePolicy, balancePolicy); this._state = new S1_RequestOrderState(this); }
private SimpleAsyncSweeper(ISweeper baseSweeper) { Contracts.CheckValue(baseSweeper, nameof(baseSweeper)); Contracts.CheckParam(!(baseSweeper is NelderMeadSweeper), nameof(baseSweeper), "baseSweeper cannot be Nelder-Mead"); _baseSweeper = baseSweeper; _lock = new object(); _results = new List <IRunResult>(); }
public SweepUnit_FO( long signedGoalCountFO, String code, double initEnterPrice, POrder initOrder, Account accountFO, ISweeper parent) : this(signedGoalCountFO, code, initEnterPrice, initOrder, accountFO, parent, 2) { }
public SweepUnit_OE( POrder goalOrder, Account accountFO, Account accountSpot, OptionTribe ot, ISweeper parent, Boolean bConservativeOptionPolicyOn) : this(goalOrder, accountFO, accountSpot, ot, parent, true, 2) { }
public TrainingManager(MLContext context, IEnumerable <Column> columns, Option option) { this.context = context; this.columns = columns; this.singlePipelineTrainingServiceMap = new Dictionary <IDictionary <string, string>, ITrainingService>(); this.bestIterations = new Dictionary <IDictionary <string, string>, IterationInfo>(); this.option = option; this.pipelineSweeper = context.AutoML().Serializable().Factory.CreateSweeper(this.option.ParameterSweeper); this.pipelineBuilder = new PipelineBuilder(this.option.TaskType, this.option.IsAzureAttach, true); this.Pipeline = this.pipelineBuilder.BuildPipeline(context, columns); }
public KdoSweeper(Arguments args) { _args = args; _sweepParameters = args.SweptParameters.ToArray(); _randomSweeper = new UniformRandomSweeper(new SweeperBase.ArgumentsBase(), _sweepParameters); _redundantSweeper = new UniformRandomSweeper(new SweeperBase.ArgumentsBase { Retries = 0 }, _sweepParameters); _spu = new SweeperProbabilityUtils(); _alreadySeenConfigs = new SortedSet <Float[]>(new FloatArrayComparer()); _randomParamSets = new List <ParameterSet>(); }
public SmacSweeper(IHostEnvironment env, Arguments args) { Contracts.CheckValue(env, nameof(env)); _host = env.Register("Sweeper"); _host.CheckUserArg(args.NumOfTrees > 0, nameof(args.NumOfTrees), "parameter must be greater than 0"); _host.CheckUserArg(args.NMinForSplit > 1, nameof(args.NMinForSplit), "parameter must be greater than 1"); _host.CheckUserArg(args.SplitRatio > 0 && args.SplitRatio <= 1, nameof(args.SplitRatio), "parameter must be in range (0,1]."); _host.CheckUserArg(args.NumberInitialPopulation > 1, nameof(args.NumberInitialPopulation), "parameter must be greater than 1"); _host.CheckUserArg(args.LocalSearchParentCount > 0, nameof(args.LocalSearchParentCount), "parameter must be greater than 0"); _host.CheckUserArg(args.NumRandomEISearchConfigurations > 0, nameof(args.NumRandomEISearchConfigurations), "parameter must be greater than 0"); _host.CheckUserArg(args.NumNeighborsForNumericalParams > 0, nameof(args.NumNeighborsForNumericalParams), "parameter must be greater than 0"); _args = args; _host.CheckUserArg(Utils.Size(args.SweptParameters) > 0, nameof(args.SweptParameters), "SMAC sweeper needs at least one parameter to sweep over"); _sweepParameters = args.SweptParameters.Select(p => p.CreateComponent(_host)).ToArray(); _randomSweeper = new UniformRandomSweeper(env, new SweeperBase.ArgumentsBase(), _sweepParameters); }
public SweepCommand(IHostEnvironment env, Arguments args) { Contracts.CheckValue(env, nameof(env)); env.CheckValue(args, nameof(args)); _host = env.Register("SweepCommand", args.RandomSeed); _host.CheckValue(args.Runner, nameof(args.Runner), "Please specify a runner"); _host.CheckValue(args.Sweeper, nameof(args.Sweeper), "Please specify a sweeper"); _host.CheckUserArg(args.SweepNumBatches > 0, nameof(args.SweepNumBatches), "Must be positive"); _host.CheckUserArg(!(args.InitialSweepBatchSize <= 0), nameof(args.InitialSweepBatchSize), "Must be positive if specified"); _host.CheckUserArg(args.SweepBatchSize > 0, nameof(args.SweepBatchSize), "Must be positive"); _numBatches = args.SweepNumBatches; _initBatchSize = args.InitialSweepBatchSize ?? args.SweepBatchSize; _batchSize = args.SweepBatchSize; _runner = args.Runner.CreateComponent(_host); _sweeper = args.Sweeper.CreateComponent(_host); }
public SweepUnitContext_FO( long signedGoalCountFO, String code, double initEnterPrice, POrder initOrder, Account accountFO, ISweeper sweeper) { this.RealOrders = new List<POrder>(); this.ID = SweepUnitIDManager.NextID++; this.InitSignedGoalCount = this.CurSignedTargetCount = signedGoalCountFO; this.Code = code; this._initEnterPrice = initEnterPrice; this._initOrder = initOrder; this.AccountFO = accountFO; this._sweeper = sweeper; }
public GaussProcessSweeper(Option option) { this._option = option; this._generated = new HashSet <IDictionary <string, string> >(); this._runHistory = new List <IRunResult>(); var randomSweeperOption = new UniformRandomSweeper.Option() { Retry = option.Retry, }; this._randomSweeper = new UniformRandomSweeper(randomSweeperOption); var gpOption = new GaussProcessRegressor.Options() { l = option.L, sigma = option.Sigma, noise = option.Noise, }; this._regressor = new GaussProcessRegressor(gpOption); }
public KdoSweeper(IHostEnvironment env, Arguments args) { Contracts.CheckValue(env, nameof(env)); _host = env.Register("Sweeper"); _host.CheckUserArg(args.NumberInitialPopulation > 1, nameof(args.NumberInitialPopulation), "Must be greater than 1"); _host.CheckUserArg(args.HistoryLength > 1, nameof(args.HistoryLength), "Must be greater than 1"); _host.CheckUserArg(args.MinimumMutationSpread >= 0, nameof(args.MinimumMutationSpread), "Must be nonnegative"); _host.CheckUserArg(0 <= args.ProportionRandom && args.ProportionRandom <= 1, nameof(args.ProportionRandom), "Must be in [0, 1]"); _host.CheckUserArg(args.WeightRescalingPower >= 1, nameof(args.WeightRescalingPower), "Must be greater or equal to 1"); _args = args; _host.CheckUserArg(Utils.Size(args.SweptParameters) > 0, nameof(args.SweptParameters), "KDO sweeper needs at least one parameter to sweep over"); _sweepParameters = args.SweptParameters.Select(p => p.CreateComponent(_host)).ToArray(); _randomSweeper = new UniformRandomSweeper(env, new SweeperBase.ArgumentsBase(), _sweepParameters); _redundantSweeper = new UniformRandomSweeper(env, new SweeperBase.ArgumentsBase { Retries = 0 }, _sweepParameters); _spu = new SweeperProbabilityUtils(_host); _alreadySeenConfigs = new SortedSet <Float[]>(new FloatArrayComparer()); _randomParamSets = new List <ParameterSet>(); }
public DeterministicSweeperAsync(IHostEnvironment env, Arguments args) { _host = env.Register("DeterministicSweeperAsync", args.RandomSeed); _host.CheckValue(args.Sweeper, nameof(args.Sweeper), "Please specify a sweeper"); _host.CheckUserArg(args.BatchSize > 0, nameof(args.BatchSize), "Batch size must be positive"); _host.CheckUserArg(args.Relaxation >= 0, nameof(args.Relaxation), "Synchronization relaxation must be non-negative"); _host.CheckUserArg(args.Relaxation <= args.BatchSize, nameof(args.Relaxation), "Synchronization relaxation cannot be larger than batch size"); _batchSize = args.BatchSize; _baseSweeper = args.Sweeper.CreateComponent(_host); _host.CheckUserArg(!(_baseSweeper is NelderMeadSweeper) || args.Relaxation == 0, nameof(args.Relaxation), "Nelder-Mead requires full synchronization (relaxation = 0)"); _cts = new CancellationTokenSource(); _relaxation = args.Relaxation; _lock = new object(); _results = new List <IRunResult>(); _nullRuns = new HashSet <int>(); _paramQueue = new BufferBlock <ParameterSetWithId>(); PrepareNextBatch(null); }
public SweepUnitTemplate( ISweepUnitContext context, ISweeper sweeper, int muteSec) { this.Context = context; this._sweeper = sweeper; this._muteSec = muteSec; this.ID = SweepUnitIDManager.NextID++; this._bResumed = false; this._bCompleteQuickly = false; Context.RequestInitOrders(); Context.AfterRequestInitOrders(); this._mute = new Timer(muteSec, ""); this.CurState = StateEnum._1_MuteFewSecsAfterInitOrders; this.CurOverviewState = OverviewState.Enter; }
public NelderMeadSweeper(IHostEnvironment env, Arguments args) { Contracts.CheckValue(env, nameof(env)); env.CheckUserArg(-1 < args.DeltaInsideContraction, nameof(args.DeltaInsideContraction), "Must be greater than -1"); env.CheckUserArg(args.DeltaInsideContraction < 0, nameof(args.DeltaInsideContraction), "Must be less than 0"); env.CheckUserArg(0 < args.DeltaOutsideContraction, nameof(args.DeltaOutsideContraction), "Must be greater than 0"); env.CheckUserArg(args.DeltaReflection > args.DeltaOutsideContraction, nameof(args.DeltaReflection), "Must be greater than " + nameof(args.DeltaOutsideContraction)); env.CheckUserArg(args.DeltaExpansion > args.DeltaReflection, nameof(args.DeltaExpansion), "Must be greater than " + nameof(args.DeltaReflection)); env.CheckUserArg(0 < args.GammaShrink && args.GammaShrink < 1, nameof(args.GammaShrink), "Must be between 0 and 1"); env.CheckValue(args.FirstBatchSweeper, nameof(args.FirstBatchSweeper), "First Batch Sweeper Contains Null Value"); _args = args; _sweepParameters = new List <IValueGenerator>(); foreach (var sweptParameter in args.SweptParameters) { var parameter = sweptParameter.CreateComponent(env); // REVIEW: ideas about how to support discrete values: // 1. assign each discrete value a random number (1-n) to make mirroring possible // 2. each time we need to mirror a discrete value, sample from the remaining value // 2.1. make the sampling non-uniform by learning "weights" for the different discrete values based on // the metric values that we get when using them. (For example, if, for a given discrete value, we get a bad result, // we lower its weight, but if we get a good result we increase its weight). var parameterNumeric = parameter as INumericValueGenerator; env.CheckUserArg(parameterNumeric != null, nameof(args.SweptParameters), "Nelder-Mead sweeper can only sweep over numeric parameters"); _sweepParameters.Add(parameterNumeric); } _initSweeper = args.FirstBatchSweeper.CreateComponent(env, _sweepParameters.ToArray()); _dim = _sweepParameters.Count; env.CheckUserArg(_dim > 1, nameof(args.SweptParameters), "Nelder-Mead sweeper needs at least two parameters to sweep over."); _simplexVertices = new SortedList <IRunResult, Float[]>(new SimplexVertexComparer()); _stage = OptimizationStage.NeedReflectionPoint; _pendingSweeps = new List <KeyValuePair <ParameterSet, Float[]> >(); _pendingSweepsNotSubmitted = new Queue <KeyValuePair <ParameterSet, Float[]> >(); }
public SweepUnitContext_Bond_Long_StartWithDone( RemainPositionDatum datum, Account bondAccount, ISweeper sweeper) { this.ID = SweepUnitIDManager.NextID++; this.LongShort = TradingDirection.Long; this.InitSignedGoalCount = datum.CurTargetCount; this.CurSignedTargetCount = datum.CurTargetCount; this.EnterCode = datum.EnterCodeWithMarketType; this._initEnterPrice = datum.EnterPrice; this.BondAccount = bondAccount; this._enterMarketType = BondUtil.GetMarketType(this.EnterCode); this._sweeper = sweeper; this._signedContractedCount = datum.CurTargetCount; this._signedBookValue = (long)(datum.EnterPrice * datum.CurTargetCount); }
public SmacSweeper(Arguments args) { _args = args; _sweepParameters = args.SweptParameters; _randomSweeper = new UniformRandomSweeper(new SweeperBase.ArgumentsBase(), _sweepParameters); }
void LiveToDone(ISweeper sweeper) { _live.Remove(sweeper); _done.Add(sweeper); }
public void Add(ISweeper sweeper) { _live.Add(sweeper); _thisTurn.Add(sweeper); }
public SweepUnitTemplate(ISweepUnitContext context, ISweeper sweeper) : this(context, sweeper, 2) { }
protected void SampleHyperparameters(RecipeInference.SuggestedRecipe.SuggestedLearner learner, ISweeper sweeper, bool isMaximizingMetric, PipelinePattern[] history) { // Make sure there are hyperparameters to sweep over. var hyperParams = learner.PipelineNode.SweepParams; if (hyperParams.Length == 0) { return; } // Get new set of hyperparameter values. var proposedParamSet = sweeper.ProposeSweeps(1, AutoMlUtils.ConvertToRunResults(history, isMaximizingMetric)).First(); Env.Assert(proposedParamSet != null && proposedParamSet.All(ps => hyperParams.Any(hp => hp.Name == ps.Name))); // Associate proposed param set with learner, so that smart hyperparam // sweepers (like KDO) can map them back. learner.PipelineNode.HyperSweeperParamSet = proposedParamSet; var generatorSet = hyperParams.Select(AutoMlUtils.ToIValueGenerator).ToArray(); var values = SweeperProbabilityUtils.ParameterSetAsFloatArray(Host, generatorSet, proposedParamSet, false); // Update hyperparameters. for (int i = 0; i < hyperParams.Length; i++) { if (hyperParams[i] is TlcModule.SweepableDiscreteParamAttribute dp) { hyperParams[i].RawValue = (int)values[i]; } else { hyperParams[i].RawValue = values[i]; } } }
public void Add(ISweeper sweeper) { _liveSweepers.Add(IdGenerator++, sweeper); }