示例#1
0
文件: match.py 项目: ccphillippi/AFP
 def get_vol( self, com1, com2, date1, date2 ):
     begin = datetime.strptime( date1, '%Y-%m-%d' )
     end = datetime.strptime( date2, '%Y-%m-%d' )
     filepath = retrieve.adjustedClosesFilepath( filename = 'cleanSP.csv' )
     dailyPrices = matrices.getEmpiricalDataFrame( [ com1, com2 ], begin, end, csvPath = filepath )
     
     p1 = dailyPrices[ com1 ]  # ystockquote.get_historical_prices( [com1], '20' + date1, '20' + date2 )
     p2 = dailyPrices[ com2 ]  # ystockquote.get_historical_prices( [com2], '20' + date1, '20' + date2 )
     n1 = p1 / p1.iat[ 0 ]
     n2 = p2 / p2.iat[ 0 ]
     diff = n1 - n2
     return numpy.std( diff, axis = 0 )
示例#2
0
import afp.settings as settings
import afp.strategies as strats
import cleaner.retrieve as retrieve
import numpy as np
import pandas as pd
import datetime
import os

if __name__ == '__main__':
    begin = datetime.date( 2011, 1, 3 )
    end = datetime.date( 2013, 11, 27 )
    tickerList = keywords.getTickerList()
    keywordsMap = keywords.getKeywordToIndexMap()
    sentCounter = count.SentimentWordCounter( keywordsMap, sentiment.classifier() )
    mentionCounter = count.WordCounter( keywordsMap )
    empiricalDf = matrices.getEmpiricalDataFrame( tickerList, begin, end )
    constrained = False
    minVarBenchmark = { True : 'minvarConstrained.csv', False : 'minvarAnalytical.csv' }
    maxDivBenchmark = { True : 'maxDivConstrained.csv', False : 'maxDivAnalytical.csv' }
    minvarBenchmarkDf = matrices.getEmpiricalDataFrame( [ strats.MinimumVariance().getName() ], begin, end, retrieve.adjustedClosesFilepath( filename = minVarBenchmark[ constrained ] ) )  
    maxDivBenchmarkDf = matrices.getEmpiricalDataFrame( [ strats.MaximumDiversification().getName() ], begin, end, retrieve.adjustedClosesFilepath( filename = maxDivBenchmark[ constrained ] ) )
    riskParityDf = matrices.getEmpiricalDataFrame( [ strats.RiskParity().getName() ], begin, end, retrieve.adjustedClosesFilepath( filename = 'riskParity.csv' ) )   
    benchmarkDf = matrices.getEmpiricalDataFrame( [ 'OEF', 'SPY' ], begin, end, retrieve.benchmarkFilepath() )
    summedSentDf = matrices.getCountDataFrame( tickerList, sentCounter, empiricalDf.index, aggregator = np.sum )
    articleSentDf = matrices.getCountDataFrame( tickerList, sentCounter, empiricalDf.index )
    summedMentionDf = matrices.getCountDataFrame( tickerList, mentionCounter, empiricalDf.index, aggregator = np.sum )
    articleMentionDf = matrices.getCountDataFrame( tickerList, mentionCounter, empiricalDf.index )
    empiricalDf = empiricalDf.ix[:, summedMentionDf.columns ]
    empiricalCov = strats.EmpiricalCovariance( empiricalDf )
    
    saveBenchmarks = False
示例#3
0
"""
Created on Mar 13, 2014

@author: curly
"""

import afp.keywords as keywords
import afp.matrices as matrices
import afp.settings as settings
import cleaner.retrieve as retrieve
import pandas as pd
import datetime
import os

if __name__ == "__main__":
    begin = datetime.date(2011, 1, 3)
    end = datetime.date(2013, 11, 27)
    tickerList = keywords.getTickerList(os.path.join(settings.KEYWORDS_DIR, "splist.csv"))
    filepath = retrieve.adjustedClosesFilepath(filename="cleanSP.csv")
    dailyPrices = matrices.getEmpiricalDataFrame(tickerList, begin, end, csvPath=filepath)
    normalizedPrices = dailyPrices / dailyPrices.ix[0]
    pairs = dict(
        (first + "|" + second, sum((normalizedPrices[first] - normalizedPrices[second]) ** 2))
        for first in normalizedPrices.columns
        for second in normalizedPrices.columns
        if first < second
    )
    pairDf = pd.DataFrame(pairs, index=["Pairs"]).T
    pairDf.to_csv(os.path.join(settings.RESULTS_DIR, "leastSqPairs.csv"))