Defining the symbol universe of the trading algorithm
(system method) Overview:is_symbol_qualified() is used to determine if the symbol qualfies from available symbols. Method can be used to dynamically create the desired symbols (e.g. md.stat.avol > 1000000).
Interface: @classmethod
def is_symbol_qualified(cls,
symbol,
md,
service,
account):
pass
Name | Type | Default | Information |
---|---|---|---|
cls | object | required | cls is how to read or assign class variables in a classmethod (compared to reading/assigning class variable in an instance method self.__class__.CLASS_VARIABLE). |
symbol | string | required | stock symbol |
md | Market | required | market data object |
service | Service | required | service object |
account | Account | required | account object |
- This method is not called, if the symbols is passed in with the submission/start message.
- return True if the symbol should in included in the symbol universe.
- is_symbol_qualified() is called for each symbol in the current trading days known symbols.
- is_symbol_qualified() determines the instances to be created if not specifically requested in the start message.
- Method is called by the simulation engine (once) before the instance is created.
- is_symbol_qualified() is a @classmethod. It is not called in the context of script (e.g. there is no self).
- md - allows access to information in md.bar.daily(), and md.stat. Other md will have different behavior in backtesting vs forward testing.
- service - allows acces to md.symbol_list. Other md will have different behavior in backtesting vs forward testing.
- symbol is note self.symbol
- Replacing in_symbol_universe(). Differences/changes changed to classmethod and added account to the interface.
Create instances for all symbols that start with the letter "A".
from cloudquant.interfaces import Strategy
class StartsWithTheLetterA(Strategy):
do_once = True
@classmethod
def is_symbol_qualified(cls, symbol, md, service, account):
if symbol.startswith('A'):
return True
return False
def on_start(self, md, order, service, account):
if self.__class__.do_once:
print service.time_to_string(service.system_time, '%Y-%m-%d')
self.__class__.do_once = False
print self.symbol
service.terminate()
Console
2016-01-04 AVHI ARTW ARCX ABAC ARP-E ARP-D ABAX A AAAP AGIO ALL-F ALL-E ALL-D ALL-C ALL-A APT APU APH APO APB APC APA APF APD AXS-D AXS-C APIC ANSS AIRI AIRM AIRR AIRT AMSG AMSF AMSC AGTC ASUR ASRVP ALLY-B ALLY-A ADUS ABGB AAME ARWAR ARWAW ARWAU AAON AAOI AQXP AVX AVY AVT AVV AVP AVH ARTX AVD AVG AVA AVB AXTI AXTA ADHD AJRD ARTNA ALOG ARIS ACG ALRM ABEV ABEO ACY AEIS ATO ATI ATV ATW ATU ATR AAMC AZPN AINV AMOV AINC ASTC ALL-B AMWD ALIM AERI AUMN AUMA ALR-B AZN AZO AZZ AVGO AHPI APOG APOL AGZD ANH-A ANH-C ANH-B AMUB ALKS AHL-C AHL-B AHL-A AEPI AUSE ATSG ACFC ADSK APDNW ABIO ABIL AEMD AMSWA AXR AXS AXP AXU AXE AXN AXL AKO.A AF-C AMNB APAM ALEX ACIM ACC ACE ACI ACH ACN ACM ACP ACW ACV ACU ACHN ACHC AFSS AFST AFSD AFSI ANFI ASCMA AWR AMLP AMH-A AMH-B AMH-C ALGT ALGN ABY AAC AAL AAN AAU AAT AAV AAP ARI-A AA- ARPI AGM.A ANDE ANDA AMBR AMBA AMBC APEI ASHX AGO AGN AGM AGI AGG AGF AGD AGC AGA AGZ AGX AGU AGR AGQ ACLS AMZN ALCO AGRX AGRO AETI AEP AES AER AET AEY AEB AEE AED AEG AEH AEK AEM AEL ACNB ALLT ARDC ARDM ARDX AMFW AXPWW AUNZ ASET ASEI ASEA AKS AKR AKP AKG ACPW AGNCB AVK AGNCP AGII ALP-O AXDX AUBN AMDA AFFX ASGN AIY AIZ AIT AIW AIV AIQ AIR AIN AIG AIF AIA AIC AIB ACRS ACRX ACRE ADGE ABUS AMZA AVOL AOD AOA AON AOM AOK AOI AOS AOR ACTX ACTS ACTA ACTG ADAP ADAT APPY APPS APPF ARNA AKAO AKAM AGEN AWRE ATLS ATLO ATLC ALOT ARQL AMH AMC AME AMD AMX AMP AMS AMU AHGP ARGT AA AC AB AE AG AF AI AM AL AN AR AU AT AV ARLP APRI AGGY AUDC ASPN AXJV AXJL ATNM ATNI ATNY ASMB ASML ACBI ARWA ARWR ACXM ASR AST ASX ASC ASB ASA ASG ASH ASM ADMA ADMP AKER APTO APTS ANW ASRV AVID ATHN ATHM ATHX AEZS ABBV ALNY AXSM ABMD ABEOW AGCO ANTX ANTM ANTH ATE ASTI ASTE AMRN AMRI AMRK AXAS AMRB AMRC AMRS AVGR AMT-A AMT-B ALQA ABILW AWX AWP AWK AWI AWH AWF ACCO APHB ALLE ALLY AMPH AMPE AIV-Z ACAD AES-C ACAT ACAS AIV-A ATTU AVEO ATTO ALSN ALSK AMJ AMG AEHR ADTN AMT AUO AUY ATVI AADR ABDC ABR-C ABR-B ABR-A AMKR APLP AGIIL APLE AP AGYS AMTX AMTG AMTD ACET AVAV AVAL AFH AKRX AZUR AOSL AYI AYA AYT AYR AMID AMIC AIMT ASYS AUPH ACGL ATRA ATRC ATRI ATRS ARCW ARCB ARCC ARCO ARCI ADRU ADRA ADRE ADRD ADRO AKTX ANGL ANGO ANGI AAVL ASPS AMOT ADM AFOP ALDX ALDW ALDR ACIW ABB ABC ABE ABG ABM ABR ABT ABX ARAY AHT-A AHT-E AHT-D AFB ANET AEO ARE-D ARE-E AVXL AFMD AIII AEUA AFSI-A AFSI-B AFSI-C AFSI-D ALFA ALFI ARGS AGM-C AGM-B AGM-A ANCB ANCX AMCX AMCO AMCN AMCC APDN AIG+ ATEC ATEN ASB+ ASBB AFL AFK AFG AFA AFC AFT AFW ARES AREX ADXS AQMS ABRN AAPC AAPL ANAT ANAD ANAC AMAG AMAT AGNC AGND AA-B ACOR ADT ADS ADZ ADX ADC ADK ADI ARKK ARKG ARKW ARKQ ARKR ADPT AMGN AFGH AFGE ATAI ATAX ARH-C ARR-B ARR-A ASB-B ASB-C ASFI ADP AJX AJG ARII ARIA AXGN AMED AKO.B AGN-A ADXSW ACST ACSF AMSGP ASHR ASHS AHC AHH AHL AHS AHP AHT AROW AROC ABTL ABTX ANDAU ANDAW ANDAR AGFSW AFCO AXLL AVNW AVNU ATMP ATML ARRS ARRY ALXN ALXA ACUR AND ANF ANH ANY ARMK ARMH AMTG-A AKBA AGO-B AGO-E AGO-F ANIK AAXJ ANIP AIXG AGFS AAWW AFAM ATOS ADK-A ADMS ACWF ACWI ACWV ACWX ALN ALL ALJ ALK ALG ALD ALE ALB ALX ALV ALU ALR ADBE AUMAU AUMAW AEGR AEGN ALTY ALTS ABCD ABCB ABCO ABCW ASND ASNA AMBCW ARP ARR ARU ARW ARC ARE ARG ARI ARL ARO AXPW AFTY APWC AXON ATRO AIMC