LoslegenKostenlos loslegen

A Dog on a Leash? (Part 1)

The Heating Oil and Natural Gas prices are pre-loaded in DataFrames HO and NG. First, plot both price series, which look like random walks. Then plot the difference between the two series, which should look more like a mean reverting series (to put the two series in the same units, we multiply the heating oil prices, in $/gallon, by 7.25, which converts it to $/millionBTU, which is the same units as Natural Gas).

The data for continuous futures (each contract has to be spliced together in a continuous series as contracts expire) was obtained from Quandl.

Diese Übung ist Teil des Kurses

Time Series Analysis in Python

Kurs anzeigen

Anleitung zur Übung

  • Plot Heating Oil, HO, and Natural Gas, NG, on the same subplot
    • Make sure you multiply the HO price by 7.25 to match the units of NG
  • Plot the spread on a second subplot
    • The spread will be 7.25*HO - NG

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Plot the prices separately
plt.subplot(2,1,1)
plt.plot(7.25*___, label='Heating Oil')
plt.plot(___, label='Natural Gas')
plt.legend(loc='best', fontsize='small')

# Plot the spread
plt.subplot(2,1,2)
plt.plot(___*HO-___, label='Spread')
plt.legend(loc='best', fontsize='small')
plt.axhline(y=0, linestyle='--', color='k')
plt.show()
Code bearbeiten und ausführen