Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 |
from datetime import timedelta import pandas as pd class BasicTemplateFuturesAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2013, 10, 8) self.SetEndDate(2013, 10, 15) self.SetCash(1000000) # Subscribe and set an expiry filter for the futures chain futureES = self.AddFuture(Futures.Indices.SP500EMini, Resolution.Minute) futureES.SetFilter(timedelta(0), timedelta(182)) benchmark = self.AddEquity("SPY"); self.SetBenchmark(benchmark.Symbol); ## Create your own python dictionary that will be populated ## with futures symbols as keys and VWAP values as values self.vwap = dict() def OnData(self,slice): ## Arbitrary code if self.Portfolio.Invested: return ## loop through the futures chains in the slice object for chain in slice.FutureChains: ## loop through the contracts in each chain for contract in chain.Value: ## use the populatr_vwap_dict() helper method to ## populate your vwap dictionary based on the contract symbol self.populate_vwap_dict(contract.Symbol) ## Access a VWAP value using the symbol you wish, i.e. front contract ## vwap = self.vwap[front.Symbol] def OnEndOfAlgorithm(self): ## Simple debug statement to print out VWAP symbols and values for symbol, vwap in self.vwap.items(): self.Debug(f'{symbol} {vwap}') def populate_vwap_dict(self, symbol): ## Create VWAP for new contract symbols if symbol not in self.vwap: self.Log(f'Creating VWAP for {symbol}') self.vwap[symbol] = self.VWAP(symbol, 200)