January 2020
Beginner to intermediate
432 pages
11h 24m
English
Execute the following steps to simulate Microsoft's stock prices one month ahead.
import numpy as npimport pandas as pdimport yfinance as yf
RISKY_ASSET = 'MSFT'START_DATE = '2019-01-01'END_DATE = '2019-07-31'
df = yf.download(RISKY_ASSET, start=START_DATE, end=END_DATE, adjusted=True)
adj_close = df['Adj Close']returns = adj_close.pct_change().dropna()print(f'Average return: {100 * returns.mean():.2f}%')returns.plot(title=f'{RISKY_ASSET} returns: {START_DATE} - {END_DATE}')
The code produces the following plot:
And the following line:
Average return: 0.24%
Read now
Unlock full access