Radium

Equity

class radium.Equity(symbol, start_date, end_date, key)

Bases: object

Class for a single equity between two dates.

data

Contains all daily signals with date as index

Type

pd.DataFrame

high

Contains daily high prices with date as index

Type

pd.Series

low

Contains daily low prices with date as index

Type

pd.Series

open

Contains daily open prices with date as index

Type

pd.Series

closed

Contains daily adjusted closed prices with date as index

Type

pd.Series

symbol

Symbol for equity as found on exchange

Type

str

start_date

First date of interest

Type

datetime.date

end_date

Last date of interest

Type

datetime.date

key

Alpha-vantage API key

Type

str

Initialises equity class

Parameters
  • symbol (str) – Symbol for equity as found on exchange

  • start_date (str or datetime or datetime.date) – First date of interest in YYYY-MM-DD form

  • end_date (str of datetime or datetime.date) – Last date of interest in YYYY-MM-DD form

  • key (str) – Alpha-vantage API key

Raises
  • ValueError – API Key is invalid Equity symbol does not exist End date is same as or before start date

  • RuntimeError – API Call limit reached

plot(start_date=None, end_date=None)

Plots closed prices of equity between two dates as a line graph

Parameters
  • start_date ((optional) str or datetime or datetime.date) – First date to plot in YYYY-MM-DD form, defaults to equity start date

  • end_date ((optional) str of datetime or datetime.date) – Last date to plot in YYYY-MM-DD form, defaults to equity end date

Raises

ValueError – End date is same as or before start date

Pair

class radium.Pair(equity1, equity2)

Bases: object

Class for a pair of equities.

price_spread

Price spread of equities for self.hedge_ratios

Type

float np.ndarray[]

equity1
Type

radium.Equity

equity2
Type

radium.Equity

start_date
Type

datetime.date

end_date
Type

datetime.date

hedge_ratios

Day-wise pairs of hedge ratios

Type

float np.ndarray[][2]

Initialise Pair class

Parameters
Raises
  • TypeError – If equity1 or equity2 is not of type radium.Equity.

  • ValueError – If equity1 and equity2 do not share any date ranges

budget(hedge_ratio, dec)

Calculates budget needed to buy integer number of equities.

Parameters
  • hedge_ratio (int np.ndarray[2]) – Hedge ratios of pair

  • dec (int) – Number of decimals to truncate to

Returns

budget – Budget needed rounded to 2 d.p.

Return type

float

Raises
  • TypeError – If hedge_ratio isnt a list of floats, or dec isnt an integer.

  • ValueError – If hedge_ratio isn’t length 2 or dec < 0.

hedge(method, lookback)

Calculates the hedge_ratios given a method and lookback and stores it in self.hedge_ratios

Parameters
  • method (str) – Method for calculating hedge ratios (‘ols’)

  • lookback (int) – Number of signals to lookback on when calculating hedge ratios

Raises
  • TypeError – If method isn’t a string. If lookback isn’t an integer.

  • ValueError – If lookback <= 0. If method isn’t available.

Notes

Available methods: ‘OLS’

plot_closed(start_date=None, end_date=None)

Plots closed prices of both equities between two dates as a line graph

Parameters
  • start_date ((optional) str or datetime or datetime.date) – First date to plot in YYYY-MM-DD form, defaults to equity start date

  • end_date ((optional) str of datetime or datetime.date) – Last date to plot in YYYY-MM-DD form, defaults to equity end date

Raises

ValueError – End date is same as or before start date

plot_price_spread()

Plots price spread of the pair given hedge_ratios

Raises

Exception – If self.hedge_ratios is not defined.

property price_spread

Price spread of equities for self.hedge_ratios

Raises

TypeError – If self.hedge_ratios isn’t defined.

Notes

Spread calculated using y = h1*y1 + h2*y2.

Type

float np.ndarray[]

radium.pair.cadf_test(pair)

Conducts a Cointegrated Augmented Dickey Fuller Test on a pair of equities.

Prints t-statistic, p-value and critical values

Parameters

pair (radium.Pair) –

Raises

TypeError – If pair is not of type radium.Pair.

radium.pair.johansen_test(pair)

Conducts a Johansen Test on a pair of equities.

Print trace/eigenvalue statistics and critical values.

Parameters

pair (radium.Pair) –

Raises

TypeError – If pair is not of type radium.Pair.

Strategy

class radium.strategy.BollingerPair(pair, entry_z, exit_z, lookback)

Bases: radium.strategy.pair_strategy.PairStrategy

Bollinger band strategy on a pair of equities

pair
Type

radium.Pair

entry_z

Z-score to enter position at

Type

float

exit_z

Z-score to exit position at

Type

float

lookback

Days looked back at on when calculating optimal positions

Type

int

th_positions

Theoretical optimum positions calculated by strategy

Type

np.float[][2]

See also

radium.PairStrategy

Parent class

Initialises strategy

Parameters
  • pair (radium.Pair) –

  • entry_z (float) – Z-score to enter position at

  • exit_z (float) – Z-score to exit position at

  • lookback (int) – Days to lookback on when calculating optimal positions

calculate_positions()

Calculates optimum positions calculated by strategy

Returns

th_positions

Return type

np.float[][2]

class radium.strategy.PairStrategy(pair)

Bases: object

Base class for equity pair trading strategies.

daily_returns

Daily returns from trading by optimal positions

Type

float np.ndarray[]

cum_returns

Daily cumulative returns from trading by optimal positions.

Type

float np.ndarray[]

CAGR

Compound annual growth rate based upon daily cumulative returns.

Type

float

sharpe

Sharpe ratio of the strategy.

Type

float

pair
Type

radium.pair

Initialises PairStrategy class

Parameters

pair (radium.Pair) –

Raises

TypeError – If pair isn’t radium.Pair.

property CAGR

Compound annual growth rate based upon daily cumulative returns.

Raises

Exception – If self.th_positions is not defined.

Type

float

property cum_returns

Daily cumulative returns from trading by optimal positions.

Raises

Exception – If self.th_positions is not defined

Type

float np.ndarray[]

property daily_returns

Daily returns from trading by optimal positions

Raises

Exception – If self.th_positions isn’t defined

Type

float np.ndarray[]

property sharpe

Sharpe ratio of the strategy.

Measures the performance of an investment compared to a risk-free asset, after adjusting for its risk.

Exception

If self.th_positions is not defined

Type

float