What does Hsi stand for in stock market in python?
HANG SENG INDEX (^HSI) is stock market Hong Kong.
What country is hsi?
Hong kong
Why is hsi droping?
We have described below through python
How to download hsi stock price in python?
!pip install yfinance
import yfinance as yf
import numpy as np
import pandas as pd
import seaborn as sns
import scipy.stats as scs
import statsmodels.api as sm
import statsmodels.tsa.api as smt
import matplotlib.pyplot as plt
This is the stock price of hsi from 1985 to 2021
df = yf.download('^HSI',
start='1985-01-01',
end='2021-07-07',
progress=False)
df = df.loc[:, ['Adj Close']]
df.rename(columns={'Adj Close':'adj_close'}, inplace=True)
df['simple_rtn'] = df.adj_close.pct_change()
df['log_rtn'] = np.log(df.adj_close/df.adj_close.shift(1))
df[['simple_rtn','log_rtn']].tail(20)
Stock price of Hsi simple and log return
simple_rtn | log_rtn | |
---|---|---|
Date | ||
2021-06-07 | -0.004524 | -0.004534 |
2021-06-08 | -0.000205 | -0.000205 |
2021-06-09 | -0.001346 | -0.001347 |
2021-06-10 | -0.000130 | -0.000130 |
2021-06-11 | 0.003593 | 0.003586 |
2021-06-15 | -0.007059 | -0.007084 |
2021-06-16 | -0.007043 | -0.007068 |
2021-06-17 | 0.004281 | 0.004272 |
2021-06-18 | 0.008498 | 0.008462 |
2021-06-21 | -0.010842 | -0.010901 |
2021-06-22 | -0.006292 | -0.006311 |
2021-06-23 | 0.017920 | 0.017761 |
2021-06-24 | 0.002269 | 0.002267 |
2021-06-25 | 0.014049 | 0.013951 |
2021-06-28 | -0.000680 | -0.000680 |
2021-06-29 | -0.009369 | -0.009413 |
2021-06-30 | -0.005730 | -0.005747 |
2021-07-02 | -0.017952 | -0.018115 |
2021-07-05 | -0.005896 | -0.005914 |
2021-07-06 | -0.002510 | -0.002513 |
How to get realised volatily of hsi?
def realized_volatility(x):
return np.sqrt(np.sum(x**2))
df_rv = df.groupby(pd.Grouper(freq='M')).apply(realized_volatility)
df_rv.rename(columns={'log_rtn': 'rv'}, inplace=True)
df_rv.rv = df_rv.rv * np.sqrt(12)
fig, ax = plt.subplots(2, 1, sharex=True)
ax[0].plot(df)
ax[1].plot(df_rv)
0 Comments