Updated Oct/04/2023 by
購入時の価格に対して10% の幅で価格が上下して、最終的に元に戻った場合に、レバレッジドインデックスに投資された資産がどうなるかを計算する。
def get_assets(asset, prices, leverage_rate = 1.0):
assets = [ asset ]
rates = []
for i in range(1, len(prices)):
old_price = prices[i-1]
new_price = prices[i]
moving_rate = (new_price - old_price) / old_price
rates.append(moving_rate * leverage_rate)
asset *= (1 + moving_rate * leverage_rate)
assets.append(int(asset))
return assets, rates
initial_assets = 10000
def get_rate(x):
return (x - 10000) / 10000 * 100
print(get_rate(9454))
print(get_rate(9333))
print(get_rate(7878))
print(get_rate(8484))
株価 | 10000 | 11000 | 10000 |
---|---|---|---|
変動率 | +10% | -9.09% | |
変動率$\times 3$ | +30% | -27.27% | |
資産 | 10000 | 13000 | 9454 |
$10000$ 円が $9454$ 円になるので、$-5.46$ %の損失となる。
prices0 = [100, 110, 100]
assets0, rates0 = get_assets(initial_assets, prices0)
assets0x3, rates0x3 = get_assets(initial_assets, prices0, 3)
print(assets0)
print(assets0x3)
print(rates0)
print(rates0x3)
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(1, 1, figsize=(6, 4))
n0 = len(assets0)
ax.plot([0, n0-1], [initial_assets, initial_assets], c='black')
ax.plot(range(n0), assets0, c='blue', marker='o', label='x1')
ax.plot(range(n0), assets0x3, c='red', marker='o', label='x3')
ax.set_title(f'moving_price = {prices0}')
ax.legend()
plt.show()
株価 | 10000 | 9000 | 10000 |
---|---|---|---|
変動率 | -10% | +11.11% | |
変動率$\times 3$ | -30% | +33.33% | |
資産 | 10000 | 7000 | 9333 |
$10000$ 円が $9333$ 円になるので、$-6.67$ %の損失となる。
prices1 = [10000, 9000, 10000]
assets1, rates1 = get_assets(initial_assets, prices1)
assets1x3, rates1x3 = get_assets(initial_assets, prices1, 3)
print(assets1)
print(assets1x3)
print(rates1)
print(rates1x3)
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(1, 1, figsize=(6, 4))
n1 = len(assets1)
ax.plot([0, n1-1], [initial_assets, initial_assets], c='black')
ax.plot(range(n1), assets1, c='blue', marker='o', label='x1')
ax.plot(range(n1), assets1x3, c='red', marker='o', label='x3')
ax.set_title(f'moving_price = {prices1}')
ax.legend()
plt.show()
株価 | 10000 | 11000 | 9000 | 10000 |
---|---|---|---|---|
変動率 | +10% | -18.18% | +11.11 | |
変動率$\times 3$ | +30% | -54.55% | +33.33% | |
資産 | 10000 | 13000 | 5909 | 7878 |
$10000$ 円が $7878$ 円になるので $-21.22$ % の損失となる。
prices2 = [100, 110, 90, 100]
assets2, rates2 = get_assets(initial_assets, prices2)
assets2x3, rates2x3 = get_assets(initial_assets, prices2, 3)
print(assets2)
print(assets2x3)
print(rates2)
print(rates2x3)
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(1, 1, figsize=(6, 4))
n2 = len(assets2)
ax.plot([0, n2-1], [initial_assets, initial_assets], c='black')
ax.plot(range(n2), assets2, c='blue', marker='o', label='x1')
ax.plot(range(n2), assets2x3, c='red', marker='o', label='x3')
ax.set_title(f'moving_price = {prices2}')
ax.legend()
plt.show()
株価 | 10000 | 9000 | 11000 | 10000 |
---|---|---|---|---|
変動率 | -10% | +22.22% | -9.09% | |
変動率$\times 3$ | -30% | +66.67% | -27.27% | |
資産 | 10000 | 13000 | 5909 | 7878 |
$10000$ 円が $8484$ 円になるので $-15.16$ % の損失となる。
prices3 = [100, 90, 110, 100]
assets3, rates3 = get_assets(10000, prices3)
assets3x3, rates3x3 = get_assets(10000, prices3, 3)
print(assets3)
print(assets3x3)
print(rates3)
print(rates3x3)
print(get_rate(assets3x3[3]))
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(1, 1, figsize=(6, 4))
n3 = len(assets3)
ax.plot([0, n3-1], [initial_assets, initial_assets], c='black')
ax.plot(range(n3), assets3, c='blue', marker='o', label='x1')
ax.plot(range(n3), assets3x3, c='red', marker='o', label='x3')
ax.set_title(f'moving_price = {prices3}')
ax.legend()
plt.show()