<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 SMA ROC Portfolio
1. The Security is above its 200-day moving average
2. The Security closes with sma_roc &gt; 0, buy.
3. If the Security closes with sma_roc &lt; 0, sell your long position.
(For a Portfolio of securities.)
Step1:  Some global data
Yahoo finance cryptocurrencies
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: SMA ROC Portfolio
1. The Security is above its 200-day moving average
2. The Security closes with sma_roc &gt; 0, buy.
3. If the Security closes with sma_roc &lt; 0, sell your long position.
(For a Portfolio of securities.)
End of explanation
# Symbol Lists
BitCoin = ['BTC-USD']
CryptoCurrencies_2016 = ['BTC-USD', 'ETH-USD', 'XRP-USD', 'LTC-USD',
                         'XEM-USD', 'DASH-USD', 'MAID-USD', 'LSK-USD', 'DOGE-USD']
# 'DAO-USD' is a dead coin, so missing from above
CryptoCurrencies_2017 = ['BTC-USD', 'ETH-USD', 'XRP-USD', 'LTC-USD', 'ETC-USD',
                         'XEM-USD', 'MIOTA-USD', 'DASH-USD', 'BTS-USD']
# 'STRAT-USD' last trade date is 2020-11-18, so removed
CryptoCurrencies_2018 = ['BTC-USD', 'ETH-USD', 'XRP-USD', 'BCH-USD', 'EOS-USD',
                         'LTC-USD', 'XLM-USD', 'ADA-USD', 'TRX-USD', 'MIOTA-USD']
CryptoCurrencies_2019 = ['BTC-USD', 'ETH-USD', 'XRP-USD', 'LTC-USD', 'BCH-USD',
                         'EOS-USD', 'BNB-USD', 'USDT-USD', 'BSV-USD', 'CRO-USD']
Stocks_Bonds_Gold_Crypto = ['SPY', 'QQQ', 'TLT', 'GLD', 'BTC-USD']
# Set 'continuous_timeseries' : False (for mixed asset classes)
start_1900 = datetime.datetime(1900, 1, 1)
start_2016 = datetime.datetime(2016, 6, 26)
start_2017 = datetime.datetime(2017, 6, 25)
start_2018 = datetime.datetime(2018, 6, 24)
start_2019 = datetime.datetime(2019, 6, 30)
# Pick one of the above symbols and start pairs
symbols = CryptoCurrencies_2016
start = start_2016
capital = 10000
end = datetime.datetime.now()
# NOTE: Cryptocurrencies have 7 days a week timeseries.  You can test them with
# their entire timeseries by setting stock_market_calendar=False.  Alternatively,
# to trade with stock market calendar by setting stock_market_calendar=True.
# For mixed asset classes that include stocks or ETFs, you must set
# stock_market_calendar=True.
options = {
    'use_adj' : False,
    'use_cache' : True,
    'use_continuous_calendar' : False,
    'force_stock_market_calendar' : True,
    'stop_loss_pct' : 1.0,
    'margin' : 1,
    'lookback' : 1,
    'sma_timeperiod': 20,
    'sma_pct_band': 3,
    'use_regime_filter' : False,
    'use_vola_weight' : True
}
Explanation: Some global data
Yahoo finance cryptocurrencies:
https://finance.yahoo.com/cryptocurrencies/
10 largest Crypto currencies from 5 years ago:
https://coinmarketcap.com/historical/20160626/   
10 largest Crypto currencies from 4 years ago:
https://coinmarketcap.com/historical/20170625/
10 largest Crypto currencies from 3 years ago:
https://coinmarketcap.com/historical/20180624/
10 largest Crypto currencies from 2 years ago:
https://coinmarketcap.com/historical/20190630/
Some global data
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('BTC-USD', 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>