コード例 #1
0
class RuntimePerformance:
    def __init__(self, user):
        self._user = user
        self._mongo_user = MongoUser(user)
        self._performance = None
        self._performance_manager = None

    @property
    def positions(self):
        return {item.id: item for item in map(Position.from_dict, self._mongo_user.collection.positions.find())}

    @property
    def deals(self):
        return {item.id: item for item in map(Deal.from_dict, self._mongo_user.collection.deals.find())}

    @property
    def profit_records(self):
        return list(self._mongo_user.collection.PnLs.find())

    @property
    def performance(self):
        if self._performance is None:
            self._performance_manager = StrategyPerformanceManagerOnline(self.profit_records, self.deals,
                                                                         self.positions)
            self._performance = self._performance_manager.get_performance()
        return self._performance
コード例 #2
0
 def get_sharpe(self, start_time, end_time, simple=True):
     si, ei = self.get_index(start_time, end_time)
     if si >= len(self.__pnl):
         return 0
     records = self.__pnl[si:ei]
     manager = StrategyPerformanceManagerOnline(records, {}, {})
     performance = manager.get_performance()
     if simple:
         return performance.sharpe_ratio.total
     else:
         return performance.sharpe_ratio_compound.total
コード例 #3
0
class RuntimePerformance:
    def __init__(self, user):
        self._user = user
        self._mongo_user = MongoUser(user)
        self._performance = None
        self._performance_manager = None
        self._positions = None
        self._deals = None
        self._profit_records = None

    @property
    def positions(self):
        if self._positions is None:
            self._positions = {item.id: item for item in
                               map(Position.from_dict,
                                   self._mongo_user.collection.positions.find(projection={"_id": False}))}
        return self._positions

    @property
    def deals(self):
        if self._deals is None:
            self._deals = {item.id: item for item in
                           map(Deal.from_dict, self._mongo_user.collection.deals.find(projection={"_id": False}))}
        return self._deals

    @property
    def profit_records(self):
        if self._profit_records is None:
            self._profit_records = list(self._mongo_user.collection.PnLs.find(projection={"_id": False}))
        return self._profit_records

    @property
    def performance(self):
        if self._performance is None:
            self._performance_manager = StrategyPerformanceManagerOnline(self.profit_records, self.deals,
                                                                         self.positions)
            self._performance = self._performance_manager.get_performance()
        return self._performance

    @property
    def empty(self):
        if self._mongo_user.collection.PnLs.count() == 0:
            return True
        if self._mongo_user.collection.positions.count() == 0:
            return True
        if self._mongo_user.collection.deals.count() == 0:
            return True
        return False