Beispiel #1
0
 def adjusted_returns(self):
     index_prices = PriceTable.head(self.lookback)[self.index]
     index_returns = daily_returns(index_prices).to_frame()
     df = (1 + self.daily_returns[self.stock]) / (
         1 + index_returns[self.index] * self.beta) - 1
     df.name = 'Adj. Returns'
     return df
    def __init__(self, stock: 'str', lookback: 'int'):
        self.stock = stock
        self.lookback = lookback

        self.price_table = PriceTable.head(self.lookback)[[self.stock]]
        self.daily_returns = daily_returns(self.price_table).head(
            self.lookback)
Beispiel #3
0
 def adjusted_returns(self):
     index_prices = PriceTable.head(self.lookback)[self.index]
     index_returns = daily_returns(index_prices).to_frame()
     adj_returns_df = (1 + self.daily_returns[self.stock]) / (
         1 + index_returns[self.index] * self.beta) - 1
     adj_returns_df.name = self.adjusted_returns_df_column_name
     adj_returns_df = adj_returns_df.to_frame()
     return adj_returns_df
 def __init__(self, stock: 'str', index: 'str', lookback: 'int', ScrubParams: 'obj'):
     self.stock = stock
     self.index = index
     self.lookback = lookback
     self.ScrubParams = ScrubParams
     
     self.price_table = PriceTable.head(self.lookback)[[self.stock, self.index]]
     self.daily_returns = daily_returns(self.price_table)
Beispiel #5
0
 def base_price(self):
     if self.base == self.stock:
         return self.price_table.tail(1)[self.stock].iloc[0]
     elif type(self.base) is str:
         return PriceTable.head(self.lookback).tail(1)[self.base].iloc[0]
     elif type(self.base) == float or type(self.base == int):
         return self.base
     else:
         raise ValueError
    def __init__(self, stock: 'str', lookback: 'int', base = None):
        self.stock = stock
        self.lookback = lookback
        if base is None:
            self.base = self.stock
        else:
            self.base = base

        self.price_table = PriceTable.head(self.lookback)[[self.stock]]
        self.daily_returns = daily_returns(self.price_table).head(self.lookback)
Beispiel #7
0
    def __init__(self, stock: 'str', index: 'str', lookback: 'int',
                 ScrubParams: 'obj'):
        self.stock = stock
        self.index = index
        self.lookback = lookback
        self.ScrubParams = ScrubParams

        #self.price_table = pickle.load(open('sp500_price_table.pkl', 'rb')).head(self.lookback)[[self.stock, self.index]]
        self.price_table = PriceTable.head(
            self.lookback)[[self.stock, self.index]]
        #self.daily_returns = self.price_table / self.price_table.shift(-1) - 1
        self.daily_returns = daily_returns(self.price_table)
    def __init__(self, stock: 'str', index: 'str', beta: 'float',
                 to_graph: 'str', base: 'str', lookback: 'int'):
        self.stock = stock
        self.index = index
        self.beta = beta
        self.to_graph = to_graph
        self.base = base
        self.lookback = lookback

        self.price_table = PriceTable.head(
            self.lookback)[[self.stock, self.index]]
        self.daily_returns = daily_returns(self.price_table).head(
            self.lookback)

        self.daily_returns['adj_returns'] = (1 + self.daily_returns[
            self.stock]) / (1 + self.daily_returns[self.index] * self.beta) - 1
        print(self.daily_returns.head(5))
Beispiel #9
0
import pprint
from pprint import pprint
import decimal
import statsmodels.formula.api as sm
from sklearn.linear_model import LinearRegression
from collections import namedtuple
import math
import matplotlib.pyplot as plt
import matplotlib.ticker as tkr
import scipy.stats as ss
import statsmodels.api as sm
from ols import OLS
from ols2 import OLS as MainOLS
from paul_resources import PriceTable, daily_returns
from time_decorator import my_time_decorator
print(PriceTable.head(10))


class ScrubParams(object):
    """Three Parameters for Scrubbing Process; Sequentially Optional"""
    def __init__(self,
                 stock_cutoff: 'float' = None,
                 index_cutoff: 'float' = None,
                 percentile_cutoff: 'float' = None):
        self.stock_cutoff = stock_cutoff
        self.index_cutoff = index_cutoff
        self.percentile_cutoff = percentile_cutoff

    def __repr__(self):
        return "ScrubParams({}, {}, {})".format(self.stock_cutoff,
                                                self.index_cutoff,