コード例 #1
0
ファイル: DataAccess.py プロジェクト: zxlstoner/PythonFinance
def benchmark():
    from time import clock, time
    da = DataAccess('./data')
    da.empty_dirs(delete=False)

    print ('Directory empty: Download and save 5 stocks')
    t1, t2 = clock(), time()
    symbols = ["AAPL","GLD","GOOG","SPY","XOM"]
    start_date = datetime(2008, 1, 1)
    end_date = datetime(2009, 12, 31)
    fields = "Close"
    da.get_data(symbols, start_date, end_date, fields)
    t1_f, t2_f = clock(), time()
    print ("   ", t1_f - t1, t2_f - t2)

    print ('Load 5 stocks from .csv')
    t1, t2 = clock(), time()
    symbols = ["AAPL","GLD","GOOG","SPY","XOM"]
    start_date = datetime(2008, 1, 1)
    end_date = datetime(2009, 12, 31)
    fields = "Close"
    da.get_data(symbols, start_date, end_date, fields, useCache=False)
    t1_f, t2_f = clock(), time()
    print ("   ", t1_f - t1, t2_f - t2)

    print ('Load 5 stocks from serialized')
    t1, t2 = clock(), time()
    symbols = ["AAPL","GLD","GOOG","SPY","XOM"]
    start_date = datetime(2008, 1, 1)
    end_date = datetime(2009, 12, 31)
    fields = "Close"
    da.get_data(symbols, start_date, end_date, fields, useCache=True)
    t1_f, t2_f = clock(), time()
    print ("   ", t1_f - t1, t2_f - t2)
コード例 #2
0
    def __init__(self):
        self.data_access = DataAccess()

        self.list = None
        self.market = 'SPY'
        self.lookback_days = 20
        self.lookforward_days = 20
        self.estimation_period = 200
        self.field = 'Adj Close'

        # Result
        self.equities_window = None
        self.equities_estimation = None
        self.market_window = None
        self.market_estimation = None

        self.reg_estimation = None

        self.dr_equities_window = None
        self.dr_equities_estimation = None
        self.dr_market_window = None
        self.dr_market_estimation = None

        self.er = None
        self.ar = None
        self.car = None
コード例 #3
0
    def setUpDataAccess(self, delete=False):
        self_dir = os.path.dirname(
            os.path.abspath(inspect.getfile(inspect.currentframe())))
        DataAccess.path = os.path.join(self_dir, 'data')
        self.data_access = DataAccess()

        self.data_access.empty_cache(delete=delete)
        self.data_access.empty_dir(delete=delete)
コード例 #4
0
    def __init__(self):
        self.da = DataAccess()

        self.initial_cash = 0
        self.field = 'adjusted_close'

        self.trades = None
        self.prices = None
        self.num_of_shares = None
        self.cash = None
        self.equities = None
        self.portfolio = None
コード例 #5
0
    def __init__(self):
        self.data_access = DataAccess()

        self.symbols = []
        self.start_date = None
        self.end_date = None
        self.field = 'Adj Close'

        self.condition = Condition()
        self.matrix = None
        self.num_events = 0

        self.oneEventPerEquity = True
コード例 #6
0
    def __init__(self):
        # Utils
        self.data_access = DataAccess()

        # Variables
        self.date = None  # Date of the event
        self.symbol = None
        self.field = 'adjusted_close'
        self.lookback_days = 20
        self.lookforward_days = 20
        self.estimation_period = 255
        self.market = "SPY"

        # Results
        self.evt_window_data = None
        self.er = None
        self.ar = None
        self.car = None
        self.t_test = None
        self.prob = None
コード例 #7
0
import os
from datetime import datetime
from finance.utils import DataAccess

# Option 1: Set the Enviroment Variable FINANCEPATH
os.environ["FINANCEPATH"] = './data'
da = DataAccess()
symbols = ["GOOG", "SPY", "XOM"]
start_date = datetime(2015, 1, 1)
end_date = datetime(2017, 12, 31)
fields = 'close'
close = da.get_data(symbols, start_date, end_date, fields)
print(close)

# Option 2: Manualy set the PATH, overwrites option 1

DataAccess.path = 'data2'
da = DataAccess()

symbols = ["AAPL", "GLD"]
start_date = datetime(2015, 1, 1)
end_date = datetime(2017, 12, 31)
fields = 'close'
close = da.get_data(symbols, start_date, end_date, fields)
print(close)

コード例 #8
0
 def delete_data():
     self_dir = os.path.dirname(
         os.path.abspath(inspect.getfile(inspect.currentframe())))
     DataAccess.path = os.path.join(self_dir, 'data')
     data_access = DataAccess()
     data_access.empty_dirs()