<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Momentum
A stock that's going up tends to keep going up...until it doesn't.  Momentum is the theory that stocks that have recently gone up will keep going up disproportionate to their underlying value because folks are overenthusiastic about them.
On the first trading day of each week
1. The SPY is higher than 'lookback' months ago, buy
2. If the SPY is lower than 'lookback' months ago, sell your long position.
The 'lookback' time period can be random, meaning a random lookback period is used for each new position.
Step1:  Some global data
Step2:  Run Strategy
Step3:  View logs
Step4:  Generate strategy stats - display all available stats
Step5:  Equity curve
Run Benchmark, Retrieve benchmark logs, and Generate benchmark stats
Step6:  Plot Equity Curves
Step7:  Plot Trades
Step8:  Bar Graph
<ASSISTANT_TASK:>
Python Code:
import pandas as pd
import matplotlib.pyplot as plt
import datetime
import pinkfish as pf
import strategy
# format price data
pd.options.display.float_format = '{:0.2f}'.format
%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: Momentum
A stock that's going up tends to keep going up...until it doesn't.  Momentum is the theory that stocks that have recently gone up will keep going up disproportionate to their underlying value because folks are overenthusiastic about them.
On the first trading day of each week
1. The SPY is higher than 'lookback' months ago, buy
2. If the SPY is lower than 'lookback' months ago, sell your long position.
The 'lookback' time period can be random, meaning a random lookback period is used for each new position.
End of explanation
#symbol = '^GSPC'
symbol = 'SPY'
#symbol = 'DIA'
#symbol = 'QQQ'
#symbol = 'IWM'
#symbol = 'TLT'
#symbol = 'GLD'
#symbol = 'AAPL'
#symbol = 'BBRY'
#symbol = 'GDX'
#symbol = 'OIH'
capital = 10000
start = datetime.datetime(1900, 1, 1)
#start = datetime.datetime(*pf.SP500_BEGIN)
end = datetime.datetime.now()
options = {
    'use_adj' : True,
    'use_cache' : True,
    'lookback': None,
    'margin': 1
}
Explanation: Some global data
End of explanation
s = strategy.Strategy(symbol, capital, start, end, options)
s.run()
Explanation: Run Strategy
End of explanation
s.tlog.tail(10)
s.dbal.tail()
Explanation: View logs
End of explanation
pf.print_full(s.stats)
Explanation: Generate strategy stats - display all available stats
End of explanation
benchmark = pf.Benchmark(symbol, s.capital, s.start, s.end, use_adj=True)
benchmark.run()
Explanation: Equity curve
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
pf.plot_trades(s.dbal, benchmark=benchmark.dbal)
Explanation: Plot Trades
End of explanation
df = pf.plot_bar_graph(s.stats, benchmark.stats)
df
Explanation: Bar Graph: Strategy vs Benchmark
End of explanation
<END_TASK>