Example #1
0
from ParadoxTrading.Chart import Wizard
from ParadoxTrading.Fetch.ChineseFutures import FetchDominantIndex
from ParadoxTrading.Indicator import FastVolatility, Volatility
import time

fetcher = FetchDominantIndex()

market = fetcher.fetchDayData('20100701', '20170101', 'cu')
print(time.clock())
vol_1 = Volatility(30, _smooth=1).addMany(market).getAllData()
vol_12 = Volatility(30, _smooth=12).addMany(market).getAllData()
print(time.clock())
fast_vol_1 = FastVolatility(30, _smooth=1).addMany(market).getAllData()
fast_vol_12 = FastVolatility(30, _smooth=12).addMany(market).getAllData()
print(time.clock())

wizard = Wizard()

price_view = wizard.addView('price')
price_view.addLine('market', market.index(), market['closeprice'])

sub_view = wizard.addView('std')
sub_view.addLine('vol_1', vol_1.index(), vol_1['volatility'])
sub_view.addLine('vol_12', vol_12.index(), vol_12['volatility'])
sub_view.addLine('fast_vol_1', fast_vol_1.index(), fast_vol_1['volatility'])
sub_view.addLine('fast_vol_12', fast_vol_12.index(), fast_vol_12['volatility'])

wizard.show()
from ParadoxTrading.Chart import Wizard
from ParadoxTrading.Fetch.ChineseFutures import FetchDominantIndex
from ParadoxTrading.Indicator import ReturnRate

fetcher = FetchDominantIndex()

market = fetcher.fetchDayData('20100701', '20170101', 'rb')
rate_1 = ReturnRate().addMany(market).getAllData()
rate_12 = ReturnRate(12).addMany(market).getAllData()

rate_abs_1 = ReturnRate(_use_abs=True).addMany(market).getAllData()
rate_abs_12 = ReturnRate(12, _use_abs=True).addMany(market).getAllData()

wizard = Wizard()

price_view = wizard.addView('price', _view_stretch=3)
price_view.addLine('market', market.index(), market['closeprice'])

sub_view = wizard.addView('sub')
sub_view.addLine('rate_1', rate_1.index(), rate_1['returnrate'])
sub_view.addLine('rate_12', rate_12.index(), rate_12['returnrate'])

abs_view = wizard.addView('abs')
abs_view.addLine('rate_abs_1', rate_abs_1.index(), rate_abs_1['returnrate'])
abs_view.addLine('rate_abs_12', rate_abs_12.index(), rate_abs_12['returnrate'])

wizard.show()
    portfolio,
    strategy,
)
engine.run()

portfolio.storeRecords('futures_tick_backtest')
daily_returns = dailyReturn('futures_tick_backtest')
print(daily_returns)
buy_records, sell_record = FetchRecord().fillToBuySell(
    'futures_tick_backtest'
)
day_data = fetcher_tick.fetchDayData(
    '20171016', '20171017', 'rb1801'
)

wizard = Wizard()

price_view = wizard.addView('price view')
price_view.addLine(
    'price', day_data.index(), day_data['lastprice']
)
ask_ema_data = strategy.ask_ema.getAllData()
bid_ema_data = strategy.bid_ema.getAllData()
price_view.addLine(
    'ask ema', ask_ema_data.index(), ask_ema_data['ema']
)
price_view.addLine(
    'bid ema', bid_ema_data.index(), bid_ema_data['ema']
)
if len(buy_records):
    price_view.addScatter(
returns = LogReturn().addMany(market).getAllData()
return_arr = np.array(returns['logreturn'])

arma_garch_model = ARMAGARCHModel()
arma_garch_model.fit(return_arr)
print(
    arma_garch_model.getPhis(), arma_garch_model.getThetas(),
    arma_garch_model.getAlphas(), arma_garch_model.getBetas(),
    arma_garch_model.getConst(), arma_garch_model.getMu()
)

arma_garch = ARMAGARCH().addMany(market).getAllData()
mean_arr = np.array(arma_garch['mean'])
std_arr = np.array(arma_garch['std'])
print(arma_garch)

wizard = Wizard()

mean_view = wizard.addView('mean')
mean_view.addLine('zero', arma_garch.index(), np.zeros_like(mean_arr))
mean_view.addLine('real', returns.index(), returns['logreturn'])
mean_view.addLine('mean', arma_garch.index(), mean_arr)
mean_view.addLine('up', arma_garch.index(), mean_arr + std_arr)
mean_view.addLine('down', arma_garch.index(), mean_arr - std_arr)

std_view = wizard.addView('std')
std_view.addLine('std', arma_garch.index(), std_arr)

wizard.show()
engine = BacktestEngine(
    market_supply,
    execution,
    portfolio,
    MAStrategy()
)
engine.run()

portfolio.storeRecords('futures_bar_backtest')
daily_returns = dailyReturn('futures_bar_backtest')
print(daily_returns)
buy_records, sell_record = FetchRecord().fillToBuySell(
    'futures_bar_backtest'
)
day_data = fetcher_min.fetchDayData(
    '20171016', '20171021', 'rb1801'
)

wizard = Wizard()

price_view = wizard.addView('price view')
price_view.addCandle(
    'price', day_data.index(), day_data.toRows([
        'openprice', 'highprice', 'lowprice', 'closeprice'
    ])[0]
)
price_view.addScatter('buy', buy_records.index(), buy_records['price'])
price_view.addScatter('sell', sell_record.index(), sell_record['price'])

wizard.show()
Example #6
0
from ParadoxTrading.Chart import Wizard
from ParadoxTrading.Fetch.ChineseFutures import FetchDominantIndex
from ParadoxTrading.Indicator import SAR

fetcher = FetchDominantIndex()

market = fetcher.fetchDayData('20100701', '20170101', 'rb')
sar = SAR().addMany(market).getAllData()

wizard = Wizard()
price_view = wizard.addView('price', _adaptive=True)
price_view.addCandle(
    'market', market.index(),
    market.toRows(['openprice', 'highprice', 'lowprice', 'closeprice'])[0]
)
price_view.addScatter('sar', sar.index(), sar['sar'])
wizard.show()
Example #7
0
from ParadoxTrading.Chart import Wizard
from ParadoxTrading.Fetch.ChineseFutures import FetchDominantIndex
from ParadoxTrading.Indicator import RSRS

fetcher = FetchDominantIndex()
data = fetcher.fetchDayData('20100101', '20170101', 'cu')

rsrs_data = RSRS().addMany(data).getAllData()

wizard = Wizard()

price_view = wizard.addView('price')
price_view.addCandle(
    'candle', data.index(), data.toRows(
        ['openprice', 'highprice', 'lowprice', 'closeprice']
    )[0]
)

rsrs_view = wizard.addView('rsrs')
rsrs_view.addLine('rsrs', rsrs_data.index(), rsrs_data['rsrs'])

wizard.show()
Example #8
0
    igarch_model.getConst(),
)

arma_garch_model = ARMAGARCHModel()
arma_garch_model.fit(return_arr)
print(
    arma_garch_model.getPhis(), arma_garch_model.getThetas(),
    arma_garch_model.getAlphas(), arma_garch_model.getBetas(),
    arma_garch_model.getConst(), arma_garch_model.getMu()
)

start_time = time.time()
garch = GARCH().addMany(market).getAllData()
print('fitting time:', time.time() - start_time)

wizard = Wizard()

price_view = wizard.addView('price')
price_view.addLine(
    'market', market.index(), market['closeprice']
)

sub_view = wizard.addView('std')
sub_view.addLine(
    'predict', garch.index(), garch['predict']
)
sub_view.addLine(
    'total garch', returns.index(), res.conditional_volatility
)
sub_view.addLine(
    'total igarch', returns.index()[1:], igarch_model.getVolatility()
Example #9
0
from ParadoxTrading.Chart import Wizard
from ParadoxTrading.Fetch.ChineseFutures import FetchDominantIndex
from ParadoxTrading.Indicator import Kurtosis

fetcher = FetchDominantIndex()
data = fetcher.fetchDayData(
    '20100101', '20170101', 'rb'
)
k_30 = Kurtosis(30).addMany(data).getAllData()
k_60 = Kurtosis(60).addMany(data).getAllData()

wizard = Wizard()

price_view = wizard.addView('price')
price_view.addLine('price', data.index(), data['closeprice'])

k_view = wizard.addView('k')
k_view.addLine('30', k_30.index(), k_30['kurtosis'])
k_view.addLine('60', k_60.index(), k_60['kurtosis'])

wizard.show()
Example #10
0
from ParadoxTrading.Chart import Wizard
from ParadoxTrading.Fetch.ChineseFutures import FetchDominantIndex
from ParadoxTrading.Indicator import ZigZag

fetcher = FetchDominantIndex()

market = fetcher.fetchDayData('20100701', '20170101', 'rb')
zigzag = ZigZag(0.1).addMany(market).getAllData()

wizard = Wizard()
price_view = wizard.addView('price', _adaptive=True)
price_view.addLine('market', market.index(), market['closeprice'])
price_view.addLine('zigzag', zigzag.index(), zigzag['zigzag'])
wizard.show()
market = fetcher.fetchDayData('20100701', '20180101', 'rb')

returns = LogReturn().addMany(market).getAllData()
return_arr = np.array(returns['logreturn'])

arma_garch_model = ARMAGARCHModel()
arma_garch_model.fit(return_arr)
print(arma_garch_model.getPhis(), arma_garch_model.getThetas(),
      arma_garch_model.getAlphas(), arma_garch_model.getBetas(),
      arma_garch_model.getConst(), arma_garch_model.getMu())

arma_garch = ARMAGARCH().addMany(market).getAllData()
mean_arr = np.array(arma_garch['mean'])
std_arr = np.array(arma_garch['std'])
print(arma_garch)

wizard = Wizard()

mean_view = wizard.addView('mean')
mean_view.addLine('zero', arma_garch.index(), np.zeros_like(mean_arr))
mean_view.addLine('real', returns.index(), returns['logreturn'])
mean_view.addLine('mean', arma_garch.index(), mean_arr)
mean_view.addLine('up', arma_garch.index(), mean_arr + std_arr)
mean_view.addLine('down', arma_garch.index(), mean_arr - std_arr)

std_view = wizard.addView('std')
std_view.addLine('std', arma_garch.index(), std_arr)

wizard.show()
Example #12
0
from ParadoxTrading.Fetch.ChineseFutures import FetchDominantIndex
from ParadoxTrading.Indicator import Plunge, EMA
from ParadoxTrading.Chart import Wizard

fetcher = FetchDominantIndex()
rb = fetcher.fetchDayData('20100101', '20170101', 'rb')

fast_ema = EMA(50).addMany(rb).getAllData()
slow_ema = EMA(100).addMany(rb).getAllData()
plunge = Plunge().addMany(rb).getAllData()

wizard = Wizard()

main_view = wizard.addView('main', _adaptive=True, _view_stretch=3)
main_view.addLine('price', rb.index(), rb['closeprice'])
main_view.addLine('fast_ema', fast_ema.index(), fast_ema['ema'])
main_view.addLine('slow_ema', slow_ema.index(), slow_ema['ema'])

sub_view = wizard.addView('sub')
sub_view.addLine('plunge', plunge.index(), plunge['plunge'])

wizard.show()
Example #13
0
from ParadoxTrading.Chart import Wizard
from ParadoxTrading.Fetch.ChineseFutures import FetchDominantIndex
from ParadoxTrading.Indicator import RSRS

fetcher = FetchDominantIndex()
data = fetcher.fetchDayData('20100101', '20170101', 'cu')

rsrs_data = RSRS().addMany(data).getAllData()

wizard = Wizard()

price_view = wizard.addView('price')
price_view.addCandle(
    'candle', data.index(),
    data.toRows(['openprice', 'highprice', 'lowprice', 'closeprice'])[0])

rsrs_view = wizard.addView('rsrs')
rsrs_view.addLine('rsrs', rsrs_data.index(), rsrs_data['rsrs'])

wizard.show()