Ejemplo n.º 1
0
def test_yahoo():

    y = YahooData(['DIS', 'GOOG'])
    date = datetime(2016, 5, 23)
    date = np.datetime64(date)
    out = y.filter_dates(end=date)

    # out  = y.filter_before(date)
    # y.get_symbols_before(date)
    df3 = out.dataframes['GOOG']
    assert df3.index[-1] <= date
    return
Ejemplo n.º 2
0
# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

sns.set()

from backtester.stockdata import YahooData
from backtester.definitions import DF_ADJ_CLOSE
from backtester.indicators import TrailingStats

y = YahooData()
start = np.datetime64('2003-01-01')
end = np.datetime64('2005-01-01')
y = y.filter_dates(start=start, end=end)

s = y.dataframes['SPY'][DF_ADJ_CLOSE]

window = 100
windows = [
    100,
]
for window in windows:
    ts = TrailingStats(s, window)
    loss = ts.max_loss
    # loss99 = np.percentile(loss, 99)

    plt.subplot(2, 1, 1)

    plt.plot(ts.times, ts.max_loss, label='max loss')
Ejemplo n.º 3
0
import matplotlib.pyplot as plt
import seaborn as sns
from globalcache import Cache

sns.set_theme()

cache = Cache(globals())

# %% Get stock data

y_data = YahooData()

start_date = np.datetime64('2012-01-01')
symbols = y_data.retrieve_symbol_names()
y_data = y_data.filter_dates(start=start_date)

# symbols = symbols[0:5]
# symbols = ['GME']

symbols.append('SPY')

# %% Define calculations


def sortino_ratio(r: np.ndarray, target: float, bins: int = 25) -> float:
    """https://en.wikipedia.org/wiki/Sortino_ratio

    Parameters
    ----------
    r : np.ndarray