# What treasury security SOMA holdings have matured so far this month?

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?

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