<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Futures Trend Following Portfolio
1. The Security closes with 50/100 ma &gt; 0, buy.
2. If the Security closes 50/100 ma &lt; 0, sell your long position.
(For a Portfolio of futures.)
NOTE
Step1:  Investment Universe
Step2:  Run Strategy
Step3:  View log DataFrames
Step4:  Generate strategy stats - display all available stats
Step5:  View Performance by Symbol
Step6:  Run Benchmark, Retrieve benchmark logs, and Generate benchmark stats
Step7:  Plot Equity Curves
Step8:  Bar Graph
Step9:  Analysis
<ASSISTANT_TASK:>
Python Code:
import datetime
import matplotlib.pyplot as plt
import pandas as pd
import pinkfish as pf
import strategy
# Format price data.
pd.options.display.float_format = '{:0.2f}'.format
pd.set_option('display.max_rows', None)
%matplotlib inline
# Set size of inline plots
'''note: rcParams can't be in same cell as import matplotlib
   or %matplotlib inline
   
   %matplotlib notebook: will lead to interactive plots embedded within
   the notebook, you can zoom and resize the figure
   
   %matplotlib inline: only draw static images in the notebook
'''
plt.rcParams["figure.figsize"] = (10, 7)
Explanation: Futures Trend Following Portfolio
1. The Security closes with 50/100 ma &gt; 0, buy.
2. If the Security closes 50/100 ma &lt; 0, sell your long position.
(For a Portfolio of futures.)
NOTE: pinkfish does not yet have full support for futures backtesting, and
the futures data from yahoo finance isn't very good.
End of explanation
# symbol: (description, multiplier)
equities = {
    'ES=F':  ('E-Mini S&P 500 Futures', 50),
    'YM=F':  ('Mini Dow Jones Futures', 5),
    'NQ=F':  ('Nasdaq 100 Futures', 20),
}
interest_rates = {
    'ZB=F':  ('U.S. Treasury Bond Futures', 1000),
    'ZN=F':  ('10-Year T-Note Futures', 1000),
    'ZF=F':  ('Five-Year US Treasury Note Futures', 1000),
    'ZT=F':  ('2-Year T-Note Futures', 2000) 
}
# https://www.cmegroup.com/markets/agriculture.html#products
agricultural_commodities = {
# Grains
    'ZC=F':  ('Corn Futures', 5000),
    'KE=F':  ('KC HRW Wheat Futures', 5000),
    'ZS=F':  ('Soybean Futures', 50),
    'KE=F':  ('KC HRW Wheat Futures', 50),
    'ZR=F':  ('Rough Rice Futures', 2000),
    'ZM=F':  ('Soybean Meal Futures', 100),
    'ZL=F':  ('Soybean Oil Futures', 600),
    'GF=F':  ('Feeder Cattle Futures', 500),
    'HE=F':  ('Lean Hogs Futures', 400),
    'CC=F':  ('Cocoa Futures', 10),
    'KC=F':  ('Coffee Futures', 375),
    'CT=F':  ('Cotton Futures', 50000),
    'LBS=F':  ('Lumber Futures', 110),
     'SB=F':  ('Sugar #11 Futures', 1120)
}
non_agricultural_commodities = {
    'GC=F':  ('Gold Futures', 100),
    'SI=F':  ('Silver Futures', 5000),
    'PL=F':  ('Platinum Futures', 50),
    'HG=F':  ('Copper Futures', 25000),
    'PA=F':  ('Palladium Futures', 100),
    'CL=F':  ('Crude Oil Futures', 1000),
    'HO=F':  ('Heating Oil Futures', 42000),
    'NG=F':  ('Natural Gas Futures', 10000),
    'RB=F':  ('RBOB Gasoline Futures', 42000)
}
# https://www.cmegroup.com/markets/fx.html#products
currency_multiplier = 100
currencies = {
# G10
    'DX=F':  ('U.S. Dollar Index', currency_multiplier),
    '6E=F':  ('Euro FX Futures', currency_multiplier),
    '6J=F':  ('Japanese Yen Futures', currency_multiplier),
    '6A=F':  ('Australian Dollar Futures', currency_multiplier),
    '6B=F':  ('British Pound Futures', currency_multiplier),
    '6C=F':  ('Canadian Dollar Futures', currency_multiplier),
    '6S=F':  ('Swiss Franc Futures', currency_multiplier),
    '6N=F':  ('New Zealand Dollar Futures', currency_multiplier),   
}
futures = {**equities, **interest_rates, **agricultural_commodities,
                 **non_agricultural_commodities, **currencies}
ten_largest = ['ZN=F', 'ES=F', 'CL=F', 'GC=F', 'ZC=F', 'KC=F', 'CT=F', 'DX=F']
symbols = list(ten_largest)
#symbols = ['ES=F', 'GC=F', 'CL=F']
capital = 100_000
start = datetime.datetime(1900, 1, 1)
end = datetime.datetime.now()
options = {
    'use_adj' : False,
    'use_cache' : True,
    'sell_short' : False,
    'force_stock_market_calendar' : True,
    'margin' : 2,
    'sma_timeperiod_slow': 100,
    'sma_timeperiod_fast': 50,
    'use_vola_weight' : True
}
Explanation: Investment Universe:  
Futures contracts cover these main asset classes:
- Equities
- Interest rates
- Agricultural commodities
- Non-agricultural commodities
- Currencies
FUTURES
https://finance.yahoo.com/commodities?.tsrc=fin-srch
https://www.barchart.com/futures/contract-specifications/currencies
End of explanation
s = strategy.Strategy(symbols, capital, start, end, options=options)
s.run()
Explanation: Run Strategy
End of explanation
s.rlog.head()
s.tlog.head()
s.dbal.tail()
Explanation: View log DataFrames: raw trade log, trade log, and daily balance
End of explanation
pf.print_full(s.stats)
Explanation: Generate strategy stats - display all available stats
End of explanation
weights = {symbol: 1 / len(symbols) for symbol in symbols}
totals = s.portfolio.performance_per_symbol(weights=weights)
totals
corr_df = s.portfolio.correlation_map(s.ts)
corr_df
Explanation: View Performance by Symbol
End of explanation
benchmark = pf.Benchmark('SPY', s.capital, s.start, s.end, use_adj=True)
benchmark.run()
Explanation: Run Benchmark, Retrieve benchmark logs, and Generate benchmark stats
End of explanation
pf.plot_equity_curve(s.dbal, benchmark=benchmark.dbal)
Explanation: Plot Equity Curves: Strategy vs Benchmark
End of explanation
df = pf.plot_bar_graph(s.stats, benchmark.stats)
df
Explanation: Bar Graph: Strategy vs Benchmark
End of explanation
kelly = pf.kelly_criterion(s.stats, benchmark.stats)
kelly
Explanation: Analysis: Kelly Criterian
End of explanation
<END_TASK>