0
내가있어 다음 코드를 매핑하는변환 반복
return ThreadPoolExecutor.map(Instrument, list(yaml.load_all(ymlfile))
을하지만 난 방법을 아주 확실하지 않다 매개 변수를 전달합니다.
---
name: 'corn'
#Trade December corn only
multiplier: 5000
contract_prefix: 'C'
months_traded: [3, 5, 7, 9, 12]
quandl: 'CHRIS/CME_C2'
first_contract: 196003
backtest_from: 199312
trade_only: [12]
contract_name_prefix: 'C'
quandl_database: 'CME'
slippage: 0.125 #half the spread
ib_code: 'ZC'
이 어떻게 내가있는 ThreadPoolExecutor를 사용할 수있는 맵으로 내 코드를 리팩토링 않습니다
여기 instruments.yaml의 예? 변경이어서
def make_instrument_pair(d):
return d['name'], Instrument(**d)
:
@classmethod
def load(self):
with open('yaml/instruments.yaml', 'r') as ymlfile:
return {v['name']: Instrument(**v) for (v) in list(yaml.load_all(ymlfile))}
에 :
당신은'ThreadPoolExecutor' (및 일반적으로 쓰레드)가 CPU 바인딩 된 작업에 매우 유용하지 않다는 것을 이해합니다. (GIL (https : // wiki)를 공개하는 제 3 자 라이브러리를 처리하는 무거운 데이터를 제외하고. python.org/moin/GIL)), 맞습니까? 'Instrument'가 일부 C 확장자 유형 (또는 I/O에 많은 시간을 소비)이 아니라면, 이것을 스레딩해도 아무 것도 얻을 수 없습니다. 또한,'for (v) in list (yaml.load_all (ymlfile))'은'for v in yaml.load_all (ymlfile)'으로 표현되는 것이 더 낫습니다. 반복하면'list'로 불필요한 변환을 피할 수 있습니다 어쨌든 그것을 던져 버려라. – ShadowRanger
로드는 분리 가능한 두 단계로 작동합니다. 각로드는 약 1000 개의 CSV 파일을 판다 데이터 프레임에로드하고 2 단계는 몇 가지 기본 계산 (이동 평균)을 수행합니다. 나의 짐 i3에 달릴 때 각 짐은 약 30-60 초를 걸린다; 또는 전체 데이터 세트의 경우 약 15 분입니다. – cjm2671