コード例 #1
0
    def test_pandl(self):
        fx = pd.DataFrame([2.0] * 10, dt_range1)
        price = pd.DataFrame(
            [100, 103, 105, 106, 110, 105, 104.5, np.nan, 120, np.nan, 142],
            dt_range2)

        trades = pd.concat([
            pd.DataFrame(
                dict(trades=[2, 1, -1, np.nan, 1],
                     fill_price=[102.9, 105.5, 106.5, np.nan, 106.]),
                pd.date_range(start=pd.datetime(2015, 1, 2), periods=5)),
            pd.DataFrame(
                dict(trades=[-1, 1, -1], fill_price=[107, 119, 132]),
                pd.date_range(start=pd.datetime(2015, 1, 8), periods=3))
        ])

        ans = pandl(price, trades, marktomarket=True, fx=fx)
        np.testing.assert_almost_equal(
            ans.pandl_base[1:],
            [0.0, 10.4, 6., 14., -16., -9., 15., 48., 78., 40.])

        ans2 = pandl(price, trades, marktomarket=False, fx=fx)

        np.testing.assert_almost_equal(ans2.pandl_base[1:],
                                       [10.4, 6., 0., -2., 6., 48., 78.])
コード例 #2
0
    def test_pandl(self):
        fx = pd.DataFrame([2.0] * 10, dt_range1)
        price = pd.DataFrame(
            [100, 103, 105, 106, 110, 105, 104.5, np.nan, 120, np.nan,
             142], dt_range2)

        trades = pd.concat([
            pd.DataFrame(
                dict(
                    trades=[2, 1, -1, np.nan, 1],
                    fill_price=[102.9, 105.5, 106.5, np.nan, 106.]),
                pd.date_range(start=pd.datetime(2015, 1, 2), periods=5)),
            pd.DataFrame(
                dict(trades=[-1, 1, -1], fill_price=[107, 119, 132]),
                pd.date_range(start=pd.datetime(2015, 1, 8), periods=3))
        ])

        ans = pandl(price, trades, marktomarket=True, fx=fx)
        np.testing.assert_almost_equal(ans.pandl_base[1:], [
            0.0, 10.4, 6., 14., -16., -9., 15., 48., 78., 40.
        ])

        ans2 = pandl(price, trades, marktomarket=False, fx=fx)

        np.testing.assert_almost_equal(ans2.pandl_base[1:],
                                       [10.4, 6., 0., -2., 6., 48., 78.])
コード例 #3
0
ファイル: account.py プロジェクト: WeiLiElectrEng/kod
        def _pandl_for_instrument(system, instrument_code, this_stage,
                                  percentage, delayfill, roundpositions):

            this_stage.log.msg("Calculating pandl for instrument for %s" %
                               instrument_code,
                               instrument_code=instrument_code)

            price = this_stage.get_daily_price(instrument_code)
            positions = this_stage.get_notional_position(instrument_code)
            fx = this_stage.get_fx_rate(instrument_code)
            value_of_price_point = this_stage.get_value_of_price_move(
                instrument_code)

            if percentage:
                capital = this_stage.get_notional_capital()
            else:
                capital = None

            instr_pandl = pandl(price=price,
                                positions=positions,
                                delayfill=delayfill,
                                roundpositions=roundpositions,
                                fx=fx,
                                value_of_price_point=value_of_price_point,
                                capital=capital)

            return instr_pandl
コード例 #4
0
ファイル: account.py プロジェクト: as4724/pysystemtrade
 def _pandl_for_instrument_forecast(system, instrument_code, rule_variation_name,  this_stage, delayfill):
     price=this_stage.get_instrument_price(instrument_code)
     forecast=this_stage.get_capped_forecast(instrument_code, rule_variation_name)
     get_daily_returns_volatility=this_stage.get_daily_returns_volatility(instrument_code)
     
     pandl_fcast=pandl(price=price,   delayfill=delayfill,  
                        get_daily_returns_volatility=get_daily_returns_volatility, 
                        forecast=forecast, capital=0.0)
     return pandl_fcast
コード例 #5
0
ファイル: account.py プロジェクト: as4724/pysystemtrade
 def _pandl_for_instrument(system, instrument_code, this_stage, percentage, delayfill, roundpositions):
     price=this_stage.get_instrument_price(instrument_code)
     positions=this_stage.get_notional_position(instrument_code)
     fx=this_stage.get_fx_rate(instrument_code)
     value_of_price_point=this_stage.get_value_of_price_move(instrument_code)
     
     if percentage:
         capital=this_stage.get_notional_capital()
     else:
         capital=None
     
     instr_pandl=pandl(price=price,  positions=positions, delayfill=delayfill, roundpositions=roundpositions, 
                     fx=fx, value_of_price_point=value_of_price_point, capital=capital )
 
     return instr_pandl
コード例 #6
0
ファイル: account.py プロジェクト: Sayan-Paul/kod
        def _pandl_for_instrument_forecast(
                system, instrument_code, rule_variation_name, this_stage, delayfill):

            this_stage.log.msg("Calculating pandl for instrument forecast for %s %s" % (instrument_code, rule_variation_name),
                               instrument_code=instrument_code, rule_variation_name=rule_variation_name)

            price = this_stage.get_daily_price(instrument_code)
            forecast = this_stage.get_capped_forecast(
                instrument_code, rule_variation_name)
            get_daily_returns_volatility = this_stage.get_daily_returns_volatility(
                instrument_code)

            pandl_fcast = pandl(price=price, delayfill=delayfill,
                                get_daily_returns_volatility=get_daily_returns_volatility,
                                forecast=forecast, capital=0.0)
            return pandl_fcast
コード例 #7
0
ファイル: account.py プロジェクト: Sayan-Paul/kod
        def _pandl_for_subsystem(
                system, instrument_code, this_stage, percentage, delayfill, roundpositions):

            this_stage.log.msg("Calculating pandl for subsystem for instrument %s" % instrument_code,
                               instrument_code=instrument_code)

            price = this_stage.get_daily_price(instrument_code)
            positions = this_stage.get_subsystem_position(instrument_code)
            fx = this_stage.get_fx_rate(instrument_code)
            value_of_price_point = this_stage.get_value_of_price_move(
                instrument_code)

            if percentage:
                capital = this_stage.get_notional_capital()
            else:
                capital = None

            instr_pandl = pandl(price=price, positions=positions, delayfill=delayfill, roundpositions=roundpositions,
                                fx=fx, value_of_price_point=value_of_price_point, capital=capital)

            return instr_pandl
コード例 #8
0
ファイル: account.py プロジェクト: WeiLiElectrEng/kod
        def _pandl_for_instrument_forecast(system, instrument_code,
                                           rule_variation_name, this_stage,
                                           delayfill):

            this_stage.log.msg(
                "Calculating pandl for instrument forecast for %s %s" %
                (instrument_code, rule_variation_name),
                instrument_code=instrument_code,
                rule_variation_name=rule_variation_name)

            price = this_stage.get_daily_price(instrument_code)
            forecast = this_stage.get_capped_forecast(instrument_code,
                                                      rule_variation_name)
            get_daily_returns_volatility = this_stage.get_daily_returns_volatility(
                instrument_code)

            pandl_fcast = pandl(
                price=price,
                delayfill=delayfill,
                get_daily_returns_volatility=get_daily_returns_volatility,
                forecast=forecast,
                capital=0.0)
            return pandl_fcast
コード例 #9
0
    fast_ewma = pd.ewma(price, span=Lfast)
    slow_ewma = pd.ewma(price, span=Lslow)
    raw_ewmac = fast_ewma - slow_ewma

    vol = robust_vol_calc(price.diff())

    return divide_df_single_column(raw_ewmac, vol)

"""
Try it out

(this isn't properly scaled at this stage of course)
"""
instrument_code = 'EDOLLAR'
price = data.get_instrument_price(instrument_code)
ewmac = calc_ewmac_forecast(price, 32, 128)
print(ewmac.tail(5))

from matplotlib.pyplot import show
ewmac.plot()
show()

"""
Did we make money?
"""

from syscore.accounting import pandl
account = pandl(price, forecast=ewmac)
account.curve().plot()
show()
コード例 #10
0
    vol = robust_vol_calc(price.diff())

    return divide_df_single_column(raw_ewmac, vol)


"""
Try it out

(this isn't properly scaled at this stage of course)
"""
instrument_code = 'EDOLLAR'
price = data.get_daily_price(instrument_code)
ewmac = calc_ewmac_forecast(price, 32, 128)
ewmac.columns = ['forecast']
print(ewmac.tail(5))

from matplotlib.pyplot import show
ewmac.plot()
show()
"""
Did we make money?
"""

from syscore.accounting import pandl
account = pandl(price, forecast=ewmac, capital=0.0)
account.curve().plot()
show()

print(account.stats())
コード例 #11
0
    return divide_df_single_column(raw_ewmac, vol)


"""
Try it out

(this isn't properly scaled at this stage of course)
"""
instrument_code = "EDOLLAR"
price = data.get_daily_price(instrument_code)
ewmac = calc_ewmac_forecast(price, 32, 128)
ewmac.columns = ["forecast"]
print(ewmac.tail(5))

from matplotlib.pyplot import show

ewmac.plot()
show()

"""
Did we make money?
"""

from syscore.accounting import pandl

account = pandl(price, forecast=ewmac, capital=0.0)
account.curve().plot()
show()

print(account.stats())