Exemple #1
0
    def get_benchmark(self, benchmark_ticker='^GSPC'):

        if benchmark_ticker == 'sp500' or benchmark_ticker == '^GSPC':
            _ticker = '^GSPC'
        else:
            _ticker = '^GSPC'  # S&P 500 as default

        # create security class object for benchmark ticker
        _benchmark = Security(_ticker, start=self.min_date, end=self.max_date)

        # calculate returns for the benchmark
        _benchmark.data = returns_column(df=_benchmark.data, column='Close')

        self.benchmark = _benchmark
Exemple #2
0
    def get_returns(self, column='Total'):
        try:
            self.data
        except AttributeError:
            self.get_timeseries()
        else:
            pass

        self.data_growth = returns_column(df=self.data_growth, column=column)

        # get date range from the transaction list
        self.min_date = min(self.transactions.Date.min(),
                            self.payments.Date.min())
        self.max_date = datetime.datetime.now()

        # make a list of days between min and max date as index for timeseries df
        date_index = pd.date_range(self.min_date, self.max_date, freq='D')
        _ts = pd.Series(range(len(date_index)), index=date_index)

        # create timeseries df from date index and wallet entries
        _df_ts = _ts.to_frame('Day')
        #

        # join in daily price change data for each security
        cols = []
        for security in self.tickers:
            _series = self.securities[security].data['Close']
            _col_name = str(_series.name) + "_" + security
            _series = _series.rename(_col_name)
            _df_ts = _df_ts.join(_series, how='left',
                                 rsuffix='').fillna(method='ffill')
            _df_ts = returns_column(df=_df_ts,
                                    column=_col_name,
                                    outname=security)
            cols.append(_col_name)

        self.returns = _df_ts.drop(cols, axis=1)
Exemple #3
0
    def get_benchmark(self, benchmark_ticker='^GSPC'):

        self.min_date = self.data.index.min()
        self.max_date = min(self.data.index.max(), datetime.datetime.now())

        if benchmark_ticker == 'sp500' or benchmark_ticker == '^GSPC':
            _ticker = '^GSPC'
        else:
            _ticker = '^GSPC'  # S&P 500 as default

        # create security class object for benchmark ticker
        _benchmark = Security(_ticker, start=self.min_date, end=self.max_date)

        # calculate returns for the benchmark
        _benchmark.data = returns_column(df=_benchmark.data,
                                         column='Close',
                                         uselogs=True)

        self.benchmark = _benchmark
Exemple #4
0
 def get_returns(self, column='Close'):
     self.data = returns_column(df=self.data, column=column)
Exemple #5
0
 def get_returns(self, column='Total'):
     self.data = returns_column(df=self.data, column=column)