Overall Statistics |
Total Trades 9 Average Win 9.30% Average Loss -3.00% Compounding Annual Return 12.370% Drawdown 12.400% Expectancy 1.563 Net Profit 41.919% Sharpe Ratio 1.079 Loss Rate 38% Win Rate 62% Profit-Loss Ratio 3.10 Alpha 0.266 Beta -7.108 Annual Standard Deviation 0.114 Annual Variance 0.013 Information Ratio 0.904 Tracking Error 0.114 Treynor Ratio -0.017 Total Fees $69.03 |
/* * 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. */ // modified by U. Weber am 22.05.2018 using QuantConnect.Data.Market; using QuantConnect.Indicators; using QuantConnect.Securities; namespace QuantConnect.Algorithm.CSharp { /// <summary> /// Regression Channel algorithm simply initializes the date range and cash /// </summary> /// <meta name="tag" content="indicators" /> /// <meta name="tag" content="indicator classes" /> /// <meta name="tag" content="placing orders" /> /// <meta name="tag" content="plotting indicators" /> public class RegressionChannelAlgorithm : QCAlgorithm { private Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA); private SecurityHolding _holdings; private RegressionChannel _rc; private TradeBars _data; /// <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() { SetStartDate(2012, 1, 1); //Set Start Date SetEndDate(2015, 1, 1); //Set End Date SetCash(100000); //Set Strategy Cash // Find more symbols here: http://quantconnect.com/data var equity = AddEquity(_spy, Resolution.Minute); _holdings = equity.Holdings; _rc = new RegressionChannel(15,2); //_rc = RC(_spy, 30, 2, Resolution.Daily); var stockPlot = new Chart("Trade Plot"); stockPlot.AddSeries(new Series("Buy", SeriesType.Scatter, 0)); stockPlot.AddSeries(new Series("Sell", SeriesType.Scatter, 0)); stockPlot.AddSeries(new Series("UpperChannel", SeriesType.Line, 0)); stockPlot.AddSeries(new Series("LowerChannel", SeriesType.Line, 0)); stockPlot.AddSeries(new Series("Regression", SeriesType.Line, 0)); AddChart(stockPlot); // schedule an event to fire every trading day for a security // the time rule here tells it to fire 10 minutes before SPY's market close Schedule.On(DateRules.EveryDay(), TimeRules.BeforeMarketClose("SPY", 10), () => { //Debug("EveryDay.SPY 10 min before close: Fired at: " + Time); check_conditions_for_all_data(); }); } /// <summary> /// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here. /// </summary> /// <param name="data">Slice object keyed by symbol containing the stock data</param> public void OnData(TradeBars data) { // Debug(" in OnData " + Time.ToString() + " " + Time.Hour + " " + Time.Minute); // if (! (Time.Hour == 15 && Time.Minute == 50) ) // return; // { _data = data; // } } public override void OnEndOfDay() { Debug(" in OnEndOfDay " + Time.ToString() + " rc_LowerChanngel=" + _rc.LowerChannel ); Plot("Trade Plot", "UpperChannel", _rc.UpperChannel); Plot("Trade Plot", "LowerChannel", _rc.LowerChannel); Plot("Trade Plot", "Regression", _rc.LinearRegression); } public void check_conditions_for_all_data() { //-------------------------------------------------------------------- var time = DateTime.Now; var value = _data[_spy].Value; _rc.Update(time,value); if (!_rc.IsReady || !_data.ContainsKey(_spy)) return; Debug(" in check_conditions_for_all_data " + Time.ToString() + " Close=" + value + " rc_LowerChanngel=" + _rc.LowerChannel ); if (_holdings.Quantity <= 0 && value < _rc.LowerChannel) { SetHoldings(_spy, 1); Plot("Trade Plot", "Buy", value); } if (_holdings.Quantity >= 0 && value > _rc.UpperChannel) { SetHoldings(_spy, -1); Plot("Trade Plot", "Sell", value); } } } }