-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_helper.py
55 lines (39 loc) · 1.53 KB
/
project_helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import numpy as np
from zipline.assets._assets import Equity # Required for USEquityPricing
from zipline.pipeline.data import USEquityPricing
from zipline.pipeline.classifiers import Classifier
from zipline.pipeline.engine import SimplePipelineEngine
from zipline.pipeline.loaders import USEquityPricingLoader
from zipline.utils.numpy_utils import int64_dtype
EOD_BUNDLE_NAME = 'eod-quotemedia'
class PricingLoader(object):
def __init__(self, bundle_data):
self.loader = USEquityPricingLoader(
bundle_data.equity_daily_bar_reader,
bundle_data.adjustment_reader)
def get_loader(self, column):
if column not in USEquityPricing.columns:
raise Exception('Column not in USEquityPricing')
return self.loader
class Sector(Classifier):
dtype = int64_dtype
window_length = 0
inputs = ()
missing_value = -1
def __init__(self):
self.data = np.load('../../data/project_4_sector/data.npy')
def _compute(self, arrays, dates, assets, mask):
return np.where(
mask,
self.data[assets],
self.missing_value,
)
def build_pipeline_engine(bundle_data, trading_calendar):
pricing_loader = PricingLoader(bundle_data)
engine = SimplePipelineEngine(
get_loader=pricing_loader.get_loader,
calendar=trading_calendar.all_sessions,
asset_finder=bundle_data.asset_finder)
return engine
def get_factor_exposures(factor_betas, weights):
return factor_betas.loc[weights.index].T.dot(weights)