<p>The above approach has a drawback:</p>
<p>What if a security is purchased in August and it also matures in August? The above query will not pick this security up, since it's using an as-of date before August.</p>
<h1>Multiple as-of dates</h1>
<p>Here are the as-of dates in August as well as one right before August:</p>
<pre><code>2022-07-27
2022-08-03
2022-08-10
2022-08-17
2022-08-24
</code></pre>
<p>We can retrieve the holdings for each as-of date and select securities from each set.</p>
<p>In PowerShell, let's query the SOMA holdings for each of these as-of dates:</p>
<pre><code>$result_0 = Invoke-RestMethod ('https://markets.newyorkfed.org/api/soma/tsy/get/all/asof/{0}.json' -f '2022-07-27')
$result_1 = Invoke-RestMethod ('https://markets.newyorkfed.org/api/soma/tsy/get/all/asof/{0}.json' -f '2022-08-03')
$result_2 = Invoke-RestMethod ('https://markets.newyorkfed.org/api/soma/tsy/get/all/asof/{0}.json' -f '2022-08-10')
$result_3 = Invoke-RestMethod ('https://markets.newyorkfed.org/api/soma/tsy/get/all/asof/{0}.json' -f '2022-08-17')
$result_4 = Invoke-RestMethod ('https://markets.newyorkfed.org/api/soma/tsy/get/all/asof/{0}.json' -f '2022-08-24')
</code></pre>
<p>From the first set (as-of 2022-07-27), we can select the securities that mature in the range Aug 1st up to the next as-of date, Aug 3rd.</p>
<p>From the second set (as-of 2022-08-03), we can select the securities that mature in the range Aug 3rd up to the next as-of date, Aug 10th.</p>
<p>And so on.</p>
<p>Code for this:</p>
<pre><code>$items = @(
    $result_0.soma.holdings | Where-Object maturityDate -GE '2022-08-01' | Where-Object maturityDate -LE '2022-08-03' 
    $result_1.soma.holdings | Where-Object maturityDate -GT '2022-08-03' | Where-Object maturityDate -LE '2022-08-10' 
    $result_2.soma.holdings | Where-Object maturityDate -GT '2022-08-10' | Where-Object maturityDate -LE '2022-08-17' 
    $result_3.soma.holdings | Where-Object maturityDate -GT '2022-08-17' | Where-Object maturityDate -LE '2022-08-24' 
    $result_4.soma.holdings | Where-Object maturityDate -GT '2022-08-24' | Where-Object maturityDate -LE '2022-08-31'
)
</code></pre>
<p>After running the above, we can display the items:</p>
<pre><code>$items | Sort-Object maturityDate | Format-Table *
</code></pre>
<p><a href="https://i.sstatic.net/CfTCU.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CfTCU.png" alt="enter image description here" /></a></p>
<p>And show the total value maturing:</p>
<pre><code>'{0:C0}' -f ($items | Measure-Object -Property parValue -Sum).Sum
</code></pre>
<p><a href="https://i.sstatic.net/sNxGU.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/sNxGU.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2022-08-28T05:07:24.210Z
2022-08-28T20:07:07.550Z
2022-08-28T20:07:07.550Z
dharmatech
<p>Today is August 15th 2022.</p>
<p>Let's say I'd like to know the treasury security SOMA holdings that have matured so far this month as well as the total that will mature this month.</p>
<p>Here's one approach I've used using PowerShell and the New York Fed API.</p>
<p>Run a query for the 'as of' date right before August:</p>
<pre><code>$result = Invoke-RestMethod ('https://markets.newyorkfed.org/api/soma/tsy/get/all/asof/{0}.json' -f '2022-07-27')
</code></pre>
<p>Show the securities maturing in August:</p>
<pre><code>$result.soma.holdings | 
    Where-Object maturityDate -GE '2022-08-01' | 
    Where-Object maturityDate -LE '2022-08-31' | 
    Sort-Object maturityDate | 
    Format-Table *
</code></pre>
<p><a href="https://i.sstatic.net/jQx9U.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jQx9U.png" alt="enter image description here" /></a></p>
<p>Show the total amount maturing in August:</p>
<pre><code>'{0:C0}' -f (
    $result.soma.holdings | 
        Where-Object maturityDate -GE '2022-08-01' | 
        Where-Object maturityDate -LE '2022-08-31' | 
        Measure-Object -Property parValue -Sum).Sum
</code></pre>
<p><code>$194,344,004,700</code></p>
<pre><code>'{0:C0}' -f (
    $result.soma.holdings | 
        Where-Object maturityDate -GE '2022-08-01' | 
        Where-Object maturityDate -LE '2022-08-15' | 
        Measure-Object -Property parValue -Sum).Sum
</code></pre>
<p><code>$128,597,828,300</code></p>
<h1>Question</h1>
<p>Is this the best approach? Or is there another recommended method?</p>

<federal-reserve>
What treasury security SOMA holdings have matured so far this month?
dharmatech
# What treasury security SOMA holdings have matured so far this month?

(Asked by: username_0 on 2022-08-15)

Today is August 15th 2022.
Let's say I'd like to know the treasury security SOMA holdings that have matured so far this month as well as the total that will mature this month.
Here's one approach I've used using PowerShell and the New York Fed API.
Run a query for the 'as of' date right before August:
$result = Invoke-RestMethod ('https://markets.newyorkfed.org/api/soma/tsy/get/all/asof/{0}.json' -f '2022-07-27')

Show the securities maturing in August:
$result.soma.holdings | 
    Where-Object maturityDate -GE '2022-08-01' | 
    Where-Object maturityDate -LE '2022-08-31' | 
    Sort-Object maturityDate | 
    Format-Table *


Show the total amount maturing in August:
'{0:C0}' -f (
    $result.soma.holdings | 
        Where-Object maturityDate -GE '2022-08-01' | 
        Where-Object maturityDate -LE '2022-08-31' | 
        Measure-Object -Property parValue -Sum).Sum

$194,344,004,700
'{0:C0}' -f (
    $result.soma.holdings | 
        Where-Object maturityDate -GE '2022-08-01' | 
        Where-Object maturityDate -LE '2022-08-15' | 
        Measure-Object -Property parValue -Sum).Sum

$128,597,828,300
Question
Is this the best approach? Or is there another recommended method?

**Tags:** federal-reserve

---

## 1 answers

### Answer by username_0 on 2022-08-28. Score: 0

The above approach has a drawback:
What if a security is purchased in August and it also matures in August? The above query will not pick this security up, since it's using an as-of date before August.
Multiple as-of dates
Here are the as-of dates in August as well as one right before August:
2022-07-27
2022-08-03
2022-08-10
2022-08-17
2022-08-24

We can retrieve the holdings for each as-of date and select securities from each set.
In PowerShell, let's query the SOMA holdings for each of these as-of dates:
$result_0 = Invoke-RestMethod ('https://markets.newyorkfed.org/api/soma/tsy/get/all/asof/{0}.json' -f '2022-07-27')
$result_1 = Invoke-RestMethod ('https://markets.newyorkfed.org/api/soma/tsy/get/all/asof/{0}.json' -f '2022-08-03')
$result_2 = Invoke-RestMethod ('https://markets.newyorkfed.org/api/soma/tsy/get/all/asof/{0}.json' -f '2022-08-10')
$result_3 = Invoke-RestMethod ('https://markets.newyorkfed.org/api/soma/tsy/get/all/asof/{0}.json' -f '2022-08-17')
$result_4 = Invoke-RestMethod ('https://markets.newyorkfed.org/api/soma/tsy/get/all/asof/{0}.json' -f '2022-08-24')

From the first set (as-of 2022-07-27), we can select the securities that mature in the range Aug 1st up to the next as-of date, Aug 3rd.
From the second set (as-of 2022-08-03), we can select the securities that mature in the range Aug 3rd up to the next as-of date, Aug 10th.
And so on.
Code for this:
$items = @(
    $result_0.soma.holdings | Where-Object maturityDate -GE '2022-08-01' | Where-Object maturityDate -LE '2022-08-03' 
    $result_1.soma.holdings | Where-Object maturityDate -GT '2022-08-03' | Where-Object maturityDate -LE '2022-08-10' 
    $result_2.soma.holdings | Where-Object maturityDate -GT '2022-08-10' | Where-Object maturityDate -LE '2022-08-17' 
    $result_3.soma.holdings | Where-Object maturityDate -GT '2022-08-17' | Where-Object maturityDate -LE '2022-08-24' 
    $result_4.soma.holdings | Where-Object maturityDate -GT '2022-08-24' | Where-Object maturityDate -LE '2022-08-31'
)

After running the above, we can display the items:
$items | Sort-Object maturityDate | Format-Table *


And show the total value maturing:
'{0:C0}' -f ($items | Measure-Object -Property parValue -Sum).Sum


---

