Skip to content

Instantly share code, notes, and snippets.

Last active Sep 14, 2021
What would you like to do?
import matplotlib.pyplot as plt
from yfapi import YahooFinanceAPI
import datetime
from simulation import GBMMonteCarlo
import pandas as pd
ticker = 'aapl'
api = YahooFinanceAPI()
end =
start = datetime.datetime(end.year - 2, end.month,
spdata = api.get_ticker_data(ticker, start, end)
gbmmc = GBMMonteCarlo()
paths =[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)[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()))[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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment