コード例 #1
0
def plotRealAuto():
    '''
    Plot scatterplot of historical volatility and its one day lag
    '''
    startDate = '2018-10-19'
    endDate = '2019-10-21'
    myTic = '^GSPC'
    winvol = 22
    myRef = yfRef(mydate=startDate, undl=myTic)
    sqret = myRef.getSqRet(startDate, endDate)
    pyplot.scatter(sqret[:-1], sqret[1:])
    pyplot.show()
コード例 #2
0
def plotMeanRev(startDate='2018-10-19',
                endDate='2019-10-21',
                myTic='^GSPC',
                winvol=22):
    '''
    Plot historical realized against the average
    '''
    myRef = yfRef(mydate=startDate, undl=myTic)
    volR = myRef.getRealized(startDate, endDate, winvol)
    pyplot.plot(volR.index,
                volR,
                color='r',
                label=str(winvol) + 'd Realized Vol SP500')
    pyplot.plot(volR.index,
                np.ones(len(volR)) * np.mean(volR),
                color='k',
                label='Average')
    pyplot.legend()
    pyplot.savefig('meanRev.pdf')
    pyplot.show()
コード例 #3
0
def volSpotCorr(startDate='2018-10-03',
                endDate='2019-10-08',
                myTic='^GSPC',
                window=25):
    myRef = yfRef(mydate=startDate, undl=myTic)
    volR = myRef.getRealized(startDate, endDate, window)
    mySpot = myRef.setSpotHist(startDate, endDate)

    pyplot.scatter(mySpot, volR, color=['r', 'k'])
    z = np.polyfit(mySpot, volR, 1)
    p = np.poly1d(z)
    pyplot.plot(mySpot,
                p(mySpot),
                color='k',
                label='Trend, R^2 = ' +
                str(round(r2_score(volR, p(mySpot)), 4)))
    pyplot.xlabel('S&P 500 Spot')
    pyplot.ylabel(str(window) + 'd Realized S&P 500 Vol')
    pyplot.legend()
    pyplot.savefig('Artifacts\spotVol.pdf')
    pyplot.show()
コード例 #4
0
def plotVixAuto():
    '''
    Plot scatterplot of historical VIX and its one day lag
    '''
    startDate = '2018-10-19'
    endDate = '2019-10-21'
    myTic = '^GSPC'
    myRef = yfRef(mydate=startDate, undl=myTic)
    myVix = myRef.getVolHist(startDate, endDate)
    pyplot.scatter(myVix[:-1], myVix[1:], color=['r', 'k'])
    z = np.polyfit(myVix[:-1], myVix[1:], 1)
    p = np.poly1d(z)
    pyplot.plot(myVix[:-1],
                p(myVix[:-1]),
                color='k',
                label='Trend, R^2 = ' +
                str(round(r2_score(myVix[:-1], p(myVix[:-1])), 4)))
    pyplot.xlabel('VIX 1d Lag')
    pyplot.ylabel('VIX')
    pyplot.legend()
    pyplot.savefig('autoCorVix.pdf')
    pyplot.show()