当前位置: 首页>>代码示例>>C#>>正文


C# IAlgorithm类代码示例

本文整理汇总了C#中IAlgorithm的典型用法代码示例。如果您正苦于以下问题:C# IAlgorithm类的具体用法?C# IAlgorithm怎么用?C# IAlgorithm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IAlgorithm类属于命名空间,在下文中一共展示了IAlgorithm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FileSystemDataFeed

        /********************************************************
        * CLASS CONSTRUCTOR
        *********************************************************/
        /// <summary>
        /// Create a new backtesting data feed.
        /// </summary>
        /// <param name="algorithm">Instance of the algorithm</param>
        /// <param name="job">Algorithm work task</param>
        public FileSystemDataFeed(IAlgorithm algorithm, BacktestNodePacket job)
        {
            Subscriptions = algorithm.SubscriptionManager.Subscriptions;
            _subscriptions = Subscriptions.Count;

            //Public Properties:
            DataFeed = DataFeedEndpoint.FileSystem;
            IsActive = true;
            Bridge = new ConcurrentQueue<List<BaseData>>[_subscriptions];
            EndOfBridge = new bool[_subscriptions];
            SubscriptionReaders = new SubscriptionDataReader[_subscriptions];
            FillForwardFrontiers = new DateTime[_subscriptions];
            RealtimePrices = new List<decimal>(_subscriptions);

            //Class Privates:
            _job = job;
            _algorithm = algorithm;
            _endOfStreams = false;
            _bridgeMax = _bridgeMax / _subscriptions; //Set the bridge maximum count:

            for (var i = 0; i < _subscriptions; i++)
            {
                //Create a new instance in the dictionary:
                Bridge[i] = new ConcurrentQueue<List<BaseData>>();
                EndOfBridge[i] = false;
                SubscriptionReaders[i] = new SubscriptionDataReader(Subscriptions[i], _algorithm.Securities[Subscriptions[i].Symbol], DataFeed, _job.PeriodStart, _job.PeriodFinish);
                FillForwardFrontiers[i] = new DateTime();
            }
        }
开发者ID:sopnic,项目名称:Lean,代码行数:37,代码来源:FileSystemDataFeed.cs

示例2: Approach

 public Approach(string title, int warmupRounds, int benchmarkRounds, IAlgorithm algorithm)
 {
     Title = title;
     WarmupRounds = warmupRounds;
     BenchmarkRounds = benchmarkRounds;
     Algorithm = algorithm;
 }
开发者ID:cthibault,项目名称:projecteuler,代码行数:7,代码来源:Approach.cs

示例3: UpdateKnn

        /// <summary>
        /// Missing mapping to P objects
        /// KdTree could be refactored to use P object instead of Math.Net
        /// 
        /// O(k * log n) 
        /// </summary>
        /// <param name="s"></param>
        /// <param name="origin"></param>
        /// <param name="k"></param>
        /// <param name="conf"></param>        
        /// <returns></returns>
        public long UpdateKnn(IAlgorithm s, IP origin, KnnConfiguration conf)
        {
            if (conf == null) conf = new KnnConfiguration();
            if (conf.SameTypeOnly) throw new NotImplementedException();
            if (conf.MaxDistance.HasValue) throw new NotImplementedException();

            var sw = new Stopwatch();
            sw.Start();

            var vector = new DenseVector(new[] { origin.X, origin.Y });
            var nn = Tree.FindNearestNNeighbors(vector, conf.K).ToList();

            s.Knn.Clear();
            s.Knn.Origin = origin;
            s.Knn.K = conf.K;
            foreach (var i in nn)
            {
                var p = new P { X = i[0], Y = i[1] };
                var dist = origin.Distance(p.X,p.Y);
                s.Knn.NNs.Add(new PDist {Point = p, Distance = dist});
            }

            sw.Stop();
            return sw.ElapsedMilliseconds;
        }
开发者ID:kunukn,项目名称:single-detect,代码行数:36,代码来源:KdTreeStrategy.cs

示例4: UpdateSingles

        /// <summary>
        ///  O(n^2)
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public long UpdateSingles(IAlgorithm s)
        {
            var sw = new Stopwatch();
            sw.Start();

            s.Singles.Clear();

            var n = s.Points.Count;
            for (var i = 0; i < n; i++)
            {
                var p1 = s.Points[i];
                var add = true;
                for (var j = 0; j < n; j++)
                {
                    if (i == j) continue;

                    var p2 = s.Points[j];
                    var dist = p1.Distance(p2.X, p2.Y);
                    if (!(dist > s.Rectangle.MaxDistance))
                    {
                        add = false;
                        break;
                    }
                }
                if (add) s.Singles.Add(p1);
            }

            sw.Stop();
            return sw.ElapsedMilliseconds;
        }
开发者ID:kunukn,项目名称:single-detect,代码行数:35,代码来源:NaiveStrategy.cs

示例5: DataPlanner

        /// <summary>
        /// Initializes a new instance of the <see cref="DataPlanner&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="algorithm">The algorithm.</param>
        public DataPlanner(IAlgorithm algorithm)
        {
            if (algorithm == null)
                throw new ArgumentNullException("algorithm");

            m_Algorithm = algorithm;
        }
开发者ID:pavkam,项目名称:school,代码行数:11,代码来源:DataPlanner.cs

示例6: Initialize

        public void Initialize(IAlgorithm algorithm, AlgorithmNodePacket job, IResultHandler resultHandler, IMapFileProvider mapFileProvider)
        {
            if (algorithm.SubscriptionManager.Subscriptions.Count == 0 && algorithm.Universes.IsNullOrEmpty())
            {
                throw new Exception("No subscriptions registered and no universe defined.");
            }

            _algorithm = algorithm;
            _resultHandler = resultHandler;
            _mapFileProvider = mapFileProvider;
            _subscriptions = new ConcurrentDictionary<Symbol, Subscription>();
            _cancellationTokenSource = new CancellationTokenSource();

            IsActive = true;
            Bridge = new BusyBlockingCollection<TimeSlice>(100);

            var ffres = Time.OneSecond;
            _fillForwardResolution = Ref.Create(() => ffres, res => ffres = res);

            // find the minimum resolution, ignoring ticks
            ffres = ResolveFillForwardResolution(algorithm);

            // add each universe selection subscription to the feed
            foreach (var universe in _algorithm.Universes)
            {
                var startTimeUtc = _algorithm.StartDate.ConvertToUtc(_algorithm.TimeZone);
                var endTimeUtc = _algorithm.EndDate.ConvertToUtc(_algorithm.TimeZone);
                AddUniverseSubscription(universe, startTimeUtc, endTimeUtc);
            }
        }
开发者ID:tremblayEric,项目名称:LeanHistory,代码行数:30,代码来源:FileSystemDataFeed.cs

示例7: TagCloudBuilder

 public TagCloudBuilder(IWordsReader reader, IAlgorithm algorithm, IImageWriter writer, IWordsFilter filter)
 {
     this.filter = filter;
     this.reader = reader;
     this.algorithm = algorithm;
     this.writer = writer;
 }
开发者ID:MyauMyauMyau,项目名称:03-design-hw,代码行数:7,代码来源:TagCloudBuilder.cs

示例8: HomeController

 public HomeController(IAlgorithm algorithm, IArrayRepository arrayRepository, IParametersRepository parametersRepository, IResultRepository resultRepository)
 {
     Algorithm = algorithm;
     _arrayRepository = arrayRepository;
     _parametersRepository = parametersRepository;
     _resultRepository = resultRepository;
 }
开发者ID:LexaGal,项目名称:MVC-1,代码行数:7,代码来源:HomeController.cs

示例9: TagCloudBuilder

 public TagCloudBuilder(IWordsReader reader, IWordNormalizer normalizer, IWordFilter filter, IAlgorithm algorithm)
 {
     this.reader = reader;
     this.normalizer = normalizer;
     this.filter = filter;
     this.algorithm = algorithm;
 }
开发者ID:KuchumovIlya,项目名称:03-design-hw,代码行数:7,代码来源:TagCloudBuilder.cs

示例10: TestLiveTradingDataFeed

 /// <summary>
 /// Creates a test live trading data feed with the specified fast forward factor
 /// </summary>
 /// <param name="algorithm">The algorithm under analysis</param>
 /// <param name="job">The job for the algorithm</param>
 public TestLiveTradingDataFeed(IAlgorithm algorithm, LiveNodePacket job)
     : base(algorithm, job)
 {
     _start = DateTime.Now;
     _current = DateTime.Now;
     _tickResolution = TimeSpan.FromSeconds(1);
 }
开发者ID:intelliBrain,项目名称:Lean,代码行数:12,代码来源:TestLiveTradingDataFeed.cs

示例11: LiveTradingDataFeed

        /********************************************************
        * CLASS CONSTRUCTOR
        *********************************************************/
        /// <summary>
        /// Live trading datafeed handler provides a base implementation of a live trading datafeed. Derived types
        /// need only implement the GetNextTicks() function to return unprocessed ticks from a data source.
        /// This creates a new data feed with a DataFeedEndpoint of LiveTrading.
        /// </summary>
        /// <param name="algorithm">Algorithm requesting data</param>
        protected LiveTradingDataFeed(IAlgorithm algorithm)
        {
            //Subscription Count:
            _subscriptions = algorithm.SubscriptionManager.Subscriptions;

            //Set Properties:
            _dataFeed = DataFeedEndpoint.LiveTrading;
            _isActive = true;
            _bridge = new ConcurrentQueue<List<BaseData>>[Subscriptions.Count];
            _endOfBridge = new bool[Subscriptions.Count];
            _subscriptionManagers = new SubscriptionDataReader[Subscriptions.Count];
            _realtimePrices = new List<decimal>();

            //Class Privates:
            _algorithm = algorithm;

            //Setup the arrays:
            for (var i = 0; i < Subscriptions.Count; i++)
            {
                _endOfBridge[i] = false;
                _bridge[i] = new ConcurrentQueue<List<BaseData>>();

                //This is quantconnect data source, store here for speed/ease of access
                _isDynamicallyLoadedData.Add(algorithm.Securities[_subscriptions[i].Symbol].IsDynamicallyLoadedData);

                //Subscription managers for downloading user data:
                _subscriptionManagers[i] = new SubscriptionDataReader(_subscriptions[i], algorithm.Securities[_subscriptions[i].Symbol], DataFeedEndpoint.LiveTrading, DateTime.MinValue, DateTime.MaxValue);

                //Set up the source file for today:
                _subscriptionManagers[i].RefreshSource(DateTime.Now.Date);

                _realtimePrices.Add(0);
            }
        }
开发者ID:intelliBrain,项目名称:Lean,代码行数:43,代码来源:LiveTradingDataFeed.cs

示例12: Run

 /// <summary>
 /// Runs this command against the specified algorithm instance
 /// </summary>
 /// <param name="algorithm">The algorithm to run this command against</param>
 public CommandResultPacket Run(IAlgorithm algorithm)
 {
     var ticket = algorithm.Transactions.CancelOrder(OrderId);
     return ticket.CancelRequest != null 
         ? new Result(this, true, ticket.QuantityFilled) 
         : new Result(this, false, ticket.QuantityFilled);
 }
开发者ID:skyfyl,项目名称:Lean,代码行数:11,代码来源:CancelOrderCommand.cs

示例13: EveryAlgorithmEndOfDay

        /// <summary>
        /// Creates a new <see cref="ScheduledEvent"/> that will fire before market close by the specified time 
        /// </summary>
        /// <param name="algorithm">The algorithm instance the event is fo</param>
        /// <param name="resultHandler">The result handler, used to communicate run time errors</param>
        /// <param name="start">The date to start the events</param>
        /// <param name="end">The date to end the events</param>
        /// <param name="endOfDayDelta">The time difference between the market close and the event, positive time will fire before market close</param>
        /// <param name="currentUtcTime">Specfies the current time in UTC, before which, no events will be scheduled. Specify null to skip this filter.</param>
        /// <returns>The new <see cref="ScheduledEvent"/> that will fire near market close each tradeable dat</returns>
        public static ScheduledEvent EveryAlgorithmEndOfDay(IAlgorithm algorithm, IResultHandler resultHandler, DateTime start, DateTime end, TimeSpan endOfDayDelta, DateTime? currentUtcTime = null)
        {
            if (endOfDayDelta >= Time.OneDay)
            {
                throw new ArgumentException("Delta must be less than a day", "endOfDayDelta");
            }

            // set up an event to fire every tradeable date for the algorithm as a whole
            var eodEventTime = Time.OneDay.Subtract(endOfDayDelta);

            // create enumerable of end of day in algorithm's time zone
            var times =
                // for every date any exchange is open in the algorithm
                from date in Time.EachTradeableDay(algorithm.Securities.Values, start, end)
                // define the time of day we want the event to fire, a little before midnight
                let eventTime = date + eodEventTime
                // convert the event time into UTC
                let eventUtcTime = eventTime.ConvertToUtc(algorithm.TimeZone)
                // perform filter to verify it's not before the current time
                where !currentUtcTime.HasValue || eventUtcTime > currentUtcTime.Value
                select eventUtcTime;

            return new ScheduledEvent(CreateEventName("Algorithm", "EndOfDay"), times, (name, triggerTime) =>
            {
                try
                {
                    algorithm.OnEndOfDay();
                }
                catch (Exception err)
                {
                    resultHandler.RuntimeError(String.Format("Runtime error in {0} event: {1}", name, err.Message), err.StackTrace);
                    Log.Error(err, string.Format("ScheduledEvent.{0}:", name));
                }
            });
        }
开发者ID:AlexCatarino,项目名称:Lean,代码行数:45,代码来源:ScheduledEventFactory.cs

示例14: BacktestingRealTimeHandler

 /********************************************************
 * PUBLIC CONSTRUCTOR
 *********************************************************/
 /// <summary>
 /// Setup the algorithm data, cash, job start end date etc.
 /// </summary>
 public BacktestingRealTimeHandler(IAlgorithm algorithm, AlgorithmNodePacket job)
 {
     //Initialize:
     _algorithm = algorithm;
     _events = new List<RealTimeEvent>();
     _job = job;
 }
开发者ID:intelliBrain,项目名称:Lean,代码行数:13,代码来源:BacktestingRealTimeHandler.cs

示例15: BaseDataFeed

        /********************************************************
        * CLASS CONSTRUCTOR
        *********************************************************/
        /// <summary>
        /// Create an instance of the base datafeed.
        /// </summary>
        public BaseDataFeed(IAlgorithm algorithm, BacktestNodePacket job)
        {
            //Save the data subscriptions
            Subscriptions = algorithm.SubscriptionManager.Subscriptions;
            _subscriptions = Subscriptions.Count;

            //Public Properties:
            DataFeed = DataFeedEndpoint.FileSystem;
            IsActive = true;
            Bridge = new ConcurrentQueue<List<BaseData>>[_subscriptions];
            EndOfBridge = new bool[_subscriptions];
            SubscriptionReaderManagers = new SubscriptionDataReader[_subscriptions];
            RealtimePrices = new List<decimal>(_subscriptions);
            _frontierTime = new DateTime[_subscriptions];

            //Class Privates:
            _job = job;
            _algorithm = algorithm;
            _endOfStreams = false;
            _bridgeMax = _bridgeMax / _subscriptions;

            //Initialize arrays:
            for (var i = 0; i < _subscriptions; i++)
            {
                _frontierTime[i] = job.PeriodStart;
                EndOfBridge[i] = false;
                Bridge[i] = new ConcurrentQueue<List<BaseData>>();
                SubscriptionReaderManagers[i] = new SubscriptionDataReader(Subscriptions[i], algorithm.Securities[Subscriptions[i].Symbol], DataFeedEndpoint.Database, job.PeriodStart, job.PeriodFinish);
            }
        }
开发者ID:sopnic,项目名称:Lean,代码行数:36,代码来源:BaseDataFeed.cs


注:本文中的IAlgorithm类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。