Example #1
0
def test_volatility(client, data, price):
    d = json.loads(
        post(client=client, data=data, url="/engine/volatility").data.decode())
    x = parse(d)
    pt.assert_series_equal(from_nav(price).ewm_volatility().dropna(),
                           x,
                           check_names=False)
Example #2
0
def test_ytd(portfolio, navs):
    #print(from_nav(portfolio.nav).ytd_series[pd.Timestamp("2015-03-31")])
    xxx = ppa.ytd(frame=navs)
    print(xxx)
    assert xxx.loc["test"]["03"] == from_nav(
        portfolio.nav).tail_year.resample("M")[pd.Timestamp("2015-03-31")]
    assert set(xxx.index) == {"test"}
Example #3
0
def test_from_nav():
    t1 = pd.Timestamp("2010-10-21")
    t2 = pd.Timestamp("2010-10-22")
    t3 = pd.Timestamp("2010-10-23")
    nav = pd.Series(index=[t1, t2, t3], data=[10.0, 10.5, 9.9])
    x = from_nav(nav)
    pdt.assert_series_equal(x.nav, nav)
Example #4
0
def ewm_volatility(frame, **kwargs) -> pd.DataFrame:
    d = {
        name: __attempt(f=lambda x: from_nav(series).ewm_volatility(**kwargs),
                        argument=series)
        for name, series in frame.items()
    }
    return pd.DataFrame(d).dropna(axis=1, how="all")
Example #5
0
def recent(frame, n=15) -> pd.DataFrame:
    d = {
        name: __attempt(f=lambda x: from_nav(series).recent(n=n),
                        argument=series)
        for name, series in frame.items()
    }
    return __last(pd.DataFrame(d).tail(n).transpose(),
                  datefmt="%b %d").dropna(axis=0, how="all")
Example #6
0
def test_month(client, data, price):
    d = post(client=client, data=data, url="/engine/month").data.decode()
    x = pd.read_json(d, orient="table")
    pt.assert_frame_equal(
        x,
        from_nav(price).monthlytable.applymap(
            lambda x: "{0:.2f}%".format(float(100.0 * x)).replace("nan%", "")),
        check_names=False)
Example #7
0
def performance(frame, **kwargs) -> pd.DataFrame:
    d = {
        name: __attempt(f=lambda x: from_nav(x).summary_format(**kwargs),
                        argument=series)
        for name, series in frame.items()
    }
    d = pd.DataFrame(d).dropna(axis=1, how="all")
    print(d)
    return d
Example #8
0
def ytd(frame) -> pd.DataFrame:
    """
    :param frame: 
    :return: 
    """
    d = {
        name: __attempt(f=lambda x: from_nav(x).tail_year.resample(rule="M"),
                        argument=series)
        for name, series in frame.items()
    }
    return __last(pd.DataFrame(d).transpose(), datefmt="%m").dropna(axis=0,
                                                                    how="all")
Example #9
0
def mtd(frame) -> pd.DataFrame:
    """

    :param frame: A DataFrame of Nav curves

    :return:
    """
    d = {
        name: __attempt(f=lambda x: from_nav(x).tail_month, argument=series)
        for name, series in frame.items()
    }
    x = __last(pd.DataFrame(d).transpose(), datefmt="%b %d")
    return x.dropna(axis=0, how="all")
Example #10
0
def test_mtd(portfolio, navs):
    xxx = ppa.mtd(frame=navs)
    print(xxx)
    assert xxx.loc["test"]["Apr 20"] == from_nav(
        portfolio.nav).tail_month[pd.Timestamp("2015-04-20")]
    assert set(xxx.index) == {"test"}
Example #11
0
def test_ewm_volatility(portfolio, navs):
    frame = ppa.ewm_volatility(navs)
    pdt.assert_series_equal(frame["test"],
                            from_nav(portfolio.nav).ewm_volatility(),
                            check_names=False)
Example #12
0
def test_periods_per_year(ts):
    assert ts.periods_per_year == 261
    x = pd.Series(index=[1], data=[5.0])
    y = from_nav(nav=x)
    assert y.periods_per_year == 256
Example #13
0
def test_performance():
    ts = read("ts.csv", parse_dates=True, squeeze=True, header=None, index_col=0)
    pdt.assert_series_equal(performance(ts), from_nav(ts).summary())
Example #14
0
def test_sortino_no_negative():
    nav = pd.Series(index=[pd.Timestamp("2010-01-13"),pd.Timestamp("2010-01-15"),pd.Timestamp("2010-01-18")], data=[4.0, 5.0, 6.0])
    assert not np.isfinite(from_nav(nav).sortino_ratio())
Example #15
0
def ts():
    ts = read("ts.csv", parse_dates=True, squeeze=True, header=None, index_col=0)
    ts.name = None
    ts.index.name = None
    return from_nav(ts)
Example #16
0
def test_recent(portfolio, navs):
    x = ppa.recent(navs)
    assert x.loc["test"]["Apr 20"] == from_nav(
        portfolio.nav).recent(n=20)[pd.Timestamp("2015-04-20")]
    assert set(x.index) == {"test"}
Example #17
0
def drawdown(frame) -> pd.DataFrame:
    d = {
        name: __attempt(f=lambda x: from_nav(series).drawdown, argument=series)
        for name, series in frame.items()
    }
    return pd.DataFrame(d).dropna(axis=1, how="all")
Example #18
0
def __series():
    return from_nav(parse(value=json.loads(request.data)))
Example #19
0
def test_drawdown(client, data, price):
    d = json.loads(
        post(client=client, data=data, url="/engine/drawdown").data.decode())
    x = parse(d)
    pt.assert_series_equal(from_nav(price).drawdown, x, check_names=False)