コード例 #1
0
tsPortfolioValues = pd.TimeSeries(lValues,ldtDates)

# Get the stats
print 'Analyzing Portfolio...'
[portCumRet, portAvgDailyRet, portVol, portSharpe] = analyzeTimeSeries(tsPortfolioValues)

# make keys for loading bench data
lsKeys = ['open','high','low','close','volume','actual_close']

# set time offset for market close to load data
dtTimeOfDay = dt.timedelta(hours=16)

print 'Analyzing benchmark %s...' % benchSymbol

# Load benchmark data
benchData = loadNYSEData.loadNYSEData(ldtDates[0], ldtDates[-1], dtTimeOfDay, 'Yahoo', [benchSymbol], lsKeys)

# Um...why do 'close' and 'open' give the same 
# value?  Need to look into this further b/c
# some experimentation in marketsim really showed
# they don't, so why does it seem that way here?
# not relevant to making this work, but still...
print "benchData[close]: {}".format(benchData['close'])

dfBenchClosePrices = benchData['close']
ldtDateIndex = dfBenchClosePrices.index

tsBenchValues = pd.TimeSeries(dfBenchClosePrices[benchSymbol], ldtDateIndex)

# Analyze the benchmark time series data
[benchCumRet, benchAvgDailyRet, benchVol, benchSharpe] = analyzeTimeSeries(tsBenchValues)
コード例 #2
0
endDate = lsDates[-1]
print 'Date and time of first trade: %s.' % startDate
print 'Date and time of last trade: %s.' % endDate

# End date should be offset by 1 day to read the
# close for the last date.
startRead = startDate
endRead = endDate + dt.timedelta(days=1)

lsKeys = ['open','high','low','close','volume','actual_close']

dtTimeOfDay = dt.timedelta(hours=16)

# read in the data
nyseData = loadNYSEData.loadNYSEData(
        startRead, endRead, dtTimeOfDay, 'Yahoo',
        lsSymbols, lsKeys
        )

# and load the adjusted close prices
dfClosePrices = pd.DataFrame(nyseData['close'])
ldtDateIndex = dfClosePrices.index

print 'Building holdings and cash data...'
# initialize the holdings dataframe
dfHoldings = pd.DataFrame(None,index=ldtDateIndex,
        columns=lsSymbols)

# need to go through orders, look up prices for any
# create timeseries index dates and initialize to 
# null values
tsCash = pd.TimeSeries(None, ldtDateIndex)