Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
-13.528%
Drawdown
2.700%
Expectancy
0
Net Profit
0%
Sharpe Ratio
-1.466
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.008
Beta
0.999
Annual Standard Deviation
0.09
Annual Variance
0.008
Information Ratio
-3.373
Tracking Error
0.002
Treynor Ratio
-0.131
Total Fees
$2.02
#
#   QuantConnect Basic Template:
#	Fundamentals to using a QuantConnect algorithm.
#
#	You can view the QCAlgorithm base class on Github: 
#	https://github.com/QuantConnect/Lean/tree/master/Algorithm
#

import pandas as pd
import numpy as np
import talib

class BasicTemplateAlgorithm(QCAlgorithm):

	def Initialize(self):
		self.SetStartDate(2017,8,1)
		
		self.stocks = ["SPY","TQQQ"]
		for s in self.stocks:
			self.AddEquity(s)
		
		# History request using list of tickers
		hist = self.History(self.stocks, 1000, Resolution.Minute)
		self.Log(str(hist.index))
		self.Log(str(hist.columns))
		
		# Check if returns an empty list. It should not.
		if hist.empty:
			self.Log(str(self.Time) + " empty hist")
			return
		
		# Select the closing prices
		prices = hist.close
		
		# The History method returns a multi-index pandas.DataFrame, where the
		# symbols are index 0 and date/time is index 1.
		# These lines are used to create a pandas.DataFrame where the symbols
		# are in the columns, instead of index 0.
		spy = prices.loc['SPY']
		tqqq = prices.loc['TQQQ']
		prices = pd.concat([spy,tqqq],axis = 1)
		prices.columns = self.stocks
	    
	    # Then we can .as_matrix normally
		ret = prices.pct_change()[1:].as_matrix(self.stocks)
		ret_mean = prices.pct_change().mean()
		ret_std = prices.pct_change().std()
		ret_norm = ret_mean / ret_std
		ret_norm = ret_norm.as_matrix(self.stocks)
		
		self.Log("ret_norm" + str(ret_norm))


	def OnData(self, data):
		if not self.Portfolio.Invested:
			self.SetHoldings("SPY", 1)