Overall Statistics
Total Trades
9
Average Win
4.95%
Average Loss
0%
Compounding Annual Return
15.739%
Drawdown
11.300%
Expectancy
0
Net Profit
53.658%
Sharpe Ratio
1.318
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
0.154
Beta
-0.006
Annual Standard Deviation
0.116
Annual Variance
0.013
Information Ratio
-0.226
Tracking Error
0.164
Treynor Ratio
-23.934
using System;
using System.Collections;
using System.Collections.Generic; 
using QuantConnect.Securities;  
using QuantConnect.Models;  

namespace QuantConnect 
{   
    // Name your algorithm class anything, as long as it inherits QCAlgorithm
    public class BarbellStrategy : QCAlgorithm
    {
        public string symbol = "XIV";
        //Initialize the data and resolution you require for your strategy:
        public override void Initialize()
        {
            SetStartDate(2012, 1, 1);         
            SetEndDate(DateTime.Now.Date.AddDays(-1)); 
            SetCash(100000); //only going to trade 20%
            AddSecurity(SecurityType.Equity, symbol, Resolution.Minute);
        }

        //Data Event Handler: New data arrives here. "TradeBars" type is a dictionary of strings so you can access it by symbol.
        public void OnData(TradeBars data) 
        {   


            //only get daily close
            if (data[symbol].Time.ToString().Contains("3:59:00")) {
                Debug(data[symbol].Time.ToString());
                
                decimal currentPercentage = (Portfolio.TotalHoldingsValue / Portfolio.TotalPortfolioValue);
                Debug("CurrentPercentage: " + currentPercentage);
                
                //reconfigure for 20/80 holding; but give a little room (15%)
                if (currentPercentage < (decimal).15 ){
                    //buy
                    decimal amtToBuy = ((((decimal).2 - (currentPercentage)) * Portfolio.TotalPortfolioValue)/data[symbol].Close);
                    amtToBuy = Math.Round(amtToBuy);
                    Order(symbol, amtToBuy);
                    Debug("Puchased " + amtToBuy + "of " + symbol);
                    return;
                }
                
                //reconfigure for 20/80; but give a little room (25%)
                if (currentPercentage > (decimal).25) {
                    //sell
                    decimal amtToSell = (((currentPercentage - (decimal).2) * Portfolio.TotalPortfolioValue)/data[symbol].Close);
                    amtToSell = Math.Round(amtToSell);
                    Debug("Sold " + amtToSell + "of " + symbol);
                    Order(symbol, -1* amtToSell);
                    return;
                }
                
            } else {
                return;
            }
            
            /*
            Debug(data[symbol].Time.ToString());
            
            if (!Portfolio.HoldStock) 
            {
                Order(symbol, (int)Math.Floor(Portfolio.Cash / data[symbol].Close) );
                Debug("Debug Purchased XIV");
            }
            */
        }
    }
}