コード例 #1
0
ファイル: metric.py プロジェクト: IanMadlenya/ultra-finance
    def calculate(self, timePositions, iTimePositionDict):
        ''' calculate basic metrics '''
        if not timePositions:
            return self.result

        # get max value, min value, max draw down
        lastHigest = 0
        maxDrawDownTimeStamp = 0
        maxDrawDownPosition = 0
        for (timeStamp, position) in timePositions:
            if self.result[BasicMetric.MAX_TIME_VALUE][0] is None or self.result[BasicMetric.MAX_TIME_VALUE][1] < position:
                self.result[BasicMetric.MAX_TIME_VALUE] = timeStamp, position
            if self.result[BasicMetric.MIN_TIME_VALUE][0] is None or self.result[BasicMetric.MIN_TIME_VALUE][1] > position:
                self.result[BasicMetric.MIN_TIME_VALUE] = timeStamp, position
            if position > lastHigest:
                lastHigest = position
                maxDrawDownPosition = position
                maxDrawDownTimeStamp = timeStamp
            elif maxDrawDownPosition > position:
                maxDrawDownPosition = position
                maxDrawDownTimeStamp = timeStamp

        self.result[BasicMetric.MAX_DRAW_DOWN] = (0, 0) if lastHigest == 0 else \
            (maxDrawDownTimeStamp, 1 - (maxDrawDownPosition / lastHigest))
        self.result[BasicMetric.START_TIME] = timePositions[0][0]
        self.result[BasicMetric.END_TIME] = timePositions[-1][0]
        self.result[BasicMetric.END_VALUE] = timePositions[-1][1]
        self.result[BasicMetric.STDDEV] = stddev([timePosition[1] for timePosition in timePositions])
        self.result[BasicMetric.SRATIO] = sharpeRatio([timePosition[1] for timePosition in timePositions])
        self.result[BasicMetric.R_SQUARED] = rsquared([tp[1] for tp in timePositions], [iTimePositionDict.get(tp[0], tp[1]) for tp in timePositions])

        return self.result
コード例 #2
0
ファイル: metric.py プロジェクト: Geraldes/ultra-finance
    def calculate(self, timePositions):
        ''' calculate basic metrics '''
        for (timeStamp, position) in timePositions:
            if self.result[BasicMetric.MAX][0] is None or self.result[BasicMetric.MAX][1] < position:
                self.result[BasicMetric.MAX] = timeStamp, position
            if self.result[BasicMetric.MIN][0] is None or self.result[BasicMetric.MIN][1] > position:
                self.result[BasicMetric.MIN] = timeStamp, position

        self.result[BasicMetric.STDDEV] = stddev([timePosition[1] for timePosition in timePositions])
        self.result[BasicMetric.SRATIO] = sharpeRatio([timePosition[1] for timePosition in timePositions])

        return self.result
コード例 #3
0
ファイル: metric.py プロジェクト: spidermanJie/ultra-finance
    def calculate(self, timePositions):
        ''' calculate basic metrics '''
        for (timeStamp, position) in timePositions:
            if self.result[BasicMetric.MAX][0] is None or self.result[
                    BasicMetric.MAX][1] < position:
                self.result[BasicMetric.MAX] = timeStamp, position
            if self.result[BasicMetric.MIN][0] is None or self.result[
                    BasicMetric.MIN][1] > position:
                self.result[BasicMetric.MIN] = timeStamp, position

        self.result[BasicMetric.STDDEV] = stddev(
            [timePosition[1] for timePosition in timePositions])
        self.result[BasicMetric.SRATIO] = sharpeRatio(
            [timePosition[1] for timePosition in timePositions])

        return self.result