mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-12 19:47:03 +08:00
MAINT: Combine leverage calculations.
Instead of having two leverage functions, whose differences were the parameter names, add a `calc_leverage` function, with the calling code determining whether it is gross or net by the type of exposure passed in.
This commit is contained in:
@@ -107,16 +107,9 @@ def calc_net_liquidation(ending_cash, long_value, short_value):
|
||||
return ending_cash + long_value + short_value
|
||||
|
||||
|
||||
def calc_gross_leverage(gross_exposure, net_liq):
|
||||
def calc_leverage(exposure, net_liq):
|
||||
if net_liq != 0:
|
||||
return gross_exposure / net_liq
|
||||
|
||||
return np.inf
|
||||
|
||||
|
||||
def calc_net_leverage(net_exposure, net_liq):
|
||||
if net_liq != 0:
|
||||
return net_exposure / net_liq
|
||||
return exposure / net_liq
|
||||
|
||||
return np.inf
|
||||
|
||||
@@ -125,8 +118,8 @@ def calc_period_stats(pos_stats, ending_cash):
|
||||
net_liq = calc_net_liquidation(ending_cash,
|
||||
pos_stats.long_value,
|
||||
pos_stats.short_value)
|
||||
gross_leverage = calc_gross_leverage(pos_stats.gross_exposure, net_liq)
|
||||
net_leverage = calc_net_leverage(pos_stats.net_exposure, net_liq)
|
||||
gross_leverage = calc_leverage(pos_stats.gross_exposure, net_liq)
|
||||
net_leverage = calc_leverage(pos_stats.net_exposure, net_liq)
|
||||
|
||||
return PeriodStats(
|
||||
net_liquidation=net_liq,
|
||||
|
||||
Reference in New Issue
Block a user