示例#1
0
    def test_oneEventPerEquity(self):
        '''
        Equities: AMD
        Function: went_below(3)
        Period: 2008-1-1 -> 2009-12-31

        Tests: oneEventPerEquity=True and oneEventPerEquity=False
        '''
        self.setUpDataAccess()

        evtf = EventFinder()
        evtf.symbols = ['AMD']
        evtf.start_date = datetime(2008, 1, 1)
        evtf.end_date = datetime(2009, 12, 31)
        evtf.condition = SampleConditions.went_below(3)
        evtf.search(oneEventPerEquity=True)
        # Test: number of events found = 1
        self.assertEqual(evtf.num_events, 1)
        # Test: date of the event is 2008-10-27
        date1 = evtf.matrix['AMD'][evtf.matrix['AMD'] == 1].index[0].to_pydatetime()
        self.assertEqual(date1, datetime(2008,10,27))

        # Test: oneEventPerEquity=False
        evtf.search(oneEventPerEquity=False)
        # Test: number of events found = 2
        self.assertEqual(evtf.num_events, 2)
        # Test: date of the events
        date1 = evtf.matrix['AMD'][evtf.matrix['AMD'] == 1].index[0].to_pydatetime()
        date2 = evtf.matrix['AMD'][evtf.matrix['AMD'] == 1].index[1].to_pydatetime()
        self.assertEqual(date1, datetime(2008,10,27))
        self.assertEqual(date2, datetime(2008,11,11))
示例#2
0
    def test_window(self):
        '''
        Two events on two different equities

        Tests
        -----
            1. Expected returns
            2. Abnormal returns
            3. Cumulative abnormal returns
            4. Mean of ER, AR, CAR
        '''
        # Set Up
        self.setUpDataAccess()

        evt_fin = EventFinder()
        evt_fin.symbols = ['AMD', 'CBG']
        evt_fin.start_date = datetime(2008, 1, 1)
        evt_fin.end_date = datetime(2009, 12, 31)
        evt_fin.condition = SampleConditions.went_below(3)
        evt_fin.search()
        
        mul_evt = MultipleEvents()
        mul_evt.list = evt_fin.list
        mul_evt.market = 'SPY'
        mul_evt.lookback_days = 20
        mul_evt.lookforward_days = 20
        mul_evt.estimation_period = 200
        mul_evt.run()

        self_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
        tests = ['MultipleEvents_window_1.csv']
        tests = [os.path.join(self_dir, 'docs', test) for test in tests]
        
        for test_file in tests:
            # Set up
            solution = pd.read_csv(test_file).set_index('index')
            # Test 1
            sol_er = solution[solution.columns[0:2]]
            sol_er.columns = mul_evt.er.columns
            sol_er.columns.name = 'Expected return'
            self.assertEqual(mul_evt.er, sol_er)
            # Test 2
            sol_ar = solution[solution.columns[3:5]]
            sol_ar.columns = mul_evt.ar.columns
            sol_ar.columns.name = 'Abnormal return'
            self.assertEqual(mul_evt.ar, sol_ar)
            # Test 3
            sol_car = solution[solution.columns[6:8]]
            sol_car.columns = mul_evt.car.columns
            sol_car.columns.name = 'Cum abnormal return'
            self.assertEqual(mul_evt.car, sol_car)
            # Test 4
            self.assertEqual(mul_evt.mean_er, solution['Mean ER'])
            self.assertEqual(mul_evt.mean_ar, solution['Mean AR'])
            self.assertEqual(mul_evt.mean_car, solution['Mean CAR'])
示例#3
0
from datetime import datetime
from finance.events import SampleConditions
from finance.events import EventFinder

# from finance.utils import DataAccess
# DataAccess.path = 'data'

evtf = EventFinder()
evtf.symbols = ['AMD', 'CBG', 'AAPL']
evtf.start_date = datetime(2008, 1, 1)
evtf.end_date = datetime(2010, 12, 31)
evtf.condition = SampleConditions.went_below(10)
evtf.search(useCache=False)

print(evtf.num_events)
print(evtf.list)
            label = self.mean_ar.name
        elif which == "er":
            y = self.mean_er.values
            yerr = self.std_er.values
            label = self.mean_er.name
        errorfill(x, y, yerr, label=label)


if __name__ == "__main__":
    from datetime import datetime
    import matplotlib.pyplot as plt
    from finance.events import EventFinder
    from finance.events import SampleConditions

    evtf = EventFinder()
    evtf.symbols = ["AMD", "CBG"]
    evtf.start_date = datetime(2008, 1, 1)
    evtf.end_date = datetime(2009, 12, 31)
    evtf.condition = SampleConditions.went_below(3)
    evtf.search()

    mevt = MultipleEvents()
    mevt.list = evtf.list
    mevt.market = "SPY"
    mevt.lookback_days = 20
    mevt.lookforward_days = 20
    mevt.estimation_period = 200
    mevt.run()

    mevt.plot("car")
    plt.legend()
示例#5
0
            label = self.mean_ar.name
        elif which == 'er':
            y = self.mean_er.values
            yerr = self.std_er.values
            label = self.mean_er.name
        errorfill(x, y, yerr, label=label)


if __name__ == '__main__':
    from datetime import datetime
    import matplotlib.pyplot as plt
    from finance.events import EventFinder
    from finance.events import SampleConditions

    evtf = EventFinder()
    evtf.symbols = ['AMD', 'CBG']
    evtf.start_date = datetime(2008, 1, 1)
    evtf.end_date = datetime(2009, 12, 31)
    evtf.condition = SampleConditions.went_below(3)
    evtf.search()

    mevt = MultipleEvents()
    mevt.list = evtf.list
    mevt.market = 'SPY'
    mevt.lookback_days = 20
    mevt.lookforward_days = 20
    mevt.estimation_period = 200
    mevt.run()

    mevt.plot('car')
    plt.legend()
示例#6
0
            yerr = self.std_ar.values
            label = self.mean_ar.name
        elif which == 'er':
            y = self.mean_er.values
            yerr = self.std_er.values
            label = self.mean_er.name
        errorfill(x, y, yerr, label=label)

if __name__ == '__main__':
    from datetime import datetime
    import matplotlib.pyplot as plt
    from finance.events import EventFinder
    from finance.events import SampleConditions

    evtf = EventFinder()
    evtf.symbols = ['AMD', 'CBG']
    evtf.start_date = datetime(2008, 1, 1)
    evtf.end_date = datetime(2009, 12, 31)
    evtf.condition = SampleConditions.went_below(3)
    evtf.search()

    mevt = MultipleEvents()
    mevt.list = evtf.list
    mevt.market = 'SPY'
    mevt.lookback_days = 20
    mevt.lookforward_days = 20
    mevt.estimation_period = 200
    mevt.run()
    print(mevt.mean_car)

    #mevt.plot('car')
from datetime import datetime
from finance.events import SampleConditions
from finance.events import EventFinder

# from finance.utils import DataAccess
# DataAccess.path = 'data'

evtf = EventFinder()
evtf.symbols = ["AMD", "CBG", "AAPL"]
evtf.start_date = datetime(2008, 1, 1)
evtf.end_date = datetime(2010, 12, 31)
evtf.condition = SampleConditions.went_below(10)
evtf.search(useCache=False)

print(evtf.num_events)
print(evtf.list)
from datetime import datetime
from finance.events import SampleConditions
from finance.events import EventFinder

# from finance.utils import DataAccess
# DataAccess.path = 'data'

evtf = EventFinder()
evtf.symbols = ['AMD', 'CBG', 'AAPL']
evtf.start_date = datetime(2008, 1, 1)
evtf.end_date = datetime(2010, 12, 31)
evtf.condition = SampleConditions.went_below(10)
evtf.search(useCache=False)

print("Number of events: {0}".format(evtf.num_events))
print(evtf.list)