Skip to content

Commit

Permalink
fix: computation of sharpe based on bank benchmark value
Browse files Browse the repository at this point in the history
  • Loading branch information
rschlaefli committed Dec 2, 2024
1 parent 42d2e19 commit 3dd6c27
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions apps/demo-game/src/lib/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,26 @@ export const computeRiskAndReturnOfPlayer = (
return assetsWithReturns.map(({ totalAssetsReturn }) => totalAssetsReturn)
})

// TODO(JJ): 12 should rather be num_segments * 3 (because a segment is fixed as 3)
const bankReturnPA: number =
12 * segmentEndResultsOfPlayer?.[0]?.facts.assetsWithReturns[1].bankReturn

const num = totalAssetsReturns.length

const numResults = segmentEndResultsOfPlayer.length
const lastResult = segmentEndResultsOfPlayer[numResults - 1]
const assetsWithReturns = lastResult.facts?.assetsWithReturns

// TODO(JJ): 12 should rather be num_segments * 3 (because a segment is fixed as 3)
const bankReturnPA: number =
Math.pow(
1 + assetsWithReturns.slice(-1)[0].accBankBenchmarkReturn,
12 / num
) - 1

const lastAccReturn = assetsWithReturns.slice(-1)[0].accTotalAssetsReturn

const risk = standardDeviation(totalAssetsReturns) * Math.sqrt(12)
const returns = Math.pow(1 + lastAccReturn, 12 / num) - 1
const sharpeRatio =
risk > 0.0001 ? (returns - bankReturnPA) / risk : undefined

return {
returns,
risk,
Expand Down

0 comments on commit 3dd6c27

Please sign in to comment.