This commit is contained in:
Alexander Kiryukhin 2020-07-25 01:35:31 +03:00
commit 4b35f7c2c3
No known key found for this signature in database
GPG key ID: 8CDA417C9098753B
10 changed files with 1987 additions and 0 deletions

18
README.md Normal file
View file

@ -0,0 +1,18 @@
# Купоны с МосБиржи
Скрипт получающий с МосБиржи информацию о купонах для разных облигаций
По умолчанию формирует таблицы на 4 года с текущей даты. Поменять количество месяцев можно в файле `exporter.go` константа `const months = 48`
## Запуск
Достаточно запустить `go run *.go`
## Примичание
Если величина купона неизвестна, в соответствующей ячейке будет 0.0₽
## Пример результата:
[Купоны ОФЗ](./samples/офз.csv)
[Купоны корпоративных облигаций](./samples/офз.csv)

42
downloader.go Normal file
View file

@ -0,0 +1,42 @@
/*
Copyright © 2020 Alexander Kiryukhin <a.kiryukhin@mail.ru>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package main
import (
"encoding/xml"
"fmt"
"net/http"
)
func download(url string) (*InXML, error) {
cl := http.DefaultClient
resp, err := cl.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return nil, fmt.Errorf("expected code 200, got %d (%s)", resp.StatusCode, resp.Status)
}
d := new(InXML)
return d, xml.NewDecoder(resp.Body).Decode(d)
}

72
exporter.go Normal file
View file

@ -0,0 +1,72 @@
/*
Copyright © 2020 Alexander Kiryukhin <a.kiryukhin@mail.ru>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package main
import (
"encoding/csv"
"fmt"
"os"
"strconv"
"time"
)
const months = 48
func export(name string, documents []*Document) error {
var sheet [][]string
header := []string{"Облигации", "Тикер"}
now := time.Now()
for i := 0; i <= months; i++ {
year, month, _ := now.Date()
cellID := fmt.Sprintf("%02d.%d", month, year)
header = append(header, cellID)
now = now.AddDate(0, 1, 0)
}
sheet = append(sheet, header)
for _, document := range documents {
row := []string{document.Name, document.ID}
now = time.Now()
for i := 0; i <= months; i++ {
if sum, ok := document.GetByDate(now); ok {
row = append(row, strconv.FormatFloat(sum, 'f', 2, 64))
} else {
row = append(row, "")
}
now = now.AddDate(0, 1, 0)
}
sheet = append(sheet, row)
}
f, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0777)
if err != nil {
return err
}
defer f.Close()
w := csv.NewWriter(f)
if err := w.WriteAll(sheet); err != nil {
return err
}
if err := w.Error(); err != nil {
return err
}
return nil
}

3
go.mod Normal file
View file

@ -0,0 +1,3 @@
module github.com/neonxp/moex
go 1.14

0
go.sum Normal file
View file

42
main.go Normal file
View file

@ -0,0 +1,42 @@
package main
import "log"
const (
OFZ_URL = `https://iss.moex.com/iss/engines/stock/markets/bonds/boards/TQOB/securities.xml?iss.meta=off&iss.only=securities&securities.columns=SECID,NEXTCOUPON,COUPONVALUE,SECNAME,COUPONPERCENT,MATDATE,COUPONPERIOD`
CORP_URL = `https://iss.moex.com/iss/engines/stock/markets/bonds/boards/TQCB/securities.xml?iss.meta=off&iss.only=securities&securities.columns=SECID,NEXTCOUPON,COUPONVALUE,SECNAME,COUPONPERCENT,MATDATE,COUPONPERIOD`
)
func main() {
d1, err := processFile(OFZ_URL)
if err != nil {
log.Fatal(err)
}
if err := export("офз.csv", d1); err != nil {
log.Fatal(err)
}
d2, err := processFile(CORP_URL)
if err != nil {
log.Fatal(err)
}
if err := export("корп.csv", d2); err != nil {
log.Fatal(err)
}
}
func processFile(url string) ([]*Document, error) {
in, err := download(url)
if err != nil {
return nil, err
}
var documents []*Document
for _, item := range in.Data.Rows.Items {
d, err := parse(item)
if err != nil {
log.Println(err)
continue
}
documents = append(documents, d)
}
return documents, nil
}

56
parser.go Normal file
View file

@ -0,0 +1,56 @@
/*
Copyright © 2020 Alexander Kiryukhin <a.kiryukhin@mail.ru>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package main
import (
"time"
)
func parse(row Row) (*Document, error) {
date, err := time.Parse("2006-01-02", row.Next)
if err != nil {
return nil, err
}
endDate, err := time.Parse("2006-01-02", row.EndDate)
if err != nil {
return nil, err
}
d := &Document{
ID: row.ID,
Name: row.Name,
From: date,
To: endDate,
Percent: row.Percent,
Coupons: []Coupon{},
}
if date.Equal(endDate) {
d.Add(endDate, row.Value)
}
for date.Before(endDate) {
d.Add(date, row.Value)
date = date.AddDate(0, 0, row.Period)
}
if !date.Equal(endDate) {
d.Add(endDate, row.Value)
}
return d, nil
}

1625
samples/корп.csv Executable file

File diff suppressed because it is too large Load diff

48
samples/офз.csv Executable file
View file

@ -0,0 +1,48 @@
Облигации,Тикер,07.2020,08.2020,09.2020,10.2020,11.2020,12.2020,01.2021,02.2021,03.2021,04.2021,05.2021,06.2021,07.2021,08.2021,09.2021,10.2021,11.2021,12.2021,01.2022,02.2022,03.2022,04.2022,05.2022,06.2022,07.2022,08.2022,09.2022,10.2022,11.2022,12.2022,01.2023,02.2023,03.2023,04.2023,05.2023,06.2023,07.2023,08.2023,09.2023,10.2023,11.2023,12.2023,01.2024,02.2024,03.2024,04.2024,05.2024,06.2024,07.2024
КОБР-33,RU000A101MQ3,,12.40,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
КОБР-34,RU000A101R74,,,11.64,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
КОБР-35,RU000A101UM5,,,,11.31,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
ОФЗ-ПК 24020 27/07/22,SU24020RMFS8,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,,,,,,,,,,,,,,,,,,,,,,,,,
ОФЗ-ПК 24021 24/04/24,SU24021RMFS6,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,,,,
ОФЗ-ПД 25083 15/12/21,SU25083RMFS5,,,,,,34.90,,,,,,34.90,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
ОФЗ-ПД 25084 04/10/23,SU25084RMFS3,,,,33.54,,,,,,,33.54,,,,,,,,33.54,,,,,,,33.54,,,,,,,,33.54,,,,,,33.54,,,,,,,,,
ОФЗ-ПД 26205 14/04/21,SU26205RMFS3,,,,37.90,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
ОФЗ-ПД 26207 03/02/27,SU26207RMFS9,,40.64,,,,,,40.64,,,,,,40.64,,,,,,40.64,,,,,,40.64,,,,,,40.64,,,,,,40.64,,,,,,40.64,,,,,
ОФЗ-ПД 26209 20/07/22,SU26209RMFS5,,,,,,,37.90,,,,,,37.90,,,,,,37.90,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
ОФЗ-ПД 26211 25/01/23,SU26211RMFS1,34.90,,,,,,34.90,,,,,,34.90,,,,,,34.90,,,,,,34.90,,,,,,,,,,,,,,,,,,,,,,,,
ОФЗ-ПД 26212 19/01/28,SU26212RMFS9,35.15,,,,,,35.15,,,,,,35.15,,,,,,35.15,,,,,,35.15,,,,,,35.15,,,,,,35.15,,,,,,35.15,,,,,,35.15
ОФЗ-ПД 26215 16/08/23,SU26215RMFS2,,34.90,,,,,,34.90,,,,,,34.90,,,,,,34.90,,,,,,34.90,,,,,,34.90,,,,,,,,,,,,,,,,,
ОФЗ-ПД 26217 18/08/21,SU26217RMFS8,,37.40,,,,,,37.40,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
ОФЗ-ПД 26218 17/09/31,SU26218RMFS6,,,42.38,,,,,,42.38,,,,,,42.38,,,,,,42.38,,,,,,42.38,,,,,,42.38,,,,,,42.38,,,,,,42.38,,,,
ОФЗ-ПД 26219 16/09/26,SU26219RMFS4,,,38.64,,,,,,38.64,,,,,,38.64,,,,,,38.64,,,,,,38.64,,,,,,38.64,,,,,,38.64,,,,,,38.64,,,,
ОФЗ-ПД 26220 07/12/22,SU26220RMFS2,,,,,,36.90,,,,,,36.90,,,,,,36.90,,,,,,36.90,,,,,,,,,,,,,,,,,,,,,,,,,
ОФЗ-ПД 26221 23/03/33,SU26221RMFS0,,,,38.39,,,,,,38.39,,,,,,38.39,,,,,,38.39,,,,,,38.39,,,,,,38.39,,,,,,38.39,,,,,,38.39,,,
ОФЗ-ПД 26222 16/10/24,SU26222RMFS8,,,,35.40,,,,,,35.40,,,,,,35.40,,,,,,35.40,,,,,,35.40,,,,,,35.40,,,,,,35.40,,,,,,35.40,,,
ОФЗ-ПД 26223 28/02/24,SU26223RMFS6,,,32.41,,,,,,32.41,,,,,,32.41,,,,,,32.41,,,,,32.41,,,,,,,32.41,,,,,32.41,,,,,,,,,,,
ОФЗ-ПД 26224 23/05/29,SU26224RMFS4,,,,,,34.41,,,,,,34.41,,,,,,34.41,,,,,,34.41,,,,,34.41,,,,,,34.41,,,,,,34.41,,,,,,34.41,,
ОФЗ-ПД 26225 10/05/34,SU26225RMFS1,,,,,36.15,,,,,,36.15,,,,,,36.15,,,,,,36.15,,,,,,36.15,,,,,,36.15,,,,,,36.15,,,,,,36.15,,
ОФЗ-ПД 26226 07/10/26,SU26226RMFS9,,,,39.64,,,,,,39.64,,,,,,39.64,,,,,,39.64,,,,,,39.64,,,,,,39.64,,,,,,39.64,,,,,,39.64,,,
ОФЗ-ПД 26227 17/07/24,SU26227RMFS7,,,,,,,36.90,,,,,,36.90,,,,,,36.90,,,,,,36.90,,,,,,36.90,,,,,,36.90,,,,,,36.90,,,,,,
ОФЗ-ПД 26228 10/04/30,SU26228RMFS5,,,,38.15,,,,,,38.15,,,,,,38.15,,,,,,38.15,,,,,,38.15,,,,,,38.15,,,,,,38.15,,,,,,38.15,,,
ОФЗ-ПД 26229 12/11/25,SU26229RMFS3,,,,,35.65,,,,,,35.65,,,,,,35.65,,,,,,35.65,,,,,,35.65,,,,,,35.65,,,,,,35.65,,,,,,35.65,,
ОФЗ-ПД 26230 16/03/39,SU26230RMFS1,,,,38.39,,,,,,38.39,,,,,,38.39,,,,,,38.39,,,,,,38.39,,,,,,38.39,,,,,,38.39,,,,,,38.39,,,
ОФЗ-ПД 26231 20/07/44,SU26231RMFS9,,1.25,,,,,,1.25,,,,,,1.25,,,,,,1.25,,,,,,1.25,,,,,,1.25,,,,,,1.25,,,,,,1.25,,,,,
ОФЗ-ПД 26232 06/10/27,SU26232RMFS7,,,,29.92,,,,,,29.92,,,,,,29.92,,,,,,29.92,,,,,,29.92,,,,,,29.92,,,,,,29.92,,,,,,29.92,,,
ОФЗ-ПД 26233 18/07/2035,SU26233RMFS5,,28.08,,,,,28.08,,,,,,28.08,,,,,28.08,,,,,,28.08,,,,,28.08,,,,,,28.08,,,,,28.08,,,,,,28.08,,,
ОФЗ-ПД 26234 16/07/2025,SU26234RMFS3,,,,,,,28.48,,,,,,,,28.48,,,,,,,28.48,,,,,,,,28.48,,,,,,,,28.48,,,,,,,28.48,,,,
ОФЗ-ПК 29006 29/01/25,SU29006RMFS2,,38.64,,,,,,38.64,,,,,,38.64,,,,,,38.64,,,,,,38.64,,,,,,38.64,,,,,,38.64,,,,,38.64,,,,,,38.64
ОФЗ-ПК 29007 03/03/27,SU29007RMFS0,,,38.10,,,,,,38.10,,,,,,38.10,,,,,,38.10,,,,,,38.10,,,,,,38.10,,,,,,38.10,,,,,,38.10,,,,
ОФЗ-ПК 29008 03/10/29,SU29008RMFS8,,,,37.65,,,,,,37.65,,,,,,37.65,,,,,,37.65,,,,,,37.65,,,,,,37.65,,,,,,37.65,,,,,,37.65,,,
ОФЗ-ПК 29009 05/05/32,SU29009RMFS6,,,,,37.30,,,,,,37.30,,,,,,37.30,,,,,,37.30,,,,,,37.30,,,,,,37.30,,,,,,37.30,,,,,,37.30,,
ОФЗ-ПК 29010 06/12/34,SU29010RMFS4,,,,,,36.80,,,,,,36.80,,,,,,36.80,,,,,,36.80,,,,,,36.80,,,,,,36.80,,,,,,36.80,,,,,,36.80,
ОФЗ-ПК 29012 16/11/22,SU29012RMFS0,,,,,31.81,,,,,,31.81,,,,,,31.81,,,,,,31.81,,,,,,,,,,,,,,,,,,,,,,,,,,
ОФЗ-ПК 29013 18/09/30,SU29013RMFS8,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,
ОФЗ-ПК 29014 25/03/26,SU29014RMFS6,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,,,0.00,
ОФЗ-АД 46011 20/08/25,SU46011RMFS1,,99.73,,,,,,,,,,,,99.73,,,,,,,,,,,,99.73,,,,,,,,,,,,99.73,,,,,,,,,,,
ОФЗ-АД 46012 05/09/29,SU46012RMFS9,,,59.39,,,,,,,,,,,,59.39,,,,,,,,,,,,59.39,,,,,,,,,,,,59.39,,,,,,,,,,
ОФЗ-АД 46018 24/11/21,SU46018RMFS6,,11.34,,,11.34,,,11.34,,,11.34,,,11.34,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
ОФЗ-АД 46020 06/02/36,SU46020RMFS2,,34.41,,,,,,34.41,,,,,,34.41,,,,,,34.41,,,,,,34.41,,,,,,34.41,,,,,,34.41,,,,,,34.41,,,,,
ОФЗ-АД 46022 19/07/23,SU46022RMFS8,,,,,,,27.42,,,,,,27.42,,,,,,27.42,,,,,,27.42,,,,,,27.42,,,,,,,,,,,,,,,,,,
ОФЗ-АД 46023 23/07/26,SU46023RMFS6,24.41,,,,,,24.41,,,,,,24.41,,,,,,24.41,,,,,,24.41,,,,,,24.41,,,,,,24.41,,,,,,24.41,,,,,,24.41
ОФЗ-ИН 52001 16/08/23,SU52001RMFS3,,15.52,,,,,,15.52,,,,,,15.52,,,,,,15.52,,,,,,15.52,,,,,,15.52,,,,,,,,,,,,,,,,,
ОФЗ-ИН 52002 02/02/28,SU52002RMFS1,,13.71,,,,,,13.71,,,,,,13.71,,,,,,13.71,,,,,,13.71,,,,,,13.71,,,,,,13.71,,,,,,13.71,,,,,
1 Облигации Тикер 07.2020 08.2020 09.2020 10.2020 11.2020 12.2020 01.2021 02.2021 03.2021 04.2021 05.2021 06.2021 07.2021 08.2021 09.2021 10.2021 11.2021 12.2021 01.2022 02.2022 03.2022 04.2022 05.2022 06.2022 07.2022 08.2022 09.2022 10.2022 11.2022 12.2022 01.2023 02.2023 03.2023 04.2023 05.2023 06.2023 07.2023 08.2023 09.2023 10.2023 11.2023 12.2023 01.2024 02.2024 03.2024 04.2024 05.2024 06.2024 07.2024
2 КОБР-33 RU000A101MQ3 12.40
3 КОБР-34 RU000A101R74 11.64
4 КОБР-35 RU000A101UM5 11.31
5 ОФЗ-ПК 24020 27/07/22 SU24020RMFS8 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
6 ОФЗ-ПК 24021 24/04/24 SU24021RMFS6 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
7 ОФЗ-ПД 25083 15/12/21 SU25083RMFS5 34.90 34.90
8 ОФЗ-ПД 25084 04/10/23 SU25084RMFS3 33.54 33.54 33.54 33.54 33.54 33.54
9 ОФЗ-ПД 26205 14/04/21 SU26205RMFS3 37.90
10 ОФЗ-ПД 26207 03/02/27 SU26207RMFS9 40.64 40.64 40.64 40.64 40.64 40.64 40.64 40.64
11 ОФЗ-ПД 26209 20/07/22 SU26209RMFS5 37.90 37.90 37.90
12 ОФЗ-ПД 26211 25/01/23 SU26211RMFS1 34.90 34.90 34.90 34.90 34.90
13 ОФЗ-ПД 26212 19/01/28 SU26212RMFS9 35.15 35.15 35.15 35.15 35.15 35.15 35.15 35.15 35.15
14 ОФЗ-ПД 26215 16/08/23 SU26215RMFS2 34.90 34.90 34.90 34.90 34.90 34.90
15 ОФЗ-ПД 26217 18/08/21 SU26217RMFS8 37.40 37.40
16 ОФЗ-ПД 26218 17/09/31 SU26218RMFS6 42.38 42.38 42.38 42.38 42.38 42.38 42.38 42.38
17 ОФЗ-ПД 26219 16/09/26 SU26219RMFS4 38.64 38.64 38.64 38.64 38.64 38.64 38.64 38.64
18 ОФЗ-ПД 26220 07/12/22 SU26220RMFS2 36.90 36.90 36.90 36.90
19 ОФЗ-ПД 26221 23/03/33 SU26221RMFS0 38.39 38.39 38.39 38.39 38.39 38.39 38.39 38.39
20 ОФЗ-ПД 26222 16/10/24 SU26222RMFS8 35.40 35.40 35.40 35.40 35.40 35.40 35.40 35.40
21 ОФЗ-ПД 26223 28/02/24 SU26223RMFS6 32.41 32.41 32.41 32.41 32.41 32.41 32.41
22 ОФЗ-ПД 26224 23/05/29 SU26224RMFS4 34.41 34.41 34.41 34.41 34.41 34.41 34.41 34.41
23 ОФЗ-ПД 26225 10/05/34 SU26225RMFS1 36.15 36.15 36.15 36.15 36.15 36.15 36.15 36.15
24 ОФЗ-ПД 26226 07/10/26 SU26226RMFS9 39.64 39.64 39.64 39.64 39.64 39.64 39.64 39.64
25 ОФЗ-ПД 26227 17/07/24 SU26227RMFS7 36.90 36.90 36.90 36.90 36.90 36.90 36.90
26 ОФЗ-ПД 26228 10/04/30 SU26228RMFS5 38.15 38.15 38.15 38.15 38.15 38.15 38.15 38.15
27 ОФЗ-ПД 26229 12/11/25 SU26229RMFS3 35.65 35.65 35.65 35.65 35.65 35.65 35.65 35.65
28 ОФЗ-ПД 26230 16/03/39 SU26230RMFS1 38.39 38.39 38.39 38.39 38.39 38.39 38.39 38.39
29 ОФЗ-ПД 26231 20/07/44 SU26231RMFS9 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25
30 ОФЗ-ПД 26232 06/10/27 SU26232RMFS7 29.92 29.92 29.92 29.92 29.92 29.92 29.92 29.92
31 ОФЗ-ПД 26233 18/07/2035 SU26233RMFS5 28.08 28.08 28.08 28.08 28.08 28.08 28.08 28.08 28.08
32 ОФЗ-ПД 26234 16/07/2025 SU26234RMFS3 28.48 28.48 28.48 28.48 28.48 28.48
33 ОФЗ-ПК 29006 29/01/25 SU29006RMFS2 38.64 38.64 38.64 38.64 38.64 38.64 38.64 38.64 38.64
34 ОФЗ-ПК 29007 03/03/27 SU29007RMFS0 38.10 38.10 38.10 38.10 38.10 38.10 38.10 38.10
35 ОФЗ-ПК 29008 03/10/29 SU29008RMFS8 37.65 37.65 37.65 37.65 37.65 37.65 37.65 37.65
36 ОФЗ-ПК 29009 05/05/32 SU29009RMFS6 37.30 37.30 37.30 37.30 37.30 37.30 37.30 37.30
37 ОФЗ-ПК 29010 06/12/34 SU29010RMFS4 36.80 36.80 36.80 36.80 36.80 36.80 36.80 36.80
38 ОФЗ-ПК 29012 16/11/22 SU29012RMFS0 31.81 31.81 31.81 31.81
39 ОФЗ-ПК 29013 18/09/30 SU29013RMFS8 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
40 ОФЗ-ПК 29014 25/03/26 SU29014RMFS6 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
41 ОФЗ-АД 46011 20/08/25 SU46011RMFS1 99.73 99.73 99.73 99.73
42 ОФЗ-АД 46012 05/09/29 SU46012RMFS9 59.39 59.39 59.39 59.39
43 ОФЗ-АД 46018 24/11/21 SU46018RMFS6 11.34 11.34 11.34 11.34 11.34
44 ОФЗ-АД 46020 06/02/36 SU46020RMFS2 34.41 34.41 34.41 34.41 34.41 34.41 34.41 34.41
45 ОФЗ-АД 46022 19/07/23 SU46022RMFS8 27.42 27.42 27.42 27.42 27.42
46 ОФЗ-АД 46023 23/07/26 SU46023RMFS6 24.41 24.41 24.41 24.41 24.41 24.41 24.41 24.41 24.41
47 ОФЗ-ИН 52001 16/08/23 SU52001RMFS3 15.52 15.52 15.52 15.52 15.52 15.52
48 ОФЗ-ИН 52002 02/02/28 SU52002RMFS1 13.71 13.71 13.71 13.71 13.71 13.71 13.71 13.71

81
types.go Normal file
View file

@ -0,0 +1,81 @@
/*
Copyright © 2020 Alexander Kiryukhin <a.kiryukhin@mail.ru>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package main
import (
"encoding/xml"
"time"
)
type InXML struct {
XMLName xml.Name `xml:"document"`
Data struct {
XMLName xml.Name `xml:"data"`
Rows struct {
XMLName xml.Name `xml:"rows"`
Items []Row `xml:"row"`
} `xml:"rows"`
} `xml:"data"`
}
type Row struct {
XMLName xml.Name `xml:"row"`
ID string `xml:"SECID,attr"`
Name string `xml:"SECNAME,attr"`
Next string `xml:"NEXTCOUPON,attr"`
Value float64 `xml:"COUPONVALUE,attr"`
Percent float64 `xml:"COUPONPERCENT,attr"`
EndDate string `xml:"MATDATE,attr"`
Period int `xml:"COUPONPERIOD,attr"`
}
type Document struct {
ID string
Name string
From time.Time
To time.Time
Percent float64
Coupons []Coupon
}
func (d *Document) Add(date time.Time, sum float64) {
d.Coupons = append(d.Coupons, Coupon{
Date: date,
Sum: sum,
})
}
func (d *Document) GetByDate(date time.Time) (float64, bool) {
year, month, _ := date.Date()
for _, coupon := range d.Coupons {
cyear, cmonth, _ := coupon.Date.Date()
if year == cyear && month == cmonth {
return coupon.Sum, true
}
}
return 0, false
}
type Coupon struct {
Date time.Time
Sum float64
}