-
-
Save anthonymorast/41bea0839695bec06959050dbac777b8 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 matplotlib.pyplot as plt | |
from yfapi import YahooFinanceAPI | |
import datetime | |
from simulation import GBMMonteCarlo | |
import pandas as pd | |
ticker = 'aapl' | |
api = YahooFinanceAPI() | |
end = datetime.datetime.today() | |
start = datetime.datetime(end.year - 2, end.month, end.day) | |
spdata = api.get_ticker_data(ticker, start, end) | |
gbmmc = GBMMonteCarlo() | |
paths = gbmmc.run([ticker], 50, '2023-9-14', data_months=12, plot_results=True) | |
sim_prices = pd.DataFrame(paths[ticker][0], columns=["sim_open"]) | |
sim_prices["changes"] = sim_prices.sim_open.pct_change() | |
spdata["changes"] = spdata.Open.pct_change() | |
max, min = spdata.changes.max()*1.1, spdata.changes.min()*1.1 | |
fig, (ax1, ax2) = plt.subplots(2, 1) | |
ax1.bar([i for i in range(len(spdata) - 1)], spdata["changes"][1:], color="darkgreen") | |
ax1.set_ylim(min, max) | |
ax1.set_title("Actual {} Movements (Daily % Change)".format(ticker.upper())) | |
ax2.bar([i for i in range(len(sim_prices) - 1)], sim_prices["changes"][1:], color="darkred") | |
ax2.set_title("Simulated {} Movements (Daily % Change)".format(ticker.upper())) | |
ax2.set_ylim(min, max) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment