util.py - \"MLT Utility code import os import pandas as pd import matplotlib.pyplot as plt def symbol_to_path(symbol base_dir=os.path.join\"data\"Return

util.py - "MLT Utility code import os import pandas as pd...

This preview shows page 1 out of 1 page.

"""MLT: Utility code.""" import os import pandas as pd import matplotlib.pyplot as plt def symbol_to_path(symbol, base_dir=os.path.join("..", "data")): """Return CSV file path given ticker symbol.""" return os.path.join(base_dir, "{}.csv".format(str(symbol))) def get_data(symbols, dates, addSPY=True, colname='Adj Close'): """Read stock data (adjusted close) for given symbols from CSV files.""" df = pd.DataFrame(index=dates) if addSPY and 'SPY' not in symbols: # add SPY for reference, if absent symbols = ['SPY'] + symbols for symbol in symbols: df_temp = pd.read_csv(symbol_to_path(symbol), index_col='Date',
Image of page 1

You've reached the end of your free preview.

Want to read the whole page?

  • Fall '10
  • BOB
  • #, Comma-separated values, Return CSV file

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes