Beispiel #1
0
    def initialize(self):
        globalVars.initialize()
        loadedDataList = load_material_data()

        # TODO:use logger latter
        print('We now have {} in our globalVar now'.format(loadedDataList))

        try:
            shiftedReturn = globalVars.materialData['pctChange'].get_shifted(
                -1)
        except AttributeError as ae:
            print(ae)
            raise AttributeError('There\'s no pctChange in globalVars')
        except Exception as e:
            print(e)
            raise

        shiftedReturn.metadata.update({'shiftN': -1})
        shiftedReturn.name = 'shiftedReturn'
        self.allTradeDatetime = shiftedReturn.timestamp
        self.dependents.update({'shiftedReturn': shiftedReturn})

        # TODO: should load from some factor.json file latter
        ############ this part realy socks
        ############ to be modified latter
        ############ with nice designed globalVars
        ############ the factor in globalVars.factors is a dict
        toLoadFactors = ['close', 'high', 'low', 'open']

        for aFactor in toLoadFactors:
            simple_load_factor(aFactor)
            self.factorNameList.append(aFactor)
    def run(self):
        # initialize the globalVars
        globalVars.initialize()
        self.logger.info('globalVars is initialized')

        # load material data
        loadedDataList = load_material_data()
        self.logger.info('material data {0} is loaded'.format(loadedDataList))

        # load factors
        # TODO: should load from some factor.json file latter rather than simply load from material data
        # self.factorNameList
        # # 给globalVars注册factors(dict)
        # # key:factor的名字,value:generalData

        if 'factors' not in globalVars.varList:
            globalVars.register('factors', {})

        # TODO: factorManager
        for factorName in self.factorNameList:

            globalVars.factors[factorName] = Factor(
                factorName, globalVars.materialData[factorName])
            print(factorName, 'is now in globalVars.factors')
            self.logger.info("factor {0} is loaded".format(factorName))
        self.logger.info("all factors are loaded")

        # calculate the signal
        # 设置计算factors的参数
        # 可直接传pipeline
        # maskList:mask的nameList
        self.logger.info("start to generate signalGenerator")
        self.signalGenerator = self.signalGeneratorClass(
            model=CrossSectionalModelXGBoost, logger=self.logger)
        signals = self.signalGenerator.generate_signals(**self.params)

        return signals
Beispiel #3
0
import random
from inspect import getmembers, isfunction
#%% initialize global vars

import numpy as np
from deap import base, creator, gp, tools

from Tool import globalVars
from Tool.GeneralData import GeneralData
from GetData.loadData import load_data
from GeneticPogramming import scalarFunctions, singleDataFunctions, singleDataNFunctions, coupleDataFunctions

#%% initialize global vars

globalVars.initialize()
loadedData = load_data()
globalVars.list_vars()
#%% add primitives

pset = gp.PrimitiveSetTyped('main', [
    GeneralData, GeneralData, GeneralData, GeneralData, GeneralData,
    GeneralData
], GeneralData)

pset.renameArguments(ARG0='CLOSE')
pset.renameArguments(ARG1='OPEN')
pset.renameArguments(ARG2='HIGH')
pset.renameArguments(ARG3='LOW')
pset.renameArguments(ARG4='AMOUNT')
pset.renameArguments(ARG5='VOLUME')
            # 记录数据
            record = stats.compile(pop)
            logger.info("The {} th record:{}".format(gen, str(record)))

            logbook.record(gen=gen, **record)
        return (False, pop, logbook)

    from GeneticPogramming.createMultiProcessWorker import toolbox, evaluate, materialDataNames, stats, logbook, compileFactor
    from Tool import globalVars, Logger
    from GetData import load_material_data, load_barra_data, align_all_to

    # set up logger
    loggerFolder = PROJECT_ROOT + "Tool\\log\\"
    logger = Logger(loggerFolder, 'log')
    globalVars.initialize(logger)

    # load data to globalVars
    load_material_data()
    load_barra_data()
    globalVars.logger.info('load all......done')

    # prepare data
    materialDataDict = {
        k: globalVars.materialData[k]
        for k in materialDataNames
    }  # only take the data specified in materialDataNames
    barraDict = globalVars.barra
    toRegFactorDict = {}

    # get the return to compare
Beispiel #5
0
    def run(self):
        # initialize the globalVars
        globalVars.initialize()
        self.logger.info('globalVars is initialized')

        # load material data
        loadedDataList = load_material_data()
        self.logger.info('material data {0} is loaded'.format(loadedDataList))

        # load factors
        # TODO: should load from some factor.json file latter rather than simply load from material data
        # self.factorNameList

        # toLoadFactors = ['close',
        #                  'high',
        #                  'low',
        #                  'open',
        #                  'volume'
        #                  ]
        # # 给globalVars注册factors(dict)
        # # key:factor的名字,value:generalData
        

        if 'factors' not in globalVars.varList:
            globalVars.register('factors', {})
        globalVars.factors['{}_factor'.format(self.toTestFactor.name)] = Factor('{}_factor'.format(self.toTestFactor.name),self.toTestFactor)
        self.factorNameList.append('{}_factor'.format(self.toTestFactor.name))
        # TODO: factorManager
        # for factorName in toLoadFactors:

        #     globalVars.factors[factorName] = Factor(factorName, globalVars.materialData[factorName])
        #     print(factorName, 'is now in globalVars.factors')
        #     self.factorNameList.append(factorName)
        #     self.logger.info("factor {0} is loaded".format(factorName))
        # self.logger.info("all factors are loaded")

        # calculate the signal
        # 设置计算factors的参数
        # 可直接传pipeline
        # maskList:mask的nameList
        params = {
            "startDate": pd.to_datetime('2020-01-01'),
            "endDate": pd.to_datetime('2020-10-31'),
            "panelSize": 3,
            "trainTestGap": 1,
            "maskList": None,
            "deExtremeMethod": DeExtremeMethod.MeanStd(),
            "imputeMethod": ImputeMethod.JustMask(),
            "standardizeMethod": StandardizeMethod.StandardScaler(),
            "pipeline": None,
            "factorNameList": self.factorNameList,
            # params for XGBoost
            "modelParams": {
                "jsonPath": None,
                "paraDict": {
                    "n_estimators": 50,
                    "random_state": 42,
                    "max_depth": 2}
            },
            # metric function for machine learning models
            "metric_func": mean_squared_error,
            # smoothing params
            "smoothing_params": None
        }
        self.logger.info("start to generate signalGenerator")
        self.signalGenerator = self.signalGeneratorClass(model=CrossSectionalModelXGBoost, logger=self.logger)
        signals = self.signalGenerator.generate_signals(**params)

        return signals