Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
-2.485%
Drawdown
2.700%
Expectancy
0
Net Profit
0%
Sharpe Ratio
-0.231
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.006
Beta
1
Annual Standard Deviation
0.09
Annual Variance
0.008
Information Ratio
-3.112
Tracking Error
0.002
Treynor Ratio
-0.021
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)
		
		# Check if returns an empty list. It should not.
		if hist.empty:
			self.Log(str(self.Time) + " empty hist")
			return
		
		# The History method returns a multi-index pandas.DataFrame, where the
		# symbols are index 0 and date/time is index 1.
		# We can use unstack to a column (close) and the index 0 will become column
		prices = hist.close.unstack(level=0)
		
	    # 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)