Skip to content

Instantly share code, notes, and snippets.

@jcbagneris
Created December 10, 2012 13:31
Show Gist options
  • Save jcbagneris/4250572 to your computer and use it in GitHub Desktop.
Save jcbagneris/4250572 to your computer and use it in GitHub Desktop.
Coursera Computational Finance Course - HW3 helper
#!/usr/bin/env python
# -*- coding: utf8 -*-
"""
Comp. Finance Course HW3 : Simulator
"""
import argparse as ap
import datetime as dt
import pandas as pd
import qstkutil.qsdateutil as du
import qstkutil.DataAccess as da
argparser = ap.ArgumentParser(
description="Takes an order file and outputs a values file.")
argparser.add_argument("cash", type=float)
argparser.add_argument("infile")
argparser.add_argument("outfile")
args = argparser.parse_args()
print "Starting with " + str(args.cash) + " dollars."
print "Input file: " + args.infile
print "Values file: " + args.outfile
# read orders file
names_spec = ['year', 'month', 'day', 'symbol', 'direction', 'qty', 'foo']
dates_spec = {'date': ['year', 'month', 'day']}
orders = pd.read_csv(args.infile, header=None, names=names_spec,
parse_dates=dates_spec, index_col='date')
del orders['foo']
print orders
#wait for user input
foo = raw_input("\nPress enter\n")
#get our timestamps for our trading days, print them to the screen
startday = orders.index.min()
endday = orders.index.max()
timeofday=dt.timedelta(hours=16)
timestamps = du.getNYSEdays(startday,endday,timeofday)
print "\n\n", timestamps
#wait for user input
foo = raw_input("\nPress enter\n")
#get list of unique symbols
symbols = orders['symbol'].unique()
#load in data
dataobj = da.DataAccess('Yahoo')
close = dataobj.get_data(timestamps, symbols, "close")
print symbols
print "variable 'close' is ", type(close), " object class"
print close
@dhd1956
Copy link

dhd1956 commented Dec 24, 2012

I get a syntax error on pd.read.csv. It doesn't like index_col='date'. It is expecting an integer value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment