Skip to content

Commit 4c95401

Browse files
committed
Merge branch 'dev' of https://github.com/uzh-bf/gbl-uzh into jakob/report-improvements
2 parents 146d640 + 3dd6c27 commit 4c95401

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

apps/demo-game/src/lib/analysis.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,26 @@ export const computeRiskAndReturnOfPlayer = (
3838
return assetsWithReturns.map(({ totalAssetsReturn }) => totalAssetsReturn)
3939
})
4040

41-
// TODO(JJ): 12 should rather be num_segments * 3 (because a segment is fixed as 3)
42-
const bankReturnPA: number =
43-
12 * segmentEndResultsOfPlayer?.[0]?.facts.assetsWithReturns[1].bankReturn
44-
4541
const num = totalAssetsReturns.length
4642

4743
const numResults = segmentEndResultsOfPlayer.length
4844
const lastResult = segmentEndResultsOfPlayer[numResults - 1]
4945
const assetsWithReturns = lastResult.facts?.assetsWithReturns
46+
47+
// TODO(JJ): 12 should rather be num_segments * 3 (because a segment is fixed as 3)
48+
const bankReturnPA: number =
49+
Math.pow(
50+
1 + assetsWithReturns.slice(-1)[0].accBankBenchmarkReturn,
51+
12 / num
52+
) - 1
53+
5054
const lastAccReturn = assetsWithReturns.slice(-1)[0].accTotalAssetsReturn
5155

5256
const risk = standardDeviation(totalAssetsReturns) * Math.sqrt(12)
5357
const returns = Math.pow(1 + lastAccReturn, 12 / num) - 1
5458
const sharpeRatio =
5559
risk > 0.0001 ? (returns - bankReturnPA) / risk : undefined
60+
5661
return {
5762
returns,
5863
risk,

0 commit comments

Comments
 (0)