primo commit
This commit is contained in:
28
pricer/utils.py
Normal file
28
pricer/utils.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import math
|
||||
from typing import Iterable, List
|
||||
|
||||
|
||||
def round_to_multiple(value: float, multiple: float) -> float:
|
||||
if multiple == 0:
|
||||
return value
|
||||
return round(value / multiple) * multiple
|
||||
|
||||
|
||||
def cumulative_sums(values: List[float]) -> List[float]:
|
||||
if not values:
|
||||
return []
|
||||
results = [0.0] * len(values)
|
||||
results[0] = values[0]
|
||||
for i in range(1, len(values)):
|
||||
results[i] = results[i - 1] + values[i]
|
||||
return results
|
||||
|
||||
|
||||
def standard_deviation(values: Iterable[float]) -> float:
|
||||
vals = list(values)
|
||||
n = len(vals)
|
||||
if n <= 1:
|
||||
return 0.0
|
||||
avg = sum(vals) / n
|
||||
sum_sq = sum((v - avg) ** 2 for v in vals)
|
||||
return math.sqrt(sum_sq / (n - 1))
|
||||
Reference in New Issue
Block a user