| 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 |
import numpy as np
import pandas as pd
class BasicTemplateAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2018,6, 5)
self.SetCash(10000)
self.symbols = ["SMG", "CRON", "CGC", "STZ"]
self.back_period = 2
for i in range(len(self.symbols)):
symbol = self.AddEquity(self.symbols[i], Resolution.Daily).Symbol
self.symbols[i] = symbol
#average price increase
def get_history(self):
history = self.History(self.back_period, Resolution.Daily)
for i in self.symbols:
bars = map(lambda x: x[i], history)
i.prices = pd.Series([float(x.Close) for x in bars])
i.ema3 = self.EMA(i, 3, Resolution.Daily)
i.ema1 = self.EMA(i, 1, Resolution.Daily)
# select the best one with the highest score.
def select(self):
self.get_history()
for i in self.symbols:
single = (i.prices / i.ema1)
three = (i.prices / i.ema3)
i.score = single / three
select = sorted(self.symbols, key = lambda x: x.score, reverse = True)
return select[0]
def rebalance(self):
target = self.select()
self.SetHoldings(target,1)