Skip to content

Instantly share code, notes, and snippets.

@Eugenio-Bruno
Created March 15, 2020 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Eugenio-Bruno/65f546459e196462d04c4ab8fe14bb8d to your computer and use it in GitHub Desktop.
Save Eugenio-Bruno/65f546459e196462d04c4ab8fe14bb8d to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import numpy as np
ursus = """
-1.9
35
26.7
14.9
32.1
70.5
-31
-15.5
-43.8
+46.2
-40.8
-14.2
5.4
-1.3
-0.8
47.4
18.2
35.4
-32.2
-15.8
3.3
""".strip().split("\n")
ursus = [float(x) / 100 + 1 for x in ursus]
market = """
17.1
18.6
5.1
16.6
31.6
-3.2
30.4
7.7
10.1
1.3
37.5
23.0
33.3
28.6
21.0
-9.2
-11.9
-22.2
28.6
10.9
-0.9
""".strip().split("\n")
market = [float(x) / 100 + 1 for x in market]
STARTING_CAPITAL = 1
ursus_cumulative = [STARTING_CAPITAL]
market_cumulative = [STARTING_CAPITAL]
neutral_cumulative = [STARTING_CAPITAL]
mktlvg_cumulative = [STARTING_CAPITAL]
leveraged_cumulative = [STARTING_CAPITAL]
for year in range(len(ursus)):
u = ursus[year]
m = market[year]
m2 = 1 + (market[year] - 1) * 2
ursus_cumulative.append(u * ursus_cumulative[-1])
market_cumulative.append(m * market_cumulative[-1])
mktlvg_cumulative.append(m2 * market_cumulative[-1])
neutral_cumulative.append((m * neutral_cumulative[-1] + u * neutral_cumulative[-1]) / 2)
leveraged_cumulative.append((m2 * leveraged_cumulative[-1] + u * leveraged_cumulative[-1]) / 2)
plt.plot(ursus_cumulative)
plt.plot(market_cumulative)
plt.plot(mktlvg_cumulative)
plt.plot(neutral_cumulative)
plt.plot(leveraged_cumulative)
plt.legend(("Short only", "SPY", "SPY with 2x leverage", "Chanos market neutral", "Chanos 190/90"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment