Overall Statistics
Total Trades
2
Average Win
0%
Average Loss
0%
Compounding Annual Return
17.212%
Drawdown
30.700%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0.857
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.177
Beta
0.018
Annual Standard Deviation
0.209
Annual Variance
0.044
Information Ratio
0.252
Tracking Error
0.258
Treynor Ratio
9.782
Total Fees
$15.91
namespace QuantConnect
{
    /// <summary>
    /// Shows how to use the Minus and Of extension methods to define a MACD on the
    /// difference in closing price between two securities
    /// </summary>
    public class MacdOnDifferenceAlgorithm : QCAlgorithm
    {
        /// <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(2011, 01, 01);  //Set Start Date
            SetEndDate(2015, 10, 11);    //Set End Date
            SetCash(100000);             //Set Strategy Cash
            // Find more symbols here: http://quantconnect.com/data
            AddSecurity(SecurityType.Equity, "AAPL", Resolution.Daily);
            AddSecurity(SecurityType.Equity, "MSFT", Resolution.Daily);

            // Identity will get updated on each data point before OnData gets called
            var msft = Identity("MSFT");
            var aapl = Identity("AAPL");
            // Minus will get free updates from it's components pieces (msft, aapl)
            var diff = msft.Minus(aapl);
            // Of will get free updates from it's parent indicator (diff)
            var macdDiff = new MovingAverageConvergenceDivergence("MSFT-AAPL_MACD", 12, 26, 9).Of(diff);
            // Plot macdDiff on each new update
            PlotIndicator("MSFT-AAPL MACD", macdDiff);
        }

        /// <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 override void OnData(Slice data)
        {
            if (!Portfolio.Invested)
            {
                SetHoldings("MSFT", .5);
                SetHoldings("AAPL", .5);
            }
        }
    }
}