/// <summary>
        /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
        /// </summary>
        public override void Initialize()
        {
            // Set requested data resolution
            UniverseSettings.Resolution = Resolution.Minute;
            // Note: Config.GetInt( "LBL-minute-resolution" ) is available to use for consolidators

            // Set start and end date
            SetStartDate(DateTime.Parse(Config.Get("LBL-start-date")));
            SetEndDate(DateTime.Parse(Config.Get("LBL-end-date")));

            // Set universe
            SetUniverseSelection(new ManualUniverseSelectionModel(QuantConnect.Symbol.Create(Config.Get("LBL-symbol"), SecurityType.Forex, Market.Oanda)));

            // Get alpha parameters
            int fastEma = Config.GetInt("LBL-ema-fast");
            int slowEma = Config.GetInt("LBL-ema-slow");

            // Initialise available alphas
            var availableAlphas = new IAlphaModel[] {
                new EmaCrossAlphaModel(fastEma, slowEma, Resolution.Minute)
            };

            // Set the alpha, for now we're assuming "ALL" has been passed
            if (Config.Get("LBL-alpha-model-name") == "ALL")
            {
                SetAlpha(new CompositeAlphaModel(availableAlphas));
            }

            // Set remaining models
            SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel());
            SetExecution(new ImmediateExecutionModel());
            SetRiskManagement(new NullRiskManagementModel());
        }
Esempio n. 2
0
        private bool TryCreateModel(Language language, out IAlphaModel model)
        {
            model = default(IAlphaModel);

            try
            {
                switch (language)
                {
                case Language.CSharp:
                    model = CreateCSharpAlphaModel();
                    return(true);

                case Language.Python:
                    _algorithm.SetPandasConverter();
                    model = CreatePythonAlphaModel();
                    return(true);

                default:
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the name of the alpha model
        /// </summary>
        public static string GetModelName(this IAlphaModel model)
        {
            var namedModel = model as INamedModel;

            if (namedModel != null)
            {
                return(namedModel.Name);
            }

            return(model.GetType().Name);
        }
Esempio n. 4
0
 /// <summary>
 /// Adds a new alpha model
 /// </summary>
 /// <param name="alpha">Model that generates alpha to add</param>
 public void AddAlpha(IAlphaModel alpha)
 {
     if (Alpha.GetType() != typeof(NullAlphaModel))
     {
         var compositeAlphaModel = Alpha as CompositeAlphaModel;
         if (compositeAlphaModel != null)
         {
             compositeAlphaModel.AddAlpha(alpha);
         }
         else
         {
             Alpha = new CompositeAlphaModel(Alpha, alpha);
         }
     }
     else
     {
         Alpha = alpha;
     }
 }
Esempio n. 5
0
 /// <summary>
 /// To be override for model types that implement <see cref="INamedModel"/>
 /// </summary>
 protected abstract string GetExpectedModelName(IAlphaModel model);
Esempio n. 6
0
 /// <summary>
 /// Sets the alpha model
 /// </summary>
 /// <param name="alpha">Model that generates alpha</param>
 public void SetAlpha(IAlphaModel alpha)
 {
     Alpha = alpha;
 }
 protected override string GetExpectedModelName(IAlphaModel model)
 {
     return($"{nameof(MacdAlphaModel)}(12,26,9,Exponential,Daily)");
 }
 protected override string GetExpectedModelName(IAlphaModel model)
 {
     return($"{nameof(PairsTradingAlphaModel)}(BAC,AIG,1)");
 }
Esempio n. 9
0
        public void AddAlphaModel(Language language)
        {
            IAlphaModel model;
            IAlphaModel model2 = null;
            IAlphaModel model3 = null;

            if (!TryCreateModel(language, out model) ||
                !TryCreateModel(language, out model2) ||
                !TryCreateModel(language, out model3))
            {
                Assert.Ignore($"Ignore {GetType().Name}: Could not create {language} model.");
            }

            // Set the alpha model
            Algorithm.SetAlpha(model);
            Algorithm.AddAlpha(model2);
            Algorithm.AddAlpha(model3);
            Algorithm.SetUniverseSelection(new ManualUniverseSelectionModel());

            var changes = new SecurityChanges(AddedSecurities, RemovedSecurities);

            Algorithm.OnFrameworkSecuritiesChanged(changes);

            var actualInsights = new List <Insight>();

            Algorithm.InsightsGenerated += (s, e) => actualInsights.AddRange(e.Insights);

            var expectedInsights = ExpectedInsights().ToList();

            var consolidators = Algorithm.Securities.SelectMany(kvp => kvp.Value.Subscriptions).SelectMany(x => x.Consolidators);
            var slices        = CreateSlices();

            foreach (var slice in slices.ToList())
            {
                Algorithm.SetDateTime(slice.Time);

                foreach (var symbol in slice.Keys)
                {
                    var data = slice[symbol];
                    Algorithm.Securities[symbol].SetMarketPrice(data);

                    foreach (var consolidator in consolidators)
                    {
                        consolidator.Update(data);
                    }
                }

                Algorithm.OnFrameworkData(slice);
            }

            Assert.AreEqual(expectedInsights.Count * 3, actualInsights.Count);

            for (var i = 0; i < actualInsights.Count; i = i + 3)
            {
                var expected = expectedInsights[i / 3];
                for (int j = i; j < 3; j++)
                {
                    var actual = actualInsights[j];
                    Assert.AreEqual(expected.Symbol, actual.Symbol);
                    Assert.AreEqual(expected.Type, actual.Type);
                    Assert.AreEqual(expected.Direction, actual.Direction);
                    Assert.AreEqual(expected.Period, actual.Period);
                    Assert.AreEqual(expected.Magnitude, actual.Magnitude);
                    Assert.AreEqual(expected.Confidence, actual.Confidence);
                }
            }
        }
Esempio n. 10
0
 protected override string GetExpectedModelName(IAlphaModel model)
 {
     return($"{nameof(ConstantAlphaModel)}({_type},{_direction},{_period},{_magnitude})");
 }
Esempio n. 11
0
 protected override string GetExpectedModelName(IAlphaModel model)
 {
     return($"{nameof(BasePairsTradingAlphaModel)}({_lookback},{_resolution},1)");
 }
Esempio n. 12
0
 /// <summary>
 /// To be override for model types that implement <see cref="INamedModel"/>
 /// </summary>
 protected virtual string GetExpectedModelName(IAlphaModel model)
 {
     return(model.GetType().Name);
 }
Esempio n. 13
0
 protected override string GetExpectedModelName(IAlphaModel model)
 {
     return($"{nameof(EmaCrossAlphaModel)}(12,26,Daily)");
 }
Esempio n. 14
0
 /// <summary>
 /// Adds a new <see cref="AlphaModel"/>
 /// </summary>
 /// <param name="alphaModel">The alpha model to add</param>
 public void AddAlpha(IAlphaModel alphaModel)
 {
     _alphaModels.Add(alphaModel);
 }
Esempio n. 15
0
 protected override string GetExpectedModelName(IAlphaModel model)
 {
     return($"{nameof(RsiAlphaModel)}(14,Daily)");
 }