0
Python for Finance 22.2 code repo
Hello! can you help me please to calculate the annual volatility of Bitcoin and output the risk % and calculate and output the Sharpe ratio. Thhis is my code : import yfinance as yf data = yf.Ticker("BTC-USD") print(data.info['description']) print(data.history(period='5d') ['Close']) import matplotlib.pyplot as plt price = data.history(period='2y') x = price['Close'].pct_change() returns = (x + 1).cumprod() returns.plot() plt.savefig('plot.PNG') import numpy as np data = yf.download("BTC-USD", start='2020-01-01') x = data['Close'].pct_change() annual_std= np.std(x)*np.sqrt(252) print(annual_std) sharpe= (np.mean(x)/np.std(x))*np.sqrt(252) print(sharpe)
1 Antwort
+ 1
import numpy as np
import numpy_financial as npf
import matplotlib.pyplot as plt
import yfinance as yf
#price for 2018-2021
bitcoin = [3869.47, 7188.46, 22203.31, 29391.78]
res = np.std(bitcoin)
#print(res)
arr=[-500,10,10,10,10,10,10,10,10,10,10,10,10]
r=npf.irr(arr)
#print(r)
data = yf.Ticker('BTC-USD')
x = data.history('1y')['Close']
x.plot()
plt.savefig('plot.png')