示例#1
0
        public override void Initialize()
        {
            SetCash(1000);
            SetStartDate(Config.GetValue <DateTime>("startDate", new DateTime(2017, 6, 12)));
            SetEndDate(Config.GetValue <DateTime>("endDate", new DateTime(2017, 7, 22)));

            if (IsOutOfSampleRun)
            {
                var startDate = new DateTime(year: 2016, month: 1, day: 1);
                SetStartDate(startDate);
                SetEndDate(startDate.AddMonths(oosPeriod));
                RuntimeStatistics["ID"] = GetParameter("ID");
                SetParameters(config.ToDictionary(k => k.Key, v => v.Value.ToString()));
            }

            _symbol = AddSecurity(SecurityType.Crypto, "BTCUSD", Resolution.Tick, Market.GDAX, false, 1m, false).Symbol;
            SetBrokerageModel(QuantConnect.Brokerages.BrokerageName.GDAX, AccountType.Cash);
            var con = new TickConsolidator(new TimeSpan(1, 0, 0));

            SetBenchmark(_symbol);

            var factory = new SignalFactory(7);

            _entry = factory.Create(this, _symbol, true);
            _exit  = factory.Create(this, _symbol, false);
        }
        public override void Initialize()
        {
            SetCash(10000);
            SetStartDate(Configuration.GetConfigDateTime("startDate", new DateTime(2017, 11, 21), this));
            SetEndDate(Configuration.GetConfigDateTime("endDate", new DateTime(2017, 11, 21), this));
            Configuration.GetConfiguration(Configuration.configUrl, config);
            if (IsOutOfSampleRun)
            {
                //var startDate = new DateTime(year: 2016, month: 1, day: 1);
                //SetStartDate(startDate);
                //SetEndDate(startDate.AddMonths(oosPeriod));
                RuntimeStatistics["ID"] = GetParameter("ID");
                SetParameters(config.ToDictionary(k => k.Key, v => v.Value.ToString()));
            }

            SetBrokerageModel(QuantConnect.Brokerages.BrokerageName.OandaBrokerage);
            var con = new TickConsolidator(new TimeSpan(1, 0, 0));

            // SetBenchmark(_symbol);

            _symbols = new List <Symbol>();
            _entry   = new List <Rule>();
            _exit    = new List <Rule>();
            foreach (var symbol in TradingSymbols.OandaFXMajors0)
            {
                var security = AddSecurity(SecurityType.Forex, symbol, Configuration._resolution, Market.Oanda, true, Configuration._leverage, false);
                _symbols.Add(security.Symbol);
            }
            foreach (var symbol in TradingSymbols.OandaCFD)
            {
                //    AddSecurity(SecurityType.Cfd, symbol, _resolution, Market.Oanda, true, _leverage, false);
            }
            var factory = new SignalFactory();

            foreach (var symbol in _symbols)
            {
                Securities[symbol].VolatilityModel = new ThreeSigmaVolatilityModel(STD(symbol: symbol, period: 12 * 60, resolution: Configuration._resolution), 20.0m);

                _entry.Add(factory.Create(this, symbol, true, Configuration._resolution));
                _exit.Add(factory.Create(this, symbol, false, Configuration._resolution));
            }

            RiskManager = new FxRiskManagment(Portfolio, Configuration._riskPerTrade, Configuration._maxExposurePerTrade, Configuration._maxExposure, Configuration._lotSize);
        }