( symbol: string, fromDate: string, holdDays: number, benchmark: string, fetchImpl: typeof fetch = globalThis.fetch, )
| 79 | } |
| 80 | |
| 81 | export async function computeReturns( |
| 82 | symbol: string, |
| 83 | fromDate: string, |
| 84 | holdDays: number, |
| 85 | benchmark: string, |
| 86 | fetchImpl: typeof fetch = globalThis.fetch, |
| 87 | ): Promise<ReturnsResult> { |
| 88 | const endDate = addDays(fromDate, holdDays); |
| 89 | const [symSeries, benchSeries] = await Promise.all([ |
| 90 | fetchSeries(symbol, fetchImpl), |
| 91 | fetchSeries(benchmark, fetchImpl), |
| 92 | ]); |
| 93 | const symbolReturn = pctChange(symSeries, fromDate, endDate); |
| 94 | const benchmarkReturn = pctChange(benchSeries, fromDate, endDate); |
| 95 | const alpha = |
| 96 | symbolReturn != null && benchmarkReturn != null |
| 97 | ? symbolReturn - benchmarkReturn |
| 98 | : null; |
| 99 | return { symbolReturn, benchmarkReturn, alpha }; |
| 100 | } |
no test coverage detected