Last active
March 20, 2017 14:16
-
-
Save ciela/44c394c3f862234d721c127d1314b42f to your computer and use it in GitHub Desktop.
ポートフォリオのシミューレション
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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