Skip to content

Instantly share code, notes, and snippets.

@davidlbatey
Last active December 16, 2015 22:20
Show Gist options
  • Save davidlbatey/5506338 to your computer and use it in GitHub Desktop.
Save davidlbatey/5506338 to your computer and use it in GitHub Desktop.
Finance calculations
Adjusting close.
Dividend multiplier for adjusting close: (Close(T-1) - d)/Close(T-1) where d is the dividend.
Splits adjusting close: Close(T) * 1/N Where N is the split ratio.
Sharpe ratio
Daily return: (new_price - old_price)/old_price
Excess daily return: (daily_return - base_return) e.g. base_return for risk free rate at 4% would be 0.04/252 where 252 is number of trading days.
Sharpe ratio: √252 * average(excess_daily_return) / standard_deviation(excess_daily_return)
Annualized sharpe ratio is √12 * monthly sharpe ratio.
with short hedge
Calculate the short daily return
Net daily return: (daily_return - short_daily_return) / 2 the divide by two is because we have twice the capital in play.
Maximum drawdown
Cumlative compound return per day: (1 + previous_cumulative_compound_return) * (1 + net_daily_return) - 1
High watermark: Maximum(previous_high_water_mark, cumulative_compound_return_of_the_day)
Days draw down: (1 + days_high_water_mark) / (1 + cumulative_compound_return_of_the_day) - 1
Maximum drawdown: Maximum(days_draw_downs)
Drawdown duration
Draw down duration: if day_draw_down = 0 then days_draw_down = 0 else days_draw_down = previous_days_draw_down + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment