Overall Statistics
Total Trades
2
Average Win
14.03%
Average Loss
-8.66%
Compounding Annual Return
4.164%
Drawdown
5.800%
Expectancy
0.31
Net Profit
4.16%
Sharpe Ratio
0.481
Loss Rate
50%
Win Rate
50%
Profit-Loss Ratio
1.62
Alpha
0.062
Beta
-0.061
Annual Standard Deviation
0.093
Annual Variance
0.009
Information Ratio
-1.604
Tracking Error
0.15
Treynor Ratio
-0.737
/*
 * 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 QuantConnect.Data.Market;
using QuantConnect.Indicators;

namespace QuantConnect.Algorithm.Examples
{
    /// <summary>
    /// In this algorithm we'll compute/plot the ratio between coke and pepsi
    /// </summary>
    public class IndicatorRatioExampleAlgorithm : QCAlgorithm
    {
        /// <summary>
        /// Our EMA of Coca cola minute close prices
        /// </summary>
        public ExponentialMovingAverage EMA_KO;
        /// <summary>
        /// Our EMA of Pepsi minute close prices
        /// </summary>
        public ExponentialMovingAverage EMA_PEP;
        /// <summary>
        /// Our ratio of the EMA of KO/PEP minute close prices
        /// </summary>
        public CompositeIndicator<IndicatorDataPoint> KO_Over_PEP;
        /// <summary>
        /// Bollinger
        /// </summary>
        public BollingerBands BB_Ratio;

        /// <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(2013, 01, 01);  //Set Start Date
            SetEndDate(2014, 01, 01);    //Set End Date
            SetCash(100000);             //Set Strategy Cash'

            // Find more symbols here: http://quantconnect.com/data
            AddSecurity(SecurityType.Equity, "KO", Resolution.Minute);
            AddSecurity(SecurityType.Equity, "PEP", Resolution.Minute);

            EMA_KO = EMA("KO", 14, Resolution.Daily);
            EMA_PEP = EMA("PEP", 14, Resolution.Daily);

            // This will create a new indicator that is the ema_ko divided by the ema_pep
            KO_Over_PEP = EMA_KO.Over(EMA_PEP);

            // we'll also create a bollinger band of the ratio for plotting
            BB_Ratio = new BollingerBands("BB_Ratio", 14, 2).Of(KO_Over_PEP);
        }

        /// <summary>
        /// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
        /// </summary>
        /// <param name="data">TradeBars IDictionary object with your stock data</param>
        public void OnData(TradeBars data)
        {
            if (BB_Ratio.IsReady && !Portfolio.Invested)
            {
                MarketOrder("KO", -2000);
                MarketOrder("PEP", (int) (2000*KO_Over_PEP));
            }

            // plot every afternoon
            if (data.Time.Hour == (3 + 12) && data.Time.Minute == 50)
            {
                // wait for bollinger bands to get ready
                if (BB_Ratio.IsReady)
                {
                    Plot("Ratio", KO_Over_PEP, BB_Ratio.UpperBand, BB_Ratio.MiddleBand, BB_Ratio.LowerBand);
                }
            }
        }
    }
}