code: def main(plot):
      initialCash = 10000
      instrumentsByClass = {
          "US Stocks": ["VTI"],
          "Foreign Stocks": ["VEU"],
          "US 10 Year Government Bonds": ["IEF"],
          "Real Estate": ["VNQ"],
          "Commodities": ["DBC"],
      }
  
      # Load the bars. These files were manually downloaded from Yahoo Finance.
      feed = yahoofeed.Feed()
      instruments = ["SPY"]
      for assetClass in instrumentsByClass:
          instruments.extend(instrumentsByClass[assetClass])
  
      for year in range(2007, 2013 + 1):
          for instrument in instruments:
              fileName = "%s-%d-yahoofinance.csv" % (instrument, year)
              print("Loading bars from %s" % fileName)
              feed.addBarsFromCSV(instrument, fileName)
  
      # Build the strategy and attach some metrics.
      strat = MarketTiming(feed, instrumentsByClass, initialCash)
      sharpeRatioAnalyzer = sharpe.SharpeRatio()
      strat.attachAnalyzer(sharpeRatioAnalyzer)
      returnsAnalyzer = returns.Returns()
      strat.attachAnalyzer(returnsAnalyzer)
  
      if plot:
          plt = plotter.StrategyPlotter(strat, False, False, True)
          plt.getOrCreateSubplot("cash").addCallback(
              "Cash", lambda x: strat.getBroker().getCash()
          )
          # Plot strategy vs. SPY cumulative returns.
          plt.getOrCreateSubplot("returns").addDataSeries(
              "SPY",
              cumret.CumulativeReturn(feed["SPY"].getPriceDataSeries()),
          )
          plt.getOrCreateSubplot("returns").addDataSeries(
              "Strategy", returnsAnalyzer.getCumulativeReturns()
          )
  
      strat.run()
      print(
          "Sharpe ratio: %.2f"
          % sharpeRatioAnalyzer.getSharpeRatio(0.05)
      )
      print(
          "Returns: %.2f %%"
          % (returnsAnalyzer.getCumulativeReturns()[-1] * 100)
      )
  
      if plot:
          plt.plot()
  
imports: from __future__ import print_function
  from pyalgotrade import strategy
  from pyalgotrade import plotter
  from pyalgotrade.barfeed import yahoofeed
  from pyalgotrade.technical import ma
  from pyalgotrade.technical import cumret
  from pyalgotrade.stratanalyzer import sharpe
  from pyalgotrade.stratanalyzer import returns
label_desc: Use image node_id 1 for calling a global function with example usage: main(plot) without return types