예제 #1
0
    def evaluation_method_3(self):
        
        self.filedf = pd.read_csv('factsheetdf.csv',index_col='Unnamed: 0')
        
        self.filedf.sort_values('r6posrate',inplace = True,ascending=False)
        
        #take by posrate and negrate
        upper = self.filedf[self.filedf['r6posrate'] >= 0.8]
        upper = upper[upper['total_hits'] >= 10]
        lower = self.filedf[self.filedf['r6negrate'] >= 0.8]
        lower = lower[lower['total_hits'] >= 10]
        
        temp = pd.concat([upper,lower])

        #70% by viability
        temp['r6difference'] = temp['r6posrate'] - temp['r6negrate']
        temp['r6viable'] = temp['r6difference'] * temp['r6mean']
        
        temp = temp[temp['r6viable'] > 0]
        
        
        self.usabledf = temp
        
        genes = temp.index.tolist()
        pool_genes = []
        for x in genes:
            pool_genes.append(ast.literal_eval(x))
        self.genes = pool_genes
        df = pd.read_csv('df.csv')
        _, self.binDict = qe.makeDf(df)
        self.inverseGenes()
예제 #2
0
 def evaluation_method_1(self):
     self.filedf = pd.read_csv('factsheetdf.csv',index_col='Unnamed: 0')
     
     self.filedf.sort_values('r5mean',inplace = True,ascending=False)
     #take highest and lowest 30% return
     
     how_many_to_take = int(len(self.filedf)*0.3)
     
     temp = pd.concat([self.filedf.head(how_many_to_take),self.filedf.tail(how_many_to_take)])
     
     temp['r5difference'] = temp['r5posrate'] - temp['r5negrate']
     temp['r5viable'] = temp['r5difference'] * temp['r5mean']
     temp = temp[temp['r5viable'] > 0]
     temp.sort_values('total_hits',inplace=True,ascending=False)
     temp = temp.tail(int(len(temp)*0.8))
     
     temp.sort_values('r5mean',inplace=True,ascending=False)
     
     temp['r5meanabs'] = abs(temp['r5mean'])
     temp.sort_values('r5meanabs',inplace=True,ascending=False)
     temp = temp[temp['total_hits'] > 10]
     self.usabledf = temp
     
     genes = temp.index.tolist()
     pool_genes = []
     for x in genes:
         pool_genes.append(ast.literal_eval(x))
     self.genes = pool_genes
     df = pd.read_csv('df.csv')
     _, self.binDict = qe.makeDf(df)
     self.inverseGenes()
예제 #3
0
    def evaluation_method_2(self):
        self.filedf = pd.read_csv('factsheetdf.csv',index_col='Unnamed: 0')
        
        self.filedf.sort_values('total_hits',inplace = True,ascending=False)
        
        #take the upper 50%
        temp = self.filedf.head(int(len(self.filedf)*0.5))
        
        #take 50% by mean
        temp.sort_values('r5mean',inplace = True,ascending=False)
        how_many_to_take = int(len(self.filedf) * 0.25)
        temp = pd.concat([temp.head(how_many_to_take),temp.tail(how_many_to_take)])

        #70% by viability
        temp['r5difference'] = temp['r5posrate'] - temp['r5negrate']
        temp['r5viable'] = temp['r5difference'] * temp['r5mean']
        
        temp.sort_values('r5viable',inplace = True,ascending=False)
        
        temp = temp.head(int(len(temp) * 0.3))
        
        self.usabledf = temp
        
        genes = temp.index.tolist()
        pool_genes = []
        for x in genes:
            pool_genes.append(ast.literal_eval(x))
        self.genes = pool_genes
        df = pd.read_csv('df.csv')
        _, self.binDict = qe.makeDf(df)
        self.inverseGenes()
예제 #4
0
    def evaluation_method_5(self):
        self.filedf = pd.read_csv('factsheetdf.csv', index_col='Unnamed: 0')
        self.filedf.dropna(inplace=True)
        self.filedf = self.filedf[self.filedf['total_hits'] >= 20]
        temp = self.filedf

        self.usabledf = temp
        genes = temp.index.tolist()
        pool_genes = []
        for x in genes:
            pool_genes.append(ast.literal_eval(x))
        self.genes = pool_genes
        df = pd.read_csv('df.csv')
        _, self.binDict = qe.makeDf(df)
        self.inverseGenes()
예제 #5
0
    def evaluation_method_6(self):
        self.filedf = pd.read_csv('factsheetdf.csv', index_col='Unnamed: 0')
        self.filedf['r7-r2'] = self.filedf['r7mean'] - self.filedf['r2mean']
        self.filedf[
            'r7-r2samesign'] = self.filedf['r2mean'] * self.filedf['r7-r2'] > 0
        #for those that are of the same sign, take the highest
        self.filedf.sort_values('r7-r2', inplace=True, ascending=False)
        upper = self.filedf.head(int(len(self.filedf) * 0.4))
        upperdiffsign = upper[upper['r7-r2samesign'] == False]
        uppersamesign = upper[upper['r7-r2samesign'] == True]
        lower = self.filedf.tail(int(len(self.filedf) * 0.4))
        lowersamesign = lower[lower['r7-r2samesign'] == True]
        lowerdiffsign = lower[lower['r7-r2samesign'] == False]

        diffsigntemp = pd.concat([upperdiffsign, lowerdiffsign])
        samesigntemp = pd.concat([uppersamesign, lowersamesign])
        diffsigntemp['r7divr2'] = (diffsigntemp['r7-r2']) / abs(
            diffsigntemp['r2mean'])

        samesigntemp['r7divr2'] = (
            samesigntemp['r7-r2']) / samesigntemp['r2mean']

        samesigntemp.sort_values('r7divr2', inplace=True, ascending=False)
        diffsigntemp.sort_values('r7divr2', inplace=True, ascending=False)
        #take 20% from them
        samesigntemp = samesigntemp.head(int(len(samesigntemp) * 0.2))
        diffsigntemp = diffsigntemp.head(int(len(diffsigntemp) * 0.2))

        temp = pd.concat([samesigntemp, diffsigntemp])

        temp['r7-r2viable'] = temp['r7-r2'] * (temp['r7posrate'] -
                                               temp['r7negrate'])
        temp.sort_values('r7-r2viable', inplace=True, ascending=False)
        temp = temp.head(int(len(temp) * 0.8))

        self.usabledf = temp
        genes = temp.index.tolist()
        pool_genes = []
        for x in genes:
            pool_genes.append(ast.literal_eval(x))
        self.genes = pool_genes
        df = pd.read_csv('df.csv')
        _, self.binDict = qe.makeDf(df)
        self.inverseGenes()
예제 #6
0
# -*- coding: utf-8 -*-

import pandas as pd
import quickEngine
import numpy as np
import geneGenerator
from multiprocessing import Process, Manager, Pool
from concurrent.futures import ProcessPoolExecutor
import numpy as np
import time
import multiprocessing
import multiprocessing.pool

df = pd.read_csv('df.csv')

column_index_value_dict, binDict = quickEngine.makeDf(df)
generator = geneGenerator.geneGenerator(5,10,20)



'''
genes = generator.generateMany(100)
factsheetdict = evaluategenes(genes,column_index_value_dict)


factsheetdf = pd.DataFrame.from_dict(factsheetdict,orient='index',columns=['hits_per_day','total_hits','r2mean','r2posrate','r2negrate','r3mean','r3posrate','r3negrate','r4mean','r4posrate','r4negrate','r5mean','r5posrate','r5negrate','r6mean','r6posrate','r6negrate','r7mean','r7posrate','r7negrate','r8mean','r8posrate','r8negrate','r9mean','r9posrate','r9negrate','r10mean','r10posrate','r10negrate'])


genes = generator.generateMany(1000)
factsheetdict = evaluategenes(genes,column_index_value_dict)
factsheetdf = pd.DataFrame.from_dict(factsheetdict,orient='index',columns=['hits_per_day','total_hits','r2mean','r2posrate','r2negrate','r3mean','r3posrate','r3negrate','r4mean','r4posrate','r4negrate','r5mean','r5posrate','r5negrate','r6mean','r6posrate','r6negrate','r7mean','r7posrate','r7negrate','r8mean','r8posrate','r8negrate','r9mean','r9posrate','r9negrate','r10mean','r10posrate','r10negrate'])
예제 #7
0
    def evaluation_method_4(self):
        #First step is to get lowest 30% for all r1

        self.filedf = pd.read_csv('factsheetdf.csv', index_col='Unnamed: 0')
        self.filedf.dropna(inplace=True)
        #Calculate deal price,
        self.filedf['r0mean'] = (self.filedf['r2mean'] - 0) * 0.3
        self.filedf['r1mean'] = self.filedf['r0mean'] + (
            self.filedf['r2mean'] - self.filedf['r0mean']) / 2
        self.filedf['deal2'] = self.filedf['r2mean'] + (
            self.filedf['r3mean'] - self.filedf['r2mean']) * 0.3
        self.filedf['deal3'] = self.filedf['r3mean'] + (
            self.filedf['r4mean'] - self.filedf['r3mean']) * 0.3
        self.filedf['deal4'] = self.filedf['r4mean'] + (
            self.filedf['r5mean'] - self.filedf['r4mean']) * 0.3
        self.filedf['deal5'] = self.filedf['r5mean'] + (
            self.filedf['r6mean'] - self.filedf['r5mean']) * 0.3
        self.filedf['deal6'] = self.filedf['r6mean'] + (
            self.filedf['r7mean'] - self.filedf['r6mean']) * 0.3
        self.filedf['deal7'] = self.filedf['r7mean'] + (
            self.filedf['r8mean'] - self.filedf['r7mean']) * 0.3
        self.filedf['deal8'] = self.filedf['r8mean'] + (
            self.filedf['r9mean'] - self.filedf['r8mean']) * 0.3
        self.filedf['deal9'] = self.filedf['r9mean'] + (
            self.filedf['r10mean'] - self.filedf['r9mean']) * 0.3
        self.filedf['highest'] = self.filedf[[
            'r0mean', 'r1mean', 'r2mean', 'r3mean', 'r4mean', 'r5mean',
            'r6mean', 'r7mean', 'r8mean', 'r9mean'
        ]].max(axis=1)
        self.filedf['lowest'] = self.filedf[[
            'r0mean', 'r1mean', 'r2mean', 'r3mean', 'r4mean', 'r5mean',
            'r6mean', 'r7mean', 'r8mean', 'r9mean'
        ]].min(axis=1)
        self.filedf['profit'] = self.filedf['highest'] - self.filedf['lowest']
        self.filedf['risk'] = self.filedf['profit'] / 2

        self.filedf['maxname'] = self.filedf[[
            'r0mean', 'r1mean', 'r2mean', 'r3mean', 'r4mean', 'r5mean',
            'r6mean', 'r7mean', 'r8mean', 'r9mean'
        ]].idxmax(axis=1)
        self.filedf['minname'] = self.filedf[[
            'r0mean', 'r1mean', 'r2mean', 'r3mean', 'r4mean', 'r5mean',
            'r6mean', 'r7mean', 'r8mean', 'r9mean'
        ]].idxmin(axis=1)
        maxlist = list(map(itemgetter(1), self.filedf['maxname'].values))
        self.filedf['maxtime'] = maxlist
        self.filedf["maxtime"] = pd.to_numeric(self.filedf["maxtime"])
        minlist = list(map(itemgetter(1), self.filedf['minname'].values))
        self.filedf['mintime'] = minlist
        self.filedf["mintime"] = pd.to_numeric(self.filedf["mintime"])
        self.filedf[
            'order_type'] = self.filedf['maxtime'] > self.filedf['mintime']

        self.filedf['placetimebuy'] = self.filedf['mintime'] * 60
        self.filedf['endtimebuy'] = self.filedf['maxtime'] * 60

        self.filedf['placetimesell'] = self.filedf['maxtime'] * 60
        self.filedf['endtimesell'] = self.filedf['mintime'] * 60

        self.filedf.sort_values('profit', inplace=True, ascending=False)
        self.filedf = self.filedf[self.filedf['total_hits'] >= 20]
        self.filedf.sort_values('profit', inplace=True, ascending=False)
        self.filedf = self.filedf.head(int(len(self.filedf) * 0.5))
        temp = self.filedf

        self.usabledf = temp
        genes = temp.index.tolist()
        pool_genes = []
        for x in genes:
            pool_genes.append(ast.literal_eval(x))
        self.genes = pool_genes
        df = pd.read_csv('df.csv')
        _, self.binDict = qe.makeDf(df)
        self.inverseGenes()