/* * 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 Newtonsoft.Json; using QuantConnect.Statistics; using System.Collections.Generic; using QuantConnect.Optimizer.Parameters; using QuantConnect.Util; namespace QuantConnect.Api { /// /// A power gauge for backtests, time and parameters to estimate the overfitting risk /// public class ResearchGuide { /// /// Number of minutes used in developing the current backtest /// public int Minutes { get; set; } /// /// The quantity of backtests run in the project /// public int BacktestCount { get; set; } /// /// Number of parameters detected /// public int Parameters { get; set; } /// /// Project ID /// public int ProjectId { get; set; } } /// /// Base class for backtest result object response /// public class BasicBacktest : RestResponse { /// /// Backtest error message /// public string Error { get; set; } /// /// Backtest error stacktrace /// public string Stacktrace { get; set; } /// /// Assigned backtest Id /// public string BacktestId { get; set; } /// /// Status of the backtest /// public string Status { get; set; } /// /// Name of the backtest /// public string Name { get; set; } /// /// Backtest creation date and time /// [JsonConverter(typeof(DateTimeJsonConverter), DateFormat.UI)] public DateTime Created { get; set; } /// /// Progress of the backtest in percent 0-1. /// public decimal Progress { get; set; } /// /// Optimization task ID, if the backtest is part of an optimization /// public string OptimizationId { get; set; } /// /// Number of tradeable days /// public int TradeableDates { get; set; } /// /// Optimization parameters /// public ParameterSet ParameterSet { get; set; } /// /// Snapshot id of this backtest result /// public int SnapShotId { get; set; } } /// /// Results object class. Results are exhaust from backtest or live algorithms running in LEAN /// public class Backtest : BasicBacktest { /// /// Note on the backtest attached by the user /// public string Note { get; set; } /// /// Boolean true when the backtest is completed. /// public bool Completed { get; set; } /// /// Organization ID /// public string OrganizationId { get; set; } /// /// Rolling window detailed statistics. /// [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] public Dictionary RollingWindow { get; set; } /// /// Total algorithm performance statistics. /// [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] public AlgorithmPerformance TotalPerformance { get; set; } /// /// Charts updates for the live algorithm since the last result packet /// [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] public IDictionary Charts { get; set; } /// /// Statistics information sent during the algorithm operations. /// /// Intended for update mode -- send updates to the existing statistics in the result GUI. If statistic key does not exist in GUI, create it [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] public IDictionary Statistics { get; set; } /// /// Runtime banner/updating statistics in the title banner of the live algorithm GUI. /// [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] public IDictionary RuntimeStatistics { get; set; } /// /// A power gauge for backtests, time and parameters to estimate the overfitting risk /// public ResearchGuide ResearchGuide { get; set; } /// /// The starting time of the backtest /// public DateTime? BacktestStart { get; set; } /// /// The ending time of the backtest /// public DateTime? BacktestEnd { get; set; } /// /// Indicates if the backtest has error during initialization /// public bool HasInitializeError { get; set; } /// /// The backtest node name /// public string NodeName { get; set; } /// /// The associated project id /// public int ProjectId { get; set; } /// /// End date of out of sample data /// public DateTime? OutOfSampleMaxEndDate { get; set; } /// /// Number of days of out of sample days /// public int? OutOfSampleDays { get; set; } } /// /// Result object class for the List Backtest response from the API /// public class BacktestSummary : BasicBacktest { /// /// Sharpe ratio with respect to risk free rate: measures excess of return per unit of risk /// public decimal? SharpeRatio { get; set; } /// /// Algorithm "Alpha" statistic - abnormal returns over the risk free rate and the relationshio (beta) with the benchmark returns /// public decimal? Alpha { get; set; } /// /// Algorithm "beta" statistic - the covariance between the algorithm and benchmark performance, divided by benchmark's variance /// public decimal? Beta { get; set; } /// /// Annual compounded returns statistic based on the final-starting capital and years /// public decimal? CompoundingAnnualReturn { get; set; } /// /// Drawdown maximum percentage /// public decimal? Drawdown { get; set; } /// /// The ratio of the number of losing trades to the total number of trades /// public decimal? LossRate { get; set; } /// /// Net profit percentage /// public decimal? NetProfit { get; set; } /// /// Number of parameters in the backtest /// public int? Parameters { get; set; } /// /// Price-to-sales ratio /// public decimal? Psr { get; set; } /// /// SecurityTypes present in the backtest /// public string? SecurityTypes { get; set; } /// /// Sortino ratio with respect to risk free rate: measures excess of return per unit of downside risk /// public decimal? SortinoRatio { get; set; } /// /// Number of trades in the backtest /// public int? Trades { get; set; } /// /// Treynor ratio statistic is a measurement of the returns earned in excess of that which could have been earned on an investment that has no diversifiable risk /// public decimal? TreynorRatio { get; set; } /// /// The ratio of the number of winning trades to the total number of trades /// public decimal? WinRate { get; set; } /// /// Collection of tags for the backtest /// public List Tags { get; set; } } /// /// Wrapper class for Backtest/* endpoints JSON response /// Currently used by Backtest/Read and Backtest/Create /// public class BacktestResponseWrapper : RestResponse { /// /// Backtest Object /// public Backtest Backtest { get; set; } /// /// Indicates if the backtest is run under debugging mode /// public bool Debugging { get; set; } } /// /// Collection container for a list of backtests for a project /// public class BacktestList : RestResponse { /// /// Collection of summarized backtest objects /// public List Backtests { get; set; } } /// /// Collection container for a list of backtest summaries for a project /// public class BacktestSummaryList : RestResponse { /// /// Collection of summarized backtest summary objects /// public List Backtests { get; set; } /// /// Number of backtest summaries retrieved in the response /// public int Count { get; set; } } /// /// Collection container for a list of backtest tags /// public class BacktestTags : RestResponse { /// /// Collection of tags for a backtest /// public List Tags { get; set; } } }