def __init__(self, total_capital, num_stocks): self.transaction_amount = total_capital / num_stocks self.mcads = [] self.old_mcads = [] self.visualization_data = VisualizationData() for count in range(num_stocks): self.mcads.append(Mcad()) for count in range(num_stocks): self.old_mcads.append(CalculationStatus.Invalid)
def reset(self): for mcad in self.mcads: mcad.reset() self.old_mcads = [ CalculationStatus.Invalid for old_mcad in self.old_mcads ] visualization_data_holder = self.visualization_data self.visualization_data = VisualizationData() return visualization_data_holder
def reset(self): for mcad in self.mcads: mcad.reset() for signal_line in self.signal_lines: signal_line.reset() self.old_dels = [ CalculationStatus.Invalid for old_del in self.old_dels ] visualization_data_holder = self.visualization_data self.visualization_data = VisualizationData() return visualization_data_holder
def reset(self): self.high_total_data = [] self.low_total_data = [] self.fast_k_percent = [] self.k_percent = [] self.old_k_percent = [] self.d_percent = [] self.old_d_percent = [] visualization_data_holder = self.visualization_data self.visualization_data = VisualizationData() return visualization_data_holder
class McadZeroCrossoverStrategy: def __init__(self, total_capital, num_stocks): self.transaction_amount = total_capital / num_stocks self.mcads = [] self.old_mcads = [] self.visualization_data = VisualizationData() for count in range(num_stocks): self.mcads.append(Mcad()) for count in range(num_stocks): self.old_mcads.append(CalculationStatus.Invalid) def notify(self, market_snapshot: MarketSnapshot): decisions = [] for i, stock_snapshot in enumerate(market_snapshot.stock_snapshots): stock_snapshot_helper = StockSnapshotHelper(stock_snapshot) mid_price = stock_snapshot_helper.get_mid_price() curr_mcad = self.mcads[i].evaluate(mid_price) self.visualization_data.add_price(stock_snapshot.ticker, mid_price) if curr_mcad == CalculationStatus.Invalid: self.visualization_data.add_mcad(stock_snapshot.ticker, 0) continue else: self.visualization_data.add_mcad(stock_snapshot.ticker, curr_mcad) if self.old_mcads[i] == CalculationStatus.Invalid: self.old_mcads[i] = curr_mcad continue del_mcad = SignFunction.evaluate( curr_mcad) - SignFunction.evaluate(self.old_mcads[i]) self.old_mcads[i] = curr_mcad if del_mcad > 0: decisions.append( (stock_snapshot.ticker, -self.transaction_amount)) elif del_mcad < 0: decisions.append( (stock_snapshot.ticker, self.transaction_amount)) return decisions def reset(self): for mcad in self.mcads: mcad.reset() self.old_mcads = [ CalculationStatus.Invalid for old_mcad in self.old_mcads ] visualization_data_holder = self.visualization_data self.visualization_data = VisualizationData() return visualization_data_holder
def __init__(self,total_capital, num_stocks,look_back_period,k_period,d_period, upper_bound, lower_bound): self.transaction_amount = total_capital / num_stocks self.high_total_data = [] self.low_total_data = [] self.fast_k_percent = [] self.k_percent = [] self.old_k_percent = [] self.d_percent = [] self.old_d_percent = [] self.upper_bound = upper_bound self.lower_bound = lower_bound self.visualization_data = VisualizationData() for count in range(num_stocks): self.high_total_data.append(Queue(look_back_period)) self.low_total_data.append(Queue(look_back_period)) self.fast_k_percent.append(Simple_Moving_Average(k_period)) self.k_percent.append(Simple_Moving_Average(k_period)) self.old_k_percent.append(CalculationStatus.Invalid) self.d_percent.append(Simple_Moving_Average(d_period)) self.old_d_percent.append(CalculationStatus.Invalid)