Exemplo n.º 1
0
    def test_min_track_record_length_paper_examples(self):
        sr_std = estimated_sharpe_ratio_stdev(n=134, skew=-0.2250, kurtosis=2.9570, sr=0.7079)
        min_trl = min_track_record_length(sr_benchmark=0, prob=0.95, n=134, sr=0.7079, sr_std=sr_std)
        self.assertAlmostEqual(round(min_trl/12, 4), 0.7152)  # minTRL was in years in the paper (and SR was monthly)

        sr_std = estimated_sharpe_ratio_stdev(n=134, skew=-1.4455, kurtosis=7.0497, sr=0.8183)
        min_trl = min_track_record_length(sr_benchmark=0, prob=0.95, n=134, sr=0.8183, sr_std=sr_std)
        self.assertAlmostEqual(round(min_trl/12, 4), 1.1593)  # minTRL was in years in the paper (and SR was monthly)
Exemplo n.º 2
0
    def test_probabilistic_sharpe_ratio_paper_examples(self):
        sr_std = estimated_sharpe_ratio_stdev(n=24, skew=0, kurtosis=3, sr=0.458)
        psr = probabilistic_sharpe_ratio(sr_benchmark=0, sr=0.458, sr_std=sr_std)
        self.assertAlmostEqual(round(psr, 3), 0.982)

        sr_std = estimated_sharpe_ratio_stdev(n=24, skew=-2.448, kurtosis=10.164, sr=0.458)
        psr = probabilistic_sharpe_ratio(sr_benchmark=0, sr=0.458, sr_std=sr_std)
        self.assertAlmostEqual(round(psr, 3), 0.913)

        psr = probabilistic_sharpe_ratio(sr_benchmark=0, sr=0.7079, sr_std=0.1028)
        self.assertAlmostEqual(round(psr, 4), 1.0)  # minTRL=0.7152 years

        psr = probabilistic_sharpe_ratio(sr_benchmark=0, sr=0.8183, sr_std=0.1550)
        self.assertAlmostEqual(round(psr, 4), 1.0)  # minTRL=1.1593 years
Exemplo n.º 3
0
    def test_estimated_sharpe_ratio_stdev(self):
        EXPECTED_SR_STD = 0.16466174867277414

        # pd.Series
        sr_std = estimated_sharpe_ratio_stdev(self.returns)
        self.assertAlmostEqual(sr_std, EXPECTED_SR_STD)

        # pd.DataFrame
        returns_df = self.returns.to_frame()
        sr_std = estimated_sharpe_ratio_stdev(returns_df)
        pd.testing.assert_series_equal(sr_std, pd.Series(EXPECTED_SR_STD, index=returns_df.columns))

        # np.array
        sr_std = estimated_sharpe_ratio_stdev(self.returns.values)
        self.assertAlmostEqual(sr_std, EXPECTED_SR_STD)
Exemplo n.º 4
0
    def test_min_track_record_length(self):
        SR_BENCHMARK = 0.05
        PROB = 0.90
        EXPECTED_MIN_TRL = 60.365085269027084

        sr = estimated_sharpe_ratio(self.returns)
        sr_std = estimated_sharpe_ratio_stdev(self.returns)
        psr = probabilistic_sharpe_ratio(self.returns, SR_BENCHMARK)

        # pd.Series
        min_trl = min_track_record_length(self.returns, SR_BENCHMARK, PROB)
        self.assertAlmostEqual(min_trl, EXPECTED_MIN_TRL)

        # pd.DataFrame
        returns_df = self.returns.to_frame()
        min_trl = min_track_record_length(returns_df, SR_BENCHMARK, PROB)
        pd.testing.assert_series_equal(min_trl, pd.Series(EXPECTED_MIN_TRL, index=returns_df.columns))

        # np.array
        min_trl = min_track_record_length(self.returns.values, SR_BENCHMARK, PROB)
        self.assertAlmostEqual(min_trl, EXPECTED_MIN_TRL)
Exemplo n.º 5
0
    def test_estimated_sharpe_ratio_stdev_paper_examples(self):
        sr_std = estimated_sharpe_ratio_stdev(n=134, skew=-0.2250, kurtosis=2.9570, sr=0.7079)
        self.assertAlmostEqual(round(sr_std, 4), 0.1028)

        sr_std = estimated_sharpe_ratio_stdev(n=134, skew=-1.4455, kurtosis=7.0497, sr=0.8183)
        self.assertAlmostEqual(round(sr_std, 4), 0.1550)
# Plotting the returns distribution, we can confirm that strategy 1 returns have a big negative skewness, and this makes bigger the stdDev of its SR^ estimates, so we have less certainty on our estimation (lower PSR).

sns.distplot(pd.Series(returns_st1),
             hist=True,
             kde=True,
             color='red',
             bins=SIZE // 2).set_title('Strategy 1 returns distribution')

sns.distplot(pd.Series(returns_st2),
             hist=True,
             kde=True,
             color='green',
             bins=SIZE // 2).set_title('Strategy 2 returns distribution')

# +
estimated_sr_std_st1 = estimated_sharpe_ratio_stdev(returns_st1)
estimated_sr_std_st2 = estimated_sharpe_ratio_stdev(returns_st2)

print('The estimated SR^ of strategy 1 have a stdDev of: ',
      estimated_sr_std_st1)
print('The estimated SR^ of strategy 2 have a stdDev of: ',
      estimated_sr_std_st2)
# -

# ## Out-of-sample checks
#
# **Now we will check if our decision of investing in strategy 2 instead of investing in the strategy 1 (that had a better SR), was a good or bad decision.**
#
# For that we will generate extra, and bigger, samples of each distribution and chechk wich strategy have a better SR.
# > Incresing the number of returns/samples for calcualting the SR^ makes the stdDev of this estimation drop drastically.