• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

moconnell / yolo / 19116466348

05 Nov 2025 09:12PM UTC coverage: 35.004% (-23.2%) from 58.251%
19116466348

push

github

web-flow
Merge pull request #37 from moconnell/36-feat-support-pure-unravel-factor-trading

Feat: support pure Unravel trading

107 of 364 branches covered (29.4%)

Branch coverage included in aggregate %.

30 of 368 new or added lines in 9 files covered. (8.15%)

1 existing line in 1 file now uncovered.

284 of 753 relevant lines covered (37.72%)

15.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/YoloAbstractions/Extensions/VolatilityExtensions.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4

5
namespace YoloAbstractions.Extensions;
6

7
public static class VolatilityExtensions
8
{
9
    /// <summary>
10
    /// Calculates the annualized volatility of a series of closing prices.
11
    /// </summary>
12
    /// <param name="closes">Sequence of closing prices (oldest to newest).</param>
13
    /// <param name="periodsPerYear">
14
    /// Number of periods per year (252 for equities, 365 for crypto daily data).
15
    /// </param>
16
    public static double AnnualizedVolatility(this IEnumerable<decimal> closes, int periodsPerYear = 365)
NEW
17
    {
×
NEW
18
        var prices = closes.ToList();
×
NEW
19
        if (prices.Count < 2)
×
NEW
20
            throw new ArgumentException("At least two closing prices are required.");
×
NEW
21
        if (prices.Any(x => x <= 0))
×
NEW
22
            throw new ArgumentException("All closing prices must be positive.");
×
NEW
23
        if (periodsPerYear <= 0)
×
NEW
24
            throw new ArgumentOutOfRangeException(nameof(periodsPerYear), periodsPerYear, "Periods per year must be positive.");
×
NEW
25
        if (periodsPerYear > 365)
×
NEW
26
            throw new ArgumentOutOfRangeException(nameof(periodsPerYear), periodsPerYear, "Periods per year must be less than 366.");
×
27

28
        // Compute log returns
NEW
29
        var logReturns = new List<double>(prices.Count - 1);
×
NEW
30
        for (var i = 1; i < prices.Count; i++)
×
NEW
31
        {
×
32

NEW
33
            var r = Math.Log((double) (prices[i] / prices[i - 1]));
×
NEW
34
            logReturns.Add(r);
×
NEW
35
        }
×
36

37
        // Standard deviation of log returns
NEW
38
        var mean = logReturns.Average();
×
NEW
39
        var variance = logReturns.Average(r => Math.Pow(r - mean, 2));
×
NEW
40
        var stdev = Math.Sqrt(variance);
×
41

42
        // Annualize
NEW
43
        return stdev * Math.Sqrt(periodsPerYear);
×
NEW
44
    }
×
45
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc