Skip to content

Commit

Permalink
Fleuriet model + report parms as a map
Browse files Browse the repository at this point in the history
  • Loading branch information
dude333 committed Mar 6, 2021
1 parent 704cb0d commit c80ed4d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 34 deletions.
19 changes: 13 additions & 6 deletions cli/cmd/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var scriptMode bool
var all bool
var showShares bool
var extraRatios bool
var fleuriet bool
var omitSector bool
var outputDir string

Expand All @@ -53,6 +54,7 @@ func init() {
reportCmd.Flags().BoolVarP(&all, "all", "a", false, "Mostra todos os indicadores")
reportCmd.Flags().BoolVarP(&showShares, "showShares", "f", false, "Mostra o número de ações e free float")
reportCmd.Flags().BoolVarP(&extraRatios, "extraRatios", "x", false, "Reporte de índices extras")
reportCmd.Flags().BoolVarP(&fleuriet, "fleuriet", "F", false, "Capital de giro no modelo Fleuriet")
reportCmd.Flags().BoolVarP(&omitSector, "omitSector", "o", false, "Omite o relatório das empresas do mesmo setor")
reportCmd.Flags().StringVarP(&outputDir, "outputDir", "d", "", "Diretório onde o relatório será salvo")
}
Expand All @@ -69,15 +71,20 @@ func report(company string) {
if all {
extraRatios = true
showShares = true
fleuriet = true
}

r := make(map[string]bool)
r["ExtraRatios"] = extraRatios
r["ShowShares"] = showShares
r["Fleuriet"] = fleuriet
r["Sector"] = !omitSector

parms := rapina.Parms{
Company: company,
OutputDir: outputDir,
YamlFile: yamlFile,
ExtraRatios: extraRatios,
ShowShares: showShares,
OmitSector: omitSector,
Company: company,
OutputDir: outputDir,
YamlFile: yamlFile,
Reports: r,
}
err := rapina.Report(parms)
if err != nil {
Expand Down
8 changes: 2 additions & 6 deletions parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ type Parms struct {
OutputDir string
// YamlFile: file with the companies' sectors
YamlFile string
// ExtraRatios: enables some extra financial ratios on report
ExtraRatios bool
// ShowShares: shows the number of shares and free float on report
ShowShares bool
// OmitSector: omits the sector report
OmitSector bool
// Reports is a map with the reports and reports items to be printed
Reports map[string]bool
}
12 changes: 5 additions & 7 deletions report.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ func Report(p Parms) (err error) {
}

parms := reports.Parms{
DB: db,
Company: p.Company,
Filename: file,
YamlFile: p.YamlFile,
ExtraRatios: p.ExtraRatios,
ShowShares: p.ShowShares,
OmitSector: p.OmitSector,
DB: db,
Company: p.Company,
Filename: file,
YamlFile: p.YamlFile,
Reports: p.Reports,
}
return reports.Report(parms)
}
Expand Down
11 changes: 5 additions & 6 deletions reports/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ type Parms struct {
Filename string
// YamlFile: file with the companies' sectors
YamlFile string
// ExtraRatios: enables some extra financial ratios on report
ExtraRatios bool
// ShowShares: shows the number of shares and free float on report
ShowShares bool
// OmitSector: omits the sector report
OmitSector bool
// Reports is a map with the reports and reports items to be printed:
// - ExtraRatios: enables some extra financial ratios on report
// - ShowShares: shows the number of shares and free float on report
// - Sector: creates a sheet with the sector report
Reports map[string]bool
}
26 changes: 17 additions & 9 deletions reports/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
grpAccts int = iota + 100
grpShares
grpExtra
grpSector
grpFleuriet
)

// metric parameters
Expand Down Expand Up @@ -61,9 +61,9 @@ func Report(p Parms) error {
}
r.groups = make(map[int]bool, 3)
r.groups[grpAccts] = true
r.groups[grpShares] = p.ShowShares
r.groups[grpExtra] = p.ExtraRatios
r.groups[grpSector] = !p.OmitSector
r.groups[grpShares] = p.Reports["ShowShares"]
r.groups[grpExtra] = p.Reports["ExtraRatios"]
r.groups[grpFleuriet] = p.Reports["Fleuriet"]

e := newExcel()
sheet, _ := e.newSheet(p.Company)
Expand Down Expand Up @@ -222,7 +222,7 @@ func Report(p Parms) error {
sheet.autoWidth()

// SECTOR REPORT
if !p.OmitSector {
if p.Reports["Sector"] {
sheet2, err := e.newSheet("SETOR")
if err == nil {
sheet2.xlsx.SetSheetViewOptions(sheet2.name, 0,
Expand Down Expand Up @@ -480,6 +480,9 @@ func metricsList(v map[uint32]float32) (metrics []metric) {
if v[p.LucLiq] > 0 && v[p.EquityAvg] > 0 {
roe = zeroIfNeg(safeDiv(v[p.LucLiq], v[p.EquityAvg]))
}
var cdg float32 = v[p.PassivoNCirc] + v[p.Equity] - v[p.AtivoNCirc]
var ncg float32 = v[p.AtivoCirc] - v[p.Caixa] -
(v[p.PassivoCirc] - v[p.Dividendos] - v[p.DividaCirc] - v[p.DividaNCirc])

return []metric{
{"Patrimônio Líquido", v[p.Equity], NUMBER, grpAccts},
Expand Down Expand Up @@ -514,27 +517,32 @@ func metricsList(v map[uint32]float32) (metrics []metric) {
{"FCF", v[p.FCF], NUMBER, grpAccts},
{"FCT", v[p.FCO] + v[p.FCI] + v[p.FCF], NUMBER, grpAccts},
{"FCL (FCO+FCI)", v[p.FCO] + v[p.FCI], NUMBER, grpAccts},

{"", 0, EMPTY, grpAccts},

{"Proventos", proventos, NUMBER, grpAccts},
{"Payout", zeroIfNeg(safeDiv(proventos, v[p.LucLiq])), PERCENT, grpAccts},

{"", 0, EMPTY, grpAccts},

{"Total de Ações", v[p.Shares], GENERAL, grpShares},
{"Free Float", v[p.FreeFloat], PERCENT, grpShares},

{"", 0, EMPTY, grpShares},

{"Liquidez Corrente", safeDiv(v[p.AtivoCirc], v[p.PassivoCirc]), INDEX, grpExtra},
{"Liquidez Seco", safeDiv(v[p.AtivoCirc]-v[p.Estoque], v[p.PassivoCirc]), INDEX, grpExtra},
{"Giro dos Ativos", safeDiv(v[p.Vendas], v[p.AtivoTotal]), INDEX, grpExtra},
{"", 0, EMPTY, grpExtra},
{"Giro de Estoque (dias)", safeDiv(v[p.EstoqueMedio], -v[p.CustoVendas]/360), INDEX, grpExtra},
{"Prazo Médio de Recebimento (dias)", safeDiv(v[p.ContasARecebCirc]+v[p.ContasARecebNCirc], v[p.Vendas]/360), INDEX, grpExtra},
{"Giro dos Ativos", safeDiv(v[p.Vendas], v[p.AtivoTotal]), INDEX, grpExtra},
{"", 0, EMPTY, grpExtra},
{"Poder de Ganho Básico (PGB)", safeDiv(EBITDA, v[p.AtivoTotal]), PERCENT, grpExtra},
{"ROA", safeDiv(v[p.LucLiq], v[p.AtivoTotal]), PERCENT, grpExtra},
{"ROE", roe, PERCENT, grpExtra},
{"", 0, EMPTY, grpExtra},

{"-- Modelo Fleuriet --", 0, EMPTY, grpFleuriet},
{"Capital de Giro (CDG)", cdg, NUMBER, grpFleuriet},
{"Necessidade de Capital de Giro (NCG)", ncg, NUMBER, grpFleuriet},
{"Saldo de Tesouraria (T)", cdg - ncg, NUMBER, grpFleuriet},
}
}

Expand Down

0 comments on commit c80ed4d

Please sign in to comment.