def test_portfolio_moex_pass_0(): d = d_pass_moex[0] data = download(**d) data = clean_data(data) pf = portfolio(data = data) pf.plot_portfolios() pf.print_results()
def test_portfolio_yfinance_pass_1(): d = d_pass_yfinance[0] data = download(**d) data = clean_data(data) pf = portfolio(data=data, risk_free_rate=0.001, freq=252, num_portfolios=10000) pf.plot_portfolios() pf.print_results()
def test_download_csv_warn_1(): d = d_warn_csv[1] with pytest.warns(UserWarning): data = download(**d) print(data.head()) isinstance(data, pd.DataFrame)
def test_portfolio_csv_pass_0(): d = d_pass_csv[0] data = download(**d) data = clean_data(data) pf = portfolio(data = data, num_portfolios=10000) pf.plot_portfolios() pf.print_results()
start_date17_20 = datetime.datetime(2017, 11, 20) end_date17_20 = datetime.datetime(2020, 11, 19) tickers = ['CSCO', 'V', 'ABBV', 'SBUX', 'MCD', 'INTC', \ 'GM', 'HPQ', 'EA', 'FDX', 'NKE', 'BERY', \ 'GOOGL', 'GOOG', 'WMT', 'NVDA', 'TSLA', 'GE', \ 'AAL', 'AMD', 'ADBE', 'AMZN', 'PYPL', 'MSFT', \ 'ATVI', 'FB', 'NEM', 'NFLX', 'AVGO', \ 'QCOM', 'BABA', 'MA', 'AAPL', 'BA', 'TWTR', \ 'MU', 'T', 'F', 'BIDU', 'BIIB', 'XOM', \ 'DIS', 'PFE', 'BMY'] data = download(source=Source.YFINANCE, tickers=tickers, start_date=start_date14_17, end_date=end_date14_17) data = clean_data(data) df_ratios = ratios(data=data) df_sharp = df_ratios[df_ratios['Sharp Ratio'] > 1.0] df_sortino = df_ratios[df_ratios['Sortino Ratio'] > 1.0] pf_stocks_sortino = df_sortino.index.to_list() pf_stocks_sharp = df_sortino.index.to_list() print('=' * 80) print('Sortino portfolio 14-17') sortino_data14_17 = download(source=Source.YFINANCE, tickers=pf_stocks_sortino, start_date=start_date14_17,
from pfo.market_data import download, Source, clean_data start_date = datetime.datetime(2017, 11, 20) end_date = '2020-11-20' tickers = ['CSCO', 'V', 'ABBV', 'SBUX', 'MCD', 'INTC', \ 'GM', 'HPQ', 'EA', 'FDX', 'NKE', 'BERY', \ 'GOOGL', 'GOOG', 'WMT', 'NVDA', 'TSLA', 'GE', \ 'AAL', 'AMD', 'ADBE', 'AMZN', 'PYPL', 'MSFT', \ 'ATVI', 'FB', 'NEM', 'NFLX', 'AVGO', \ 'QCOM', 'BABA', 'MA', 'AAPL', 'BA', 'TWTR', \ 'MU', 'T', 'F', 'BIDU', 'BIIB', 'XOM', \ 'DIS', 'PFE', 'BMY'] data = download(source=Source.YFINANCE, tickers=tickers, start_date=start_date, end_date=end_date) data = clean_data(data) df_ratios = ratios(data=data) df_sharp = df_ratios[df_ratios['Sharp Ratio'] > 1.0] df_sortino = df_ratios[df_ratios['Sortino Ratio'] > 1.0] with pd.option_context('display.max_rows', None, 'display.max_columns', None): print(df_sharp) print(df_sortino) pf_stocks_sortino = df_sortino.index.to_list() pf_stocks_sharp = df_sortino.index.to_list() sortino_data = download(source=Source.YFINANCE, tickers=pf_stocks_sortino,
def test_download_csv_pass_1(): d = d_pass_csv[1] data = download(**d) print(data.head()) isinstance(data, pd.DataFrame)
def test_download_moex_pass_3(): d = d_pass_moex[3] data = download(**d) print(data.head()) isinstance(data, pd.DataFrame)
def test_download_yfinance_pass_0(): d = d_pass_yfinance[0] data = download(**d) print(data.head()) isinstance(data, pd.DataFrame)
'GM', 'HPQ', 'EA', 'FDX', 'NKE', 'BERY', \ 'GOOGL', 'GOOG', 'WMT', 'NVDA', 'TSLA', 'GE', \ 'AAL', 'AMD', 'ADBE', 'AMZN', 'PYPL', 'MSFT', \ 'ATVI', 'FB', 'NEM', 'NFLX', 'AVGO', \ 'QCOM', 'BABA', 'MA', 'AAPL', 'BA', 'TWTR', \ 'MU', 'T', 'F', 'BIDU', 'BIIB', 'XOM', \ 'DIS', 'PFE', 'BMY'] # # tickers = ['BABA', 'MA', 'AAPL', 'BA', 'TWTR', \ # 'MU', 'T', 'F', 'BIDU', 'BIIB', 'XOM', \ # 'DIS', 'PFE', 'BMY'] #tickers = ['AKRN', 'PIKK', 'PLZL', 'SELG'] data = download(source=Source.YFINANCE, tickers=tickers, start_date=start_date, end_date=end_date) data = clean_data(data) #data.to_csv(path) # # pf = portfolio(data=data, risk_free_rate=0.01, freq=252) pf.mc() pf.plot_portfolios() pf.print_results() # ef = sharp_efficient_frontier(data=data) msr = ef.max_sharpe_ratio() mv = ef.min_volatility() # res = pf_valuation(msr['x'], data=data)
def test_cluster_stocks_pass_0(): d = d_pass_csv[0] data = download(**d) data = clean_data(data) data.dropna(how="all").replace([np.inf, -np.inf], np.nan) cluster_stocks(data, n_clusters=4, verbose=True)