# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.from AlgorithmImports import *### <summary>### Basic template framework algorithm uses framework components to define the algorithm.### </summary>### <meta name="tag" content="using data" />### <meta name="tag" content="using quantconnect" />### <meta name="tag" content="trading and orders" />class IndiaDataRegressionAlgorithm(QCAlgorithm):'''Basic template framework algorithm uses framework components to define the algorithm.'''def initialize(self):'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''self.set_account_currency("INR")self.set_start_date(2004, 5, 20)self.set_end_date(2016, 7, 26)self._mapping_symbol = self.add_equity("3MINDIA", Resolution.DAILY, Market.INDIA).symbolself._split_and_dividend_symbol = self.add_equity("CCCL", Resolution.DAILY, Market.INDIA).symbolself._received_warning_event = Falseself._received_occurred_event = Falseself._initial_mapping = Falseself._execution_mapping = Falseself.debug("numpy test >>> print numpy.pi: " + str(np.pi))def on_dividends(self, dividends: Dividends):if dividends.contains_key(self._split_and_dividend_symbol):dividend = dividends[self._split_and_dividend_symbol]if ((self.time.year == 2010 and self.time.month == 6 and self.time.day == 15) and(dividend.price != 0.5 or dividend.reference_price != 88.8 or dividend.distribution != 0.5)):raise AssertionError("Did not receive expected dividend values")def on_splits(self, splits: Splits):if splits.contains_key(self._split_and_dividend_symbol):split = splits[self._split_and_dividend_symbol]if split.type == SplitType.WARNING:self._received_warning_event = Trueelif split.type == SplitType.SPLIT_OCCURRED:self._received_occurred_event = Trueif split.price != 421.0 or split.reference_price != 421.0 or split.split_factor != 0.2:raise AssertionError("Did not receive expected price values")def on_symbol_changed_events(self, symbols_changed: SymbolChangedEvents):if symbols_changed.contains_key(self._mapping_symbol):mapping_event = [x.value for x in symbols_changed if x.key.security_type == 1][0]if self.time.year == 1999 and self.time.month == 1 and self.time.day == 1:self._initial_mapping = Trueelif self.time.year == 2004 and self.time.month == 6 and self.time.day == 15:if mapping_event.new_symbol == "3MINDIA" and mapping_event.old_symbol == "BIRLA3M":self._execution_mapping = Truedef on_end_of_algorithm(self):if self._initial_mapping:raise AssertionError("The ticker generated the initial rename event")if not self._execution_mapping:raise AssertionError("The ticker did not rename throughout the course of its life even though it should have")if not self._received_occurred_event:raise AssertionError("Did not receive expected split event")if not self._received_warning_event:raise AssertionError("Did not receive expected split warning event")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。