Overall Statistics
using QuantConnect.Data.Custom;
using QuantConnect.Data.Market;

namespace QuantConnect 
{   
    /*
    *   QuantConnect University: Futures Example
    *
    *   QuantConnect allows importing generic data sources! This example demonstrates importing a futures
    *   data from the popular open data source Quandl.
    *
    *   QuantConnect has a special deal with Quandl giving you access to Stevens Continuous Futurs (SCF) for free. 
    *   If you'd like to download SCF for local backtesting, you can download it through Quandl.com.
    */
    public class VolatilityETN : QCAlgorithm
    {
        string shortTerm = "SPY";
		string shortTerm1 = "SPY1";

        decimal diff = 0;
        DateTime sampledToday;


        //Initialize the data and resolution you require for your strategy:
        public override void Initialize()
        {
			// Code Automaticly Generated  
            SetStartDate(2015,1,1);        
            SetEndDate(2015,5,10);
            SetCash(10000);
			// Code Automaticly Generated  
			AddSecurity(SecurityType.Equity, shortTerm, Resolution.Minute);
           //AddData<Quandl>("YAHOO/INDEX_SPY");
 
        }

        bool IsLastTradingMin(TradeBar b)
        {
            if ( b.Time.Hour==15 && b.Time.Minute == 30)
                return true;
            else
                return false;
        } // IsLastTradingMin

        bool IsFirstTradingMin(TradeBar b)
        {
            if ( b.Time.Hour==9 && b.Time.Minute == 31)
                return true;
            else
                return false;
        } // IsFirstTradingMin


        public void OnData(TradeBars data) 
        {   
           // diff = data[shortTerm].Close - data[longTerm].Close;
             // add logic to have orders placed once / day
            //Log("XIV " + data[shortTerm].Close + " ZIV = "  + data[longTerm].Close + " diff is " + diff);
            Log("XIV Time : " + data[shortTerm].Time + " Close : " + data[shortTerm].Close );
            //Log("SPY1 Time : " + data[shortTerm].Time + " Close : " + data[shortTerm].Close );
            // Add buy/sell logic
			if(IsFirstTradingMin(data[shortTerm]))
			{
                   SetHoldings(shortTerm, 0.5);
 			}
 			else if(IsLastTradingMin(data[shortTerm]))
 			{
 			       SetHoldings(shortTerm, 0);
 				
 			}
            //sampledToday = Time;
        }
        
        public void OnData(Quandl quandl)
        {
        }
        
    }
}