/* * 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.Collections.Generic; using QuantConnect.Algorithm.Framework; using QuantConnect.Algorithm.Framework.Alphas; using QuantConnect.Algorithm.Framework.Execution; using QuantConnect.Algorithm.Framework.Portfolio; using QuantConnect.Algorithm.Framework.Risk; using QuantConnect.Algorithm.Framework.Selection; namespace QuantConnect.Algorithm.CSharp { /// /// Show cases how to use the to define /// public class CompositeAlphaModelFrameworkAlgorithm : QCAlgorithmFramework, IRegressionAlgorithmDefinition { public override void Initialize() { SetStartDate(2013, 10, 07); SetEndDate(2013, 10, 11); // even though we're using a framework algorithm, we can still add our securities // using the AddEquity/Forex/Crypto/ect methods and then pass them into a manual // universe selection model using Securities.Keys AddEquity("SPY"); AddEquity("IBM"); AddEquity("BAC"); AddEquity("AIG"); // define a manual universe of all the securities we manually registered SetUniverseSelection(new ManualUniverseSelectionModel(Securities.Keys)); // define alpha model as a composite of the rsi and ema cross models SetAlpha(new CompositeAlphaModel( new RsiAlphaModel(), new EmaCrossAlphaModel() )); // default models for the rest SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel()); SetExecution(new ImmediateExecutionModel()); SetRiskManagement(new NullRiskManagementModel()); } /// /// This is used by the regression test system to indicate which languages this algorithm is written in. /// public Language[] Languages { get; } = {Language.CSharp, Language.Python}; /// /// This is used by the regression test system to indicate what the expected statistics are from running the algorithm /// public Dictionary ExpectedStatistics => new Dictionary { {"Total Trades", "468"}, {"Average Win", "0.06%"}, {"Average Loss", "-0.04%"}, {"Compounding Annual Return", "-96.930%"}, {"Drawdown", "4.500%"}, {"Expectancy", "-0.490"}, {"Net Profit", "-4.356%"}, {"Sharpe Ratio", "-26.255"}, {"Loss Rate", "81%"}, {"Win Rate", "19%"}, {"Profit-Loss Ratio", "1.75"}, {"Alpha", "-1.975"}, {"Beta", "-23.261"}, {"Annual Standard Deviation", "0.085"}, {"Annual Variance", "0.007"}, {"Information Ratio", "-26.372"}, {"Tracking Error", "0.085"}, {"Treynor Ratio", "0.096"}, {"Total Fees", "$2215.48"}, {"Total Insights Generated", "289"}, {"Total Insights Closed", "0"}, {"Total Insights Analysis Completed", "0"}, {"Long Insight Count", "146"}, {"Short Insight Count", "143"}, {"Long/Short Ratio", "102.10%"}, {"Estimated Monthly Alpha Value", "$0"}, {"Total Accumulated Estimated Alpha Value", "$0"}, {"Mean Population Estimated Insight Value", "$0"}, {"Mean Population Direction", "0%"}, {"Mean Population Magnitude", "0%"}, {"Rolling Averaged Population Direction", "0%"}, {"Rolling Averaged Population Magnitude", "0%"}, }; } }