Example #1
0
import utility.windutility as wu
from datetime import date
import seaborn as sns

today = date.today()
startdate = wu.tdaysoffset(-120, today)
enddate = wu.tdaysoffset(-1, today)

bars = wu.wsd('000001.SH','open, close', startdate, enddate)
bars['return'] = bars.close / bars.open - 1
sns.distplot(bars['return'])
# -*- coding: utf-8 -*-
import utility.windutility as wu
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from datetime import date, timedelta
from pptx import Presentation

# tracking 50ETF historical volatility and implied volatility

enddate = wu.tdaysoffset(-1, date.today())
startdate = enddate - timedelta(60)
firstdate = date(2015,12,31)

sh510050 = wu.wsd('000016.SH', 'close', startdate, enddate)
sh510050['ret'] = sh510050['close'].pct_change()
sh510050['vol_10d'] = pd.rolling_std(sh510050['ret'], window = 10) * np.sqrt(240)
sh510050['vol_20d'] = pd.rolling_std(sh510050['ret'], window = 20) * np.sqrt(240)

ivix = wu.wsd('IVIX.SH', 'close', startdate, enddate) / 100

# pic 1: price vs implied volatility
plt.figure()
sh510050['close'].plot(label = u'上证50')
ivix['close'].plot(label = 'IVIX', secondary_y = True)
plt.legend()
plt.savefig('D:\\reports\\pic\\1.png')

# pic 2: implied vol and rolling 5 day volatility
plt.figure()
sh510050['vol_10d'].plot(label = '10 days vol')
Example #3
0
import utility.windutility as wu
import numpy as np
from datetime import date
import talib
tickerList = ['000001.SH']

# enddate = wu.tdaysoffset(-1, date.today())
enddate = date.today()
startdate = wu.tdaysoffset(-240, date.today())
data = wu.wsd(tickerList, 'close', startdate, enddate)
close = np.array(list(data['close']))
talib.MACD(close)
Example #4
0
# -*- coding: utf-8 -*-
import utility.windutility as wu
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from datetime import date, timedelta
from pptx import Presentation

# tracking 50ETF historical volatility and implied volatility

enddate = wu.tdaysoffset(-1, date.today())
startdate = enddate - timedelta(60)
firstdate = date(2015,12,31)

sh510050 = wu.wsd('000016.SH', 'close', startdate, enddate)
sh510050['ret'] = sh510050['close'].pct_change()
sh510050['vol_10d'] = pd.rolling_std(sh510050['ret'], window = 10) * np.sqrt(240)
sh510050['vol_20d'] = pd.rolling_std(sh510050['ret'], window = 20) * np.sqrt(240)

ivix = wu.wsd('IVIX.SH', 'close', startdate, enddate) / 100

# pic 1: price vs implied volatility
plt.figure()
sh510050['close'].plot(label = u'上证50')
ivix['close'].plot(label = 'IVIX', secondary_y = True)
plt.legend()
plt.savefig('D:\\reports\\pic\\1.png')

# pic 2: implied vol and rolling 5 day volatility
plt.figure()
sh510050['vol_10d'].plot(label = '10 days vol')