Skip to content

Instantly share code, notes, and snippets.

@ciela
Last active March 20, 2017 14:16
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 ciela/44c394c3f862234d721c127d1314b42f to your computer and use it in GitHub Desktop.
Save ciela/44c394c3f862234d721c127d1314b42f to your computer and use it in GitHub Desktop.
ポートフォリオのシミューレション
import sys
import numpy as np
import numpy.random as rnd
import matplotlib.pyplot as plt
A = 0.7
SEED = 10000
TRIAL = 100
def calc_assets(portfolio, days):
result = SEED
for _ in range(days):
seed_a = result * portfolio
seed_b = result - seed_a
result = 2 * rnd.choice([seed_a, seed_b], p=[A, 1.0 - A])
return result
def main():
portfolio, days = float(sys.argv[1]), int(sys.argv[2])
log10_results = []
for _ in range(TRIAL):
assets = calc_assets(portfolio, days)
log10_results.append(np.floor(np.log10(assets / SEED)).astype('int'))
log10_hist, log10_bin, _ = plt.hist(log10_results)
print(log10_hist)
print(log10_bin)
plt.show()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment