Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
35.255%
Drawdown
3.200%
Expectancy
0
Net Profit
0%
Sharpe Ratio
2.859
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.416
Beta
-0.3
Annual Standard Deviation
0.106
Annual Variance
0.011
Information Ratio
-0.427
Tracking Error
0.173
Treynor Ratio
-1.01
Total Fees
$1.00
using System.Net;

namespace QuantConnect 
{   
    /*
    *   Example of how to download current prices from Google Finance
    *   by: Jean-Paul van Brakel
    */
    public class BasicTemplateAlgorithm : QCAlgorithm
    {
    	static bool retrieved;
    	static double VIX;
    	
        //Initialize the data and resolution you require for your strategy:
        public override void Initialize() 
        {
			retrieved = false;
            //Start and End Date range for the backtest:
            SetStartDate(2013, 1, 1);         
            SetEndDate(2013,6,1);
            
            //Cash allocation
            SetCash(25000);
            
            //Add as many securities as you like. All the data will be passed into the event handler:
            AddSecurity(SecurityType.Equity, "SPY", Resolution.Daily);
            
        }
        
		public static void GetVIX()
		{
			string address = "http://www.google.com/finance/info?q=INDEXCBOE%3aVIX";
		    WebClient client = new WebClient();
		    string reply = client.DownloadString(address);
		    int start = reply.IndexOf("$");
		    int end = reply.IndexOf("\"", start);
			VIX = Convert.ToDouble(reply.Substring(start+1, end-start-1));
		    Console.WriteLine("\n> Current VIX price:\t"+VIX+"\t("+DateTime.Now.TimeOfDay+")\n\n");
		}

        //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) 
        {   
        	if (!retrieved) {
        		GetVIX();
        		retrieved = true;
        	}
            
            if (!Portfolio.HoldStock) 
            {
                int quantity = (int)Math.Floor(Portfolio.Cash / data["SPY"].Close);
                
                //Order function places trades: enter the string symbol and the quantity you want:
                Order("SPY",  quantity);
                
                //Debug sends messages to the user console: "Time" is the algorithm time keeper object 
                Debug("Purchased SPY on " + Time.ToShortDateString());
            }
        }
    }
}