print(key)
    print(future_contract.to_dict()[key])
    print('\n')
futures_position_value = get_pricing(future_contract, start_date = '2017-01-01', end_date = '2018-01-01', fields = 'price')
futures_position_value.name = futures_position_value.name.symbol
futures_position_value.plot()
plt.title('NG Futures Price')
plt.xlabel('Date')
plt.ylabel('Price');
# ## Historical Data
print history.__doc__
# In[88]:
ngf18 = future_contract
ngf18_data = history(ngf18, 
                     fields=['price', 'open_price', 'high', 'low', 'close_price', 'volume', 'contract'], 
                     frequency='daily', 
                     start_date='2017-06-01', 
                     end_date='2017-08-01')
ngf18_data.head()
# Notice the 4th of July!
ngf18_data['volume'].plot(kind='bar')
# ## Comparison of Different Maturity Dates
ng_contracts = symbols(['NGF17', 'NGG17', 'NGH17', 'NGJ17', 'NGK17', 'NGM17'])
ng_consecutive_contract_volume = history(ng_contracts, 
                                         fields='volume', 
                                         frequency='daily', 
                                         start_date='2016-01-01', 
                                         end_date='2017-08-01')
ng_consecutive_contract_volume.plot()
ng_consecutive_contract_volume.plot(xlim=['2016-10-01','2017-08-01'])
# Trading activity jumps from one contract to the next. Transitions happen just prior to the delivery date of each contract.
]
Prices = []
Correlation = []
Order = []

# In[ ]:

#Pulls data for all futures listed above and curve fits them via Math filter we created

for x in FutureTicker:

    y = continuous_future(x, roll='volume')

    y = history(y,
                fields='price',
                frequency='daily',
                start='2018-10-21',
                end='2018-10-21')

    x = pd.Series(
        scipy.signal.savgol_filter(y, 31, 2, 0, 1.0, -1, 'interp', 0.0))

    Prices.append(x)

# In[40]:

#Finds every possible Correlation between futures

for i in range(0, len(FutureTicker) - 1):
    for x in range(i + 1, len(FutureTicker)):
        Correlation.append((Prices[i].corr(Prices[x])))
from quantopian.research.experimental import continuous_future
import scipy
import numpy
numpy.arange
import matplotlib.pyplot as plt


# In[3]:


WTI = continuous_future( 'CL', roll = 'volume' ) #Crude Oil Futures

WTI = history(
    WTI, 
    fields='price', 
    frequency='daily', 
    start='2008-08-31', 
    end='2018-08-31'
)

Corn = continuous_future( 'CN' , roll = 'volume')  #Corn Futures

Corn = history(
    Corn, 
    fields='price', 
    frequency='daily', 
    start='2008-08-31', 
    end='2018-08-31'
)

Esempio n. 4
0

"""
SAMPLE COMMODODITIES, INDEX, CURRENCY (FOREX) FUTURES ARE ALL AVAILABLE ON QUANTOPIAN
"""

future_contract = symbols('NGF20')  # NG (Natural Gas) F (January Future) 20 (2020)
for key in future_contract.to_dict():
    print("{} -> {}".format(key, future_contract.to_dict()[key]))

futures_position_value = get_pricing(future_contract, start_date='2017-01-01', end_date='2018-01-01')
futures_position_value.name = futures_position_value.name.symbol
futures_position_value.plot()
# NOW, LET'S GET SOME HISTORICAL DATA
ngf20 = future_contract  # RESET A NEW SHORTER VARIABLE :')
ngf20_data = history(ngf20, fields=['price', 'open_price', 'high', 'low', 'close_price', 'volume', 'contract'],
                     frequency='daily', start_date='2017-06-01', end_date='2017-08-01')
ngf20_data.head(); ngf20_data.plot()  # WORK WITH THIS DATAFRAME HOWEVER
# F - January, G - February, ...
ng_contracts = symbols(['NGF18', 'NGG18', 'NGH18', 'NGJ18', 'NGK18', 'NGM18'])

#   FIRST, WORKING WITH CONSECUTIVE FUTURES
ng_consecutive_contract_volume = history(ng_contracts, fields='volume', frequency='daily',
                                         start_date='2017-08-01', end_date='2017-08-01')
ng_consecutive_contract_volume.plot()  # ANOTHER DATAFRAME :)
# VOLUME BEING TRADED INCREASES FUTURE'S PRICE AS IT ALSO INCREASES
# BUT ALSO, AS THE FUTURE'S MATURITY DATE APPROACHES, IT'S PRICE BEGINS TO REDUCE GRADUALLY

#   NOW, WORKING WITH CONTINUOUS FUTURES
ng_continuous = continuous_future('NG', offset=0, roll='volume', adjustment='mul')  # / 'add' / 'nul'
ng_continuous_active = history(ng_continuous, fields=['contract', 'price', 'volume'],
                               frequency='daily', start_date='2018-10-01', end_date='2019-08-01')
from quantopian.research.experimental import continuous_future
import scipy
import numpy
numpy.arange
import matplotlib.pyplot as plt


# In[11]:


WTI = continuous_future( 'CL', roll = 'volume' ) #Crude Oil Futures

WTI = history(
    WTI, 
    fields='price', 
    frequency='daily', 
    start='2014-04-01', 
    end='2015-01-29'
)

Corn = continuous_future( 'CN' , roll = 'volume')  #Corn Futures

Corn = history(
    Corn, 
    fields='price', 
    frequency='daily', 
    start='2014-10-01', 
    end='2015-05-29'
)

Corn2 = continuous_future( 'CN' , roll = 'volume')  #Corn Futures