Index future simple stat and time-series test module

# Simple Backtest Module (Personal Usage)

## Install and Update

pip install --upgrade sc-backtest


or (if slow)

pip install --upgrade -i https://pypi.tuna.tsinghua.edu.cn/simple sc-backtest


## Simple Test

• Check for factor validity
• Statistical:
• CDF
• Markout
• Hist
• ...
• Time-Series:
• ...
# x: factors
# y: asset's future ret

import pandas as pd
import numpy as np
from sc_backtest import simpletest, dataset

x = data.pct_change(240).iloc[:, 0]
y = data.pct_change().shift(-1).iloc[:, 0]
st = simpletest()
st.plot_cdf(x, y)
st.plot_composite(x, y)


## Backtest (bt)

• Backtest
• get_report
• get_pnl_plot
• round_test
• ...
# x: factors
# y: asset's future ret

import pandas as pd
import numpy as np
from sc_backtest import simpletest, bt, dataset

x = data.pct_change(240).iloc[:, 0]
y = data.pct_change().shift(-1).iloc[:, 0]
st = simpletest()
data = st.simple_pnl(x, y, data_return=True)
report = bt.get_report(data['delta_med'], y)
bt.get_pnl_plot(data['delta_med'], y)


## Technical Analysis (ta)

Reference: ta

import pandas as pd
import numpy as np
from sc_backtest import ta, dataset

macd_diff = ta.trend.macd(data.iloc[:, 0]).macd_diff()


## Technical Analysis2 (ta2)

Variou moving average function and stat model

• sma, ema, wma, ...
• rsi, atr, ...
• z_score, div_std, de_mean, ...
import pandas as pd
import numpy as np
from sc_backtest import ta2, dataset

wma = ta2.wma(data.iloc[:, 0], window=5)


## Example

Input your factor and underlying asset's future return with index type as DatetimeIndex and get the composite factor analysis stat and simple-pnl time-series plots.

# x: factors
# y: asset's future ret

import pandas as pd
import numpy as np
from sc_backtest import simpletest, bt, dataset, ta2

x = data.pct_change().apply(lambda x: ta2.ema(x, window=240))
y = data.pct_change().shift(-1)
st = simpletest()
st.plot_composite_cs(x, y, ic=True, horizon=5)
bt.get_pnl_plot(x, y, alpha=True)


## Project details

Uploaded Source
Uploaded Python 3