Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
22.772%
Drawdown
32.400%
Expectancy
0
Net Profit
350.036%
Sharpe Ratio
0.913
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.407
Beta
-13.139
Annual Standard Deviation
0.209
Annual Variance
0.044
Information Ratio
0.834
Tracking Error
0.209
Treynor Ratio
-0.015
Total Fees
$10.00
namespace QuantConnect.Algorithm.CSharp
{
    public class BasicTemplateAlgorithm : QCAlgorithm
    {
        private Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);

        public override void Initialize()
        {
            SetStartDate(2010, 10, 07);  //Set Start Date
            SetEndDate(2018, 02, 02);    //Set End Date
            SetCash(100000);             //Set Strategy Cash

            AddEquity("SPY", Resolution.Daily);
            Securities["SPY"].SetLeverage(2.0M);

            Chart plotter = new Chart("Leverage (actual)");
            plotter.AddSeries(new Series("SPY", SeriesType.Line, "%"));
			plotter.AddSeries(new Series("Total leverage", SeriesType.Line, "%"));
            AddChart(plotter);
        }
        public override void OnData(Slice data)
        {
            if (!Portfolio.Invested)
            {
                SetHoldings(_spy, 2.0M);
                Debug("Purchased Stock");
            }
        }
        
        public override void OnEndOfDay() 
        {
            try 
            {
                Plot("Leverage (actual)", "Total Leverage", (Portfolio.TotalHoldingsValue / Portfolio.TotalPortfolioValue)*100);
                Plot("Leverage (actual)", "SPY", (Securities["SPY"].Holdings.HoldingsValue/Portfolio.TotalPortfolioValue)*100);

            } 
            catch (Exception err) 
            {
                Error("OnEndOfDay Err:" + err.Message);
            }
        }
    }
}