Exemplo n.º 1
0
 def __compute_final_stats(self):
     self._final_stats["MeanProfit"] = np.mean(
         self._trade_detail["EverytimeProfit"])
     self._final_stats["MaxLoss"] = np.min(
         self._trade_detail["EverytimeProfit"])
     self._final_stats["FinalProfit"] = self._trade_detail[
         "EverytimeProfit"].values[-1]
     self._final_stats["MeanProfitPer"] = round(
         self._final_stats["MeanProfit"] / self.trader_fund * 100, 2)
     self._final_stats["FinalProfitPer"] = round(
         self._final_stats["FinalProfit"] / self.trader_fund * 100, 2)
     self._final_stats["MaxLossPer"] = round(
         self._final_stats["MaxLoss"] / self.trader_fund * 100, 2)
     # +1, calculate_Datenbr not include last day
     trade_days = (calculate_Datenbr(
         self._trade_detail["date"].min(),
         self._trade_detail["date"].max(),
     ) + 1)
     trade_years = (trade_days + 1) / 365
     # +1, self._trade_detail wihtout contain first day
     self._final_stats["AnnualReturnPer"] = round(
         ((self._final_stats["FinalProfitPer"] / 100 + 1)**
          (1 / trade_years) - 1) * 100,
         2,
     )
     timestep_returns = (self._trade_detail["EverytimeProfit"] -
                         self._trade_detail["EverytimeProfit"].shift(1)) / (
                             self._trade_detail["EverytimeProfit"].shift(1)
                             + self.trader_fund)
     stratagy_return = np.mean(timestep_returns)
     stratagy_std = np.std(timestep_returns)
     self._final_stats["AnnualSharpRatio"] = calculate_sharp_ratio(
         stratagy_return, stratagy_std)
Exemplo n.º 2
0
 def __compute_final_stats(self):
     self._final_stats["MeanProfit"] = np.mean(
         self._trade_detail["EverytimeProfit"]
     )
     self._final_stats["MaxLoss"] = np.min(
         self._trade_detail["EverytimeProfit"]
     )
     self._final_stats["FinalProfit"] = self._trade_detail[
         "EverytimeProfit"
     ].values[-1]
     self._final_stats["MeanProfitPer"] = round(
         self._final_stats["MeanProfit"] / self.trader_fund * 100, 2
     )
     self._final_stats["FinalProfitPer"] = round(
         self._final_stats["FinalProfit"] / self.trader_fund * 100, 2
     )
     self._final_stats["MaxLossPer"] = round(
         self._final_stats["MaxLoss"] / self.trader_fund * 100, 2
     )
     self._final_stats["AnnualReturnPer"] = round(
         convert_Return2Annual(
             self._final_stats["FinalProfitPer"] / 100,
             self._trade_period_years,
         )
         * 100,
         2,
     )
     timestep_returns = (
         self._trade_detail["EverytimeProfit"]
         - self._trade_detail["EverytimeProfit"].shift(1)
     ) / (self._trade_detail["EverytimeProfit"].shift(1) + self.trader_fund)
     stratagy_return = np.mean(timestep_returns)
     stratagy_std = np.std(timestep_returns)
     self._final_stats["AnnualSharpRatio"] = calculate_sharp_ratio(
         stratagy_return, stratagy_std
     )
Exemplo n.º 3
0
def test_calculate_sharp_ratio(retrun, std, expected):
    resp = calculate_sharp_ratio(retrun, std)
    assert resp == expected